probe: drop support for PROTO_OPENOCD_CUSTOM CMSIS-DAP is a complete superset of the Picoprobe protocol, so now we default to DAPv2 there's no need to keep the downstream code. Also make setting up the reset pin conditional and in the correct place.
diff --git a/CMakeLists.txt b/CMakeLists.txt index c5135ce..1c4ca75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -35,13 +35,6 @@ target_compile_options(picoprobe PRIVATE -Wall) -if (DEFINED ENV{PICOPROBE_LED}) - message("PICOPROBE_LED is defined as " $ENV{PICOPROBE_LED}) - target_compile_definitions(picoprobe PRIVATE PICOPROBE_LED=$ENV{PICOPROBE_LED}) -endif() - -set(DBG_PIN_COUNT=4) - pico_generate_pio_header(picoprobe ${CMAKE_CURRENT_LIST_DIR}/src/probe.pio) target_include_directories(picoprobe PRIVATE src)
diff --git a/src/led.c b/src/led.c index fb73532..f1e9f87 100644 --- a/src/led.c +++ b/src/led.c
@@ -28,16 +28,7 @@ #include "picoprobe_config.h" -#define LED_COUNT_SHIFT 14 -#define LED_COUNT_MAX 5 * (1 << LED_COUNT_SHIFT) - -static uint32_t led_count; - void led_init(void) { - led_count = 0; - gpio_init(PICOPROBE_LED); - gpio_set_dir(PICOPROBE_LED, GPIO_OUT); - gpio_put(PICOPROBE_LED, 1); #ifdef PICOPROBE_USB_CONNECTED_LED gpio_init(PICOPROBE_USB_CONNECTED_LED); gpio_set_dir(PICOPROBE_USB_CONNECTED_LED, GPIO_OUT); @@ -59,20 +50,3 @@ gpio_set_dir(PICOPROBE_UART_TX_LED, GPIO_OUT); #endif } - -void led_task(void) { - if (led_count != 0) { - --led_count; - gpio_put(PICOPROBE_LED, !((led_count >> LED_COUNT_SHIFT) & 1)); - } -} - -void led_signal_activity(uint total_bits) { - if (led_count == 0) { - gpio_put(PICOPROBE_LED, 0); - } - - if (led_count < LED_COUNT_MAX) { - led_count += total_bits; - } -}
diff --git a/src/led.h b/src/led.h index 9dff940..82a2cfd 100644 --- a/src/led.h +++ b/src/led.h
@@ -27,7 +27,5 @@ #define LED_H void led_init(void); -void led_task(void); -void led_signal_activity(uint total_bits); #endif
diff --git a/src/main.c b/src/main.c index 9f6d83a..daf3a51 100644 --- a/src/main.c +++ b/src/main.c
@@ -92,18 +92,14 @@ } int main(void) { - uint32_t resp_len; board_init(); usb_serial_init(); cdc_uart_init(); tusb_init(); -#if (PICOPROBE_DEBUG_PROTOCOL == PROTO_OPENOCD_CUSTOM) - probe_gpio_init(); - probe_init(); -#else + DAP_Setup(); -#endif + led_init(); picoprobe_info("Welcome to Picoprobe!\n"); @@ -120,11 +116,10 @@ while (!THREADED) { tud_task(); cdc_task(); -#if (PICOPROBE_DEBUG_PROTOCOL == PROTO_OPENOCD_CUSTOM) - probe_task(); - led_task(); -#elif (PICOPROBE_DEBUG_PROTOCOL == PROTO_DAP_V2) + +#if (PICOPROBE_DEBUG_PROTOCOL == PROTO_DAP_V2) if (tud_vendor_available()) { + uint32_t resp_len; tud_vendor_read(RxDataBuffer, sizeof(RxDataBuffer)); resp_len = DAP_ProcessCommand(RxDataBuffer, TxDataBuffer); tud_vendor_write(TxDataBuffer, resp_len);
diff --git a/src/picoprobe_config.h b/src/picoprobe_config.h index 042fdff..bd72d28 100644 --- a/src/picoprobe_config.h +++ b/src/picoprobe_config.h
@@ -68,18 +68,6 @@ #define PICOPROBE_UART_RX_LED 7 #define PICOPROBE_UART_TX_LED 8 -// LED config -#ifndef PICOPROBE_LED - -#ifndef PICO_DEFAULT_LED_PIN -#error PICO_DEFAULT_LED_PIN is not defined, run PICOPROBE_LED=<led_pin> cmake -#elif PICO_DEFAULT_LED_PIN == -1 -#error PICO_DEFAULT_LED_PIN is defined as -1, run PICOPROBE_LED=<led_pin> cmake -#else -#define PICOPROBE_LED PICO_DEFAULT_LED_PIN -#endif - -#define PROTO_OPENOCD_CUSTOM 0 #define PROTO_DAP_V1 1 #define PROTO_DAP_V2 2 @@ -88,6 +76,5 @@ #define PICOPROBE_DEBUG_PROTOCOL PROTO_DAP_V2 #endif -#endif #endif
diff --git a/src/probe.c b/src/probe.c index 0ec32be..de8832d 100644 --- a/src/probe.c +++ b/src/probe.c
@@ -52,15 +52,6 @@ #define PROBE_BUF_SIZE 8192 struct _probe { - // Total length - uint tx_len; - // Data back to host - uint8_t tx_buf[PROBE_BUF_SIZE]; - - // CMD / Data RX'd from - uint rx_len; - uint8_t rx_buf[PROBE_BUF_SIZE]; - // PIO offset uint offset; uint initted; @@ -68,25 +59,6 @@ static struct _probe probe; -enum PROBE_CMDS { - PROBE_INVALID = 0, // Invalid command - PROBE_WRITE_BITS = 1, // Host wants us to write bits - PROBE_READ_BITS = 2, // Host wants us to read bits - PROBE_SET_FREQ = 3, // Set TCK - PROBE_RESET = 4, // Reset all state - PROBE_TARGET_RESET = 5, // Reset target -}; - -struct __attribute__((__packed__)) probe_cmd_hdr { - uint8_t id; - uint8_t cmd; - uint32_t bits; -}; - -struct __attribute__((__packed__)) probe_pkt_hdr { - uint32_t total_packet_length; -}; - void probe_set_swclk_freq(uint freq_khz) { uint clk_sys_freq_khz = clock_get_hz(clk_sys) / 1000; picoprobe_info("Set swclk freq %dKHz sysclk %dkHz\n", freq_khz, clk_sys_freq_khz); @@ -97,8 +69,10 @@ void probe_assert_reset(bool state) { +#if defined(PROBE_PIN_RESET) /* Change the direction to out to drive pin to 0 or to in to emulate open drain */ gpio_set_dir(PROBE_PIN_RESET, state); +#endif } void probe_write_bits(uint bit_count, uint32_t data_byte) { @@ -139,6 +113,12 @@ void probe_gpio_init() { +#if defined(PROBE_PIN_RESET) + // Target reset pin: pull up, input to emulate open drain pin + gpio_pull_up(PROBE_PIN_RESET); + // gpio_init will leave the pin cleared and set as input + gpio_init(PROBE_PIN_RESET); +#endif // Funcsel pins pio_gpio_init(pio0, PROBE_PIN_SWCLK); pio_gpio_init(pio0, PROBE_PIN_SWDIO); @@ -147,10 +127,6 @@ } void probe_init() { - // Target reset pin: pull up, input to emulate open drain pin - gpio_pull_up(PROBE_PIN_RESET); - // gpio_init will leave the pin cleared and set as input - gpio_init(PROBE_PIN_RESET); if (!probe.initted) { uint offset = pio_add_program(pio0, &probe_program); probe.offset = offset; @@ -201,119 +177,3 @@ probe.initted = 0; } } - -void probe_handle_read(uint total_bits) { - picoprobe_debug("Read %d bits\n", total_bits); - probe_read_mode(); - - uint chunk; - uint bits = total_bits; - while (bits > 0) { - if (bits > 8) { - chunk = 8; - } else { - chunk = bits; - } - probe.tx_buf[probe.tx_len] = (uint8_t)probe_read_bits(chunk); - probe.tx_len++; - // Decrement remaining bits - bits -= chunk; - } -} - -void probe_handle_write(uint8_t *data, uint total_bits) { - picoprobe_debug("Write %d bits\n", total_bits); - - led_signal_activity(total_bits); - - probe_write_mode(); - - uint chunk; - uint bits = total_bits; - while (bits > 0) { - if (bits > 8) { - chunk = 8; - } else { - chunk = bits; - } - - probe_write_bits(chunk, (uint32_t)*data++); - bits -= chunk; - } -} - -void probe_prepare_read_header(struct probe_cmd_hdr *hdr) { - // We have a read so need to prefix the data with the cmd header - if (probe.tx_len == 0) { - // Reserve some space for probe_pkt_hdr - probe.tx_len += sizeof(struct probe_pkt_hdr); - } - - memcpy((void*)&probe.tx_buf[probe.tx_len], hdr, sizeof(struct probe_cmd_hdr)); - probe.tx_len += sizeof(struct probe_cmd_hdr); -} - -void probe_handle_pkt(void) { - uint8_t *pkt = &probe.rx_buf[0] + sizeof(struct probe_pkt_hdr); - uint remaining = probe.rx_len - sizeof(struct probe_pkt_hdr); - - DEBUG_PINS_SET(probe_timing, DBG_PIN_PKT); - - picoprobe_debug("Processing packet of length %d\n", probe.rx_len); - - probe.tx_len = 0; - while (remaining) { - struct probe_cmd_hdr *hdr = (struct probe_cmd_hdr*)pkt; - uint data_bytes = DIV_ROUND_UP(hdr->bits, 8); - pkt += sizeof(struct probe_cmd_hdr); - remaining -= sizeof(struct probe_cmd_hdr); - - if (hdr->cmd == PROBE_WRITE_BITS) { - uint8_t *data = pkt; - probe_handle_write(data, hdr->bits); - pkt += data_bytes; - remaining -= data_bytes; - } else if (hdr->cmd == PROBE_READ_BITS) { - probe_prepare_read_header(hdr); - probe_handle_read(hdr->bits); - } else if (hdr->cmd == PROBE_SET_FREQ) { - probe_set_swclk_freq(hdr->bits); - } else if (hdr->cmd == PROBE_RESET) { - // TODO: Is there anything to do after a reset? - // tx len and rx len should already be 0 - ; - } else if (hdr->cmd == PROBE_TARGET_RESET) { - probe_assert_reset(hdr->bits); - } - } - probe.rx_len = 0; - - if (probe.tx_len) { - // Fill in total packet length before sending - struct probe_pkt_hdr *tx_hdr = (struct probe_pkt_hdr*)&probe.tx_buf[0]; - tx_hdr->total_packet_length = probe.tx_len; - tud_vendor_write(&probe.tx_buf[0], probe.tx_len); - picoprobe_debug("Picoprobe wrote %d response bytes\n", probe.tx_len); - } - probe.tx_len = 0; - - DEBUG_PINS_CLR(probe_timing, DBG_PIN_PKT); -} - -// USB bits -void probe_task(void) { - if ( tud_vendor_available() ) { - uint count = tud_vendor_read(&probe.rx_buf[probe.rx_len], 64); - if (count == 0) { - return; - } - probe.rx_len += count; - } - - if (probe.rx_len >= sizeof(struct probe_pkt_hdr)) { - struct probe_pkt_hdr *pkt_hdr = (struct probe_pkt_hdr*)&probe.rx_buf[0]; - if (pkt_hdr->total_packet_length == probe.rx_len) { - probe_handle_pkt(); - } - } -}
diff --git a/src/probe.h b/src/probe.h index 0ad8c76..d9d9e55 100644 --- a/src/probe.h +++ b/src/probe.h
@@ -33,10 +33,6 @@ void probe_read_mode(void); void probe_write_mode(void); -void probe_handle_read(uint total_bits); -void probe_handle_write(uint8_t *data, uint total_bits); - -void probe_task(void); void probe_gpio_init(void); void probe_init(void); void probe_deinit(void);
diff --git a/src/usb_descriptors.c b/src/usb_descriptors.c index 31b1475..9220aa7 100644 --- a/src/usb_descriptors.c +++ b/src/usb_descriptors.c
@@ -47,11 +47,7 @@ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, .idVendor = 0x2E8A, // Pi -#if (PICOPROBE_DEBUG_PROTOCOL == PROTO_OPENOCD_CUSTOM) - .idProduct = 0x0004, // Picoprobe -#else .idProduct = 0x000c, // CMSIS-DAP Debug Probe -#endif .bcdDevice = 0x0101, // Version 01.01 .iManufacturer = 0x01, .iProduct = 0x02,