Compare commits
6 Commits
develop
...
debug-prob
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59ced31058 | ||
|
|
4a3d23a85a | ||
|
|
b10589915c | ||
|
|
6cf7e08291 | ||
|
|
7adec12fa9 | ||
|
|
abc32c8ada |
@@ -493,14 +493,22 @@ It is recommended to provide the following LEDs for status indication:
|
||||
- 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit.
|
||||
- 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit.
|
||||
*/
|
||||
__STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {}
|
||||
__STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {
|
||||
#ifdef PICOPROBE_DAP_CONNECTED_LED
|
||||
gpio_put(PICOPROBE_DAP_CONNECTED_LED, bit);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Debug Unit: Set status Target Running LED.
|
||||
\param bit status of the Target Running LED.
|
||||
- 1: Target Running LED ON: program execution in target started.
|
||||
- 0: Target Running LED OFF: program execution in target stopped.
|
||||
*/
|
||||
__STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {}
|
||||
__STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {
|
||||
#ifdef PICOPROBE_DAP_RUNNING_LED
|
||||
gpio_put(PICOPROBE_DAP_RUNNING_LED, bit);
|
||||
#endif
|
||||
}
|
||||
|
||||
///@}
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ TickType_t last_wake, interval = 100;
|
||||
|
||||
static uint8_t tx_buf[CFG_TUD_CDC_TX_BUFSIZE];
|
||||
static uint8_t rx_buf[CFG_TUD_CDC_RX_BUFSIZE];
|
||||
// Actually s^-1 so 25ms
|
||||
#define DEBOUNCE_MS 40
|
||||
static uint debounce_ticks = 5;
|
||||
static uint tx_led_debounce;
|
||||
static uint rx_led_debounce;
|
||||
|
||||
void cdc_uart_init(void) {
|
||||
gpio_set_function(PICOPROBE_UART_TX, GPIO_FUNC_UART);
|
||||
@@ -61,21 +66,43 @@ void cdc_task(void)
|
||||
/* Implicit overflow if we don't write all the bytes to the host.
|
||||
* Also throw away bytes if we can't write... */
|
||||
if (rx_len) {
|
||||
#ifdef PICOPROBE_UART_RX_LED
|
||||
gpio_put(PICOPROBE_UART_RX_LED, 1);
|
||||
rx_led_debounce = debounce_ticks;
|
||||
#endif
|
||||
written = MIN(tud_cdc_write_available(), rx_len);
|
||||
if (written > 0) {
|
||||
tud_cdc_write(rx_buf, written);
|
||||
tud_cdc_write_flush();
|
||||
}
|
||||
} else {
|
||||
#ifdef PICOPROBE_UART_RX_LED
|
||||
if (rx_led_debounce)
|
||||
rx_led_debounce--;
|
||||
else
|
||||
gpio_put(PICOPROBE_UART_RX_LED, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Reading from a firehose and writing to a FIFO. */
|
||||
size_t watermark = MIN(tud_cdc_available(), sizeof(tx_buf));
|
||||
if (watermark > 0) {
|
||||
size_t tx_len;
|
||||
#ifdef PICOPROBE_UART_TX_LED
|
||||
gpio_put(PICOPROBE_UART_TX_LED, 1);
|
||||
tx_led_debounce = debounce_ticks;
|
||||
#endif
|
||||
/* Batch up to half a FIFO of data - don't clog up on RX */
|
||||
watermark = MIN(watermark, 16);
|
||||
tx_len = tud_cdc_read(tx_buf, watermark);
|
||||
uart_write_blocking(PICOPROBE_UART_INTERFACE, tx_buf, tx_len);
|
||||
} else {
|
||||
#ifdef PICOPROBE_UART_TX_LED
|
||||
if (tx_led_debounce)
|
||||
tx_led_debounce--;
|
||||
else
|
||||
gpio_put(PICOPROBE_UART_TX_LED, 0);
|
||||
#endif
|
||||
}
|
||||
} else if (was_connected) {
|
||||
tud_cdc_write_clear();
|
||||
@@ -102,10 +129,10 @@ void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* line_coding)
|
||||
* fill up half a FIFO. Millis is too coarse for integer divide.
|
||||
*/
|
||||
uint32_t micros = (1000 * 1000 * 16 * 10) / MAX(line_coding->bit_rate, 1);
|
||||
|
||||
/* Modifying state, so park the thread before changing it. */
|
||||
vTaskSuspend(uart_taskhandle);
|
||||
interval = MAX(1, micros / ((1000 * 1000) / configTICK_RATE_HZ));
|
||||
debounce_ticks = MAX(1, configTICK_RATE_HZ / (interval * DEBOUNCE_MS));
|
||||
picoprobe_info("New baud rate %d micros %d interval %u\n",
|
||||
line_coding->bit_rate, micros, interval);
|
||||
uart_deinit(PICOPROBE_UART_INTERFACE);
|
||||
@@ -119,8 +146,16 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
||||
{
|
||||
/* CDC drivers use linestate as a bodge to activate/deactivate the interface.
|
||||
* Resume our UART polling on activate, stop on deactivate */
|
||||
if (!dtr && !rts)
|
||||
if (!dtr && !rts) {
|
||||
vTaskSuspend(uart_taskhandle);
|
||||
else
|
||||
#ifdef PICOPROBE_UART_RX_LED
|
||||
gpio_put(PICOPROBE_UART_RX_LED, 0);
|
||||
rx_led_debounce = 0;
|
||||
#endif
|
||||
#ifdef PICOPROBE_UART_RX_LED
|
||||
gpio_put(PICOPROBE_UART_TX_LED, 0);
|
||||
tx_led_debounce = 0;
|
||||
#endif
|
||||
} else
|
||||
vTaskResume(uart_taskhandle);
|
||||
}
|
||||
|
||||
23
src/led.c
23
src/led.c
@@ -35,14 +35,31 @@ 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);
|
||||
#endif
|
||||
#ifdef PICOPROBE_DAP_CONNECTED_LED
|
||||
gpio_init(PICOPROBE_DAP_CONNECTED_LED);
|
||||
gpio_set_dir(PICOPROBE_DAP_CONNECTED_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PICOPROBE_DAP_RUNNING_LED
|
||||
gpio_init(PICOPROBE_DAP_RUNNING_LED);
|
||||
gpio_set_dir(PICOPROBE_DAP_RUNNING_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PICOPROBE_UART_RX_LED
|
||||
gpio_init(PICOPROBE_UART_RX_LED);
|
||||
gpio_set_dir(PICOPROBE_UART_RX_LED, GPIO_OUT);
|
||||
#endif
|
||||
#ifdef PICOPROBE_UART_TX_LED
|
||||
gpio_init(PICOPROBE_UART_TX_LED);
|
||||
gpio_set_dir(PICOPROBE_UART_TX_LED, GPIO_OUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
void led_task(void) {
|
||||
if (led_count != 0) {
|
||||
--led_count;
|
||||
|
||||
@@ -59,6 +59,12 @@ void usb_thread(void *ptr)
|
||||
{
|
||||
do {
|
||||
tud_task();
|
||||
#ifdef PICOPROBE_USB_CONNECTED_LED
|
||||
if (!gpio_get(PICOPROBE_USB_CONNECTED_LED) && tud_ready())
|
||||
gpio_put(PICOPROBE_USB_CONNECTED_LED, 1);
|
||||
else
|
||||
gpio_put(PICOPROBE_USB_CONNECTED_LED, 0);
|
||||
#endif
|
||||
// Trivial delay to save power
|
||||
vTaskDelay(1);
|
||||
} while (1);
|
||||
@@ -74,7 +80,7 @@ void dap_thread(void *ptr)
|
||||
tud_vendor_write(TxDataBuffer, resp_len);
|
||||
} else {
|
||||
// Trivial delay to save power
|
||||
vTaskDelay(2);
|
||||
vTaskDelay(1);
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
@@ -48,12 +48,13 @@
|
||||
|
||||
// PIO config
|
||||
#define PROBE_SM 0
|
||||
#define PROBE_PIN_OFFSET 2
|
||||
#define PROBE_PIN_OFFSET 12
|
||||
#define PROBE_PIN_SWCLK (PROBE_PIN_OFFSET + 0) // 2
|
||||
#define PROBE_PIN_SWDIO (PROBE_PIN_OFFSET + 1) // 3
|
||||
#define PROBE_PIN_SWDIO (PROBE_PIN_OFFSET + 2) // 3
|
||||
#define PROBE_PIN_SWDI (PROBE_PIN_OFFSET + 1) // 1 - for level-shifted input
|
||||
|
||||
// Target reset config
|
||||
#define PROBE_PIN_RESET 6
|
||||
#define PROBE_PIN_RESET 0
|
||||
|
||||
// UART config
|
||||
#define PICOPROBE_UART_TX 4
|
||||
@@ -61,6 +62,12 @@
|
||||
#define PICOPROBE_UART_INTERFACE uart1
|
||||
#define PICOPROBE_UART_BAUDRATE 115200
|
||||
|
||||
#define PICOPROBE_USB_CONNECTED_LED 2
|
||||
#define PICOPROBE_DAP_CONNECTED_LED 15
|
||||
#define PICOPROBE_DAP_RUNNING_LED 16
|
||||
#define PICOPROBE_UART_RX_LED 7
|
||||
#define PICOPROBE_UART_TX_LED 8
|
||||
|
||||
// LED config
|
||||
#ifndef PICOPROBE_LED
|
||||
|
||||
|
||||
@@ -163,7 +163,11 @@ void probe_init() {
|
||||
// Set SWDIO offset
|
||||
sm_config_set_out_pins(&sm_config, PROBE_PIN_SWDIO, 1);
|
||||
sm_config_set_set_pins(&sm_config, PROBE_PIN_SWDIO, 1);
|
||||
#ifdef PROBE_PIN_SWDI
|
||||
sm_config_set_in_pins(&sm_config, PROBE_PIN_SWDI);
|
||||
#else
|
||||
sm_config_set_in_pins(&sm_config, PROBE_PIN_SWDIO);
|
||||
#endif
|
||||
|
||||
// Set SWD and SWDIO pins as output to start. This will be set in the sm
|
||||
pio_sm_set_consecutive_pindirs(pio0, PROBE_SM, PROBE_PIN_OFFSET, 2, true);
|
||||
|
||||
@@ -50,7 +50,7 @@ tusb_desc_device_t const desc_device =
|
||||
#if (PICOPROBE_DEBUG_PROTOCOL == PROTO_OPENOCD_CUSTOM)
|
||||
.idProduct = 0x0004, // Picoprobe
|
||||
#else
|
||||
.idProduct = 0x000c, // CMSIS-DAP adapter
|
||||
.idProduct = 0x000c, // CMSIS-DAP Debug Probe
|
||||
#endif
|
||||
.bcdDevice = 0x0101, // Version 01.01
|
||||
.iManufacturer = 0x01,
|
||||
@@ -137,11 +137,11 @@ char const* string_desc_arr [] =
|
||||
{
|
||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||
"Raspberry Pi", // 1: Manufacturer
|
||||
"Picoprobe CMSIS-DAP", // 2: Product
|
||||
"Debug Probe (CMSIS-DAP)", // 2: Product
|
||||
usb_serial, // 3: Serial, uses flash unique ID
|
||||
"Picoprobe CMSIS-DAP v1", // 4: Interface descriptor for HID transport
|
||||
"Picoprobe CMSIS-DAP v2", // 5: Interface descriptor for Bulk transport
|
||||
"Picoprobe CDC-ACM UART", // 6: Interface descriptor for CDC
|
||||
"CMSIS-DAP v1 Interface", // 4: Interface descriptor for HID transport
|
||||
"CMSIS-DAP v2 Interface", // 5: Interface descriptor for Bulk transport
|
||||
"CDC-ACM UART Interface", // 6: Interface descriptor for CDC
|
||||
};
|
||||
|
||||
static uint16_t _desc_str[32];
|
||||
|
||||
Reference in New Issue
Block a user