Compare commits
4 Commits
debugprobe
...
debugprobe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37f315f45e | ||
|
|
4dcf6ee4ea | ||
|
|
b166e59789 | ||
|
|
728ca6d1eb |
@@ -10,7 +10,6 @@ project(debugprobe)
|
||||
pico_sdk_init()
|
||||
|
||||
add_executable(debugprobe
|
||||
src/probe_config.c
|
||||
src/led.c
|
||||
src/main.c
|
||||
src/usb_descriptors.c
|
||||
|
||||
@@ -502,8 +502,8 @@ It is recommended to provide the following LEDs for status indication:
|
||||
- 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit.
|
||||
*/
|
||||
__STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {
|
||||
#ifdef PROBE_DAP_CONNECTED_LED
|
||||
gpio_put(PROBE_DAP_CONNECTED_LED, bit);
|
||||
#ifdef DEBUGPROBE_DAP_CONNECTED_LED
|
||||
gpio_put(DEBUGPROBE_DAP_CONNECTED_LED, bit);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -513,8 +513,8 @@ __STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {
|
||||
- 0: Target Running LED OFF: program execution in target stopped.
|
||||
*/
|
||||
__STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {
|
||||
#ifdef PROBE_DAP_RUNNING_LED
|
||||
gpio_put(PROBE_DAP_RUNNING_LED, bit);
|
||||
#ifdef DEBUGPROBE_DAP_RUNNING_LED
|
||||
gpio_put(DEBUGPROBE_DAP_RUNNING_LED, bit);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,6 @@
|
||||
|
||||
/* Include CDC interface to bridge to target UART. Omit if not used. */
|
||||
#define PROBE_CDC_UART
|
||||
|
||||
/* Board implements hardware flow control for UART RTS/CTS instead of ACM control */
|
||||
#define PROBE_UART_HWFC
|
||||
|
||||
/* Target reset GPIO (active-low). Omit if not used.*/
|
||||
#define PROBE_PIN_RESET 1
|
||||
|
||||
@@ -60,7 +56,7 @@
|
||||
#endif
|
||||
|
||||
/* PIO config for PROBE_IO_OEN - note that SWDIOEN and SWCLK are both side_set signals, so must be consecutive. */
|
||||
#if defined(PROBE_IO_OEN)
|
||||
#if defined(PROBE_IO_SWDIOEN)
|
||||
#define PROBE_PIN_SWDIOEN (PROBE_PIN_OFFSET + 0)
|
||||
#define PROBE_PIN_SWCLK (PROBE_PIN_OFFSET + 1)
|
||||
#define PROBE_PIN_SWDIO (PROBE_PIN_OFFSET + 2)
|
||||
@@ -72,17 +68,9 @@
|
||||
#define PROBE_UART_RX 5
|
||||
#define PROBE_UART_INTERFACE uart1
|
||||
#define PROBE_UART_BAUDRATE 115200
|
||||
|
||||
#if defined(PROBE_UART_HWFC)
|
||||
/* Hardware flow control - see 1.4.3 in the RP2040 datasheet for valid pin settings */
|
||||
#define PROBE_UART_CTS 6
|
||||
#define PROBE_UART_RTS 7
|
||||
#else
|
||||
/* Software flow control - RTS and DTR can be omitted if not used */
|
||||
/* Flow control - some or all of these can be omitted if not used */
|
||||
#define PROBE_UART_RTS 9
|
||||
#endif
|
||||
#define PROBE_UART_DTR 10
|
||||
|
||||
#endif
|
||||
|
||||
/* LED config - some or all of these can be omitted if not used */
|
||||
|
||||
@@ -49,4 +49,4 @@
|
||||
|
||||
#define PROBE_PRODUCT_STRING "Debugprobe on Pico (CMSIS-DAP)"
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -33,8 +33,6 @@
|
||||
|
||||
TaskHandle_t uart_taskhandle;
|
||||
TickType_t last_wake, interval = 100;
|
||||
volatile TickType_t break_expiry;
|
||||
volatile bool timed_break;
|
||||
|
||||
/* Max 1 FIFO worth of data */
|
||||
static uint8_t tx_buf[32];
|
||||
@@ -44,7 +42,7 @@ static uint8_t rx_buf[32];
|
||||
static uint debounce_ticks = 5;
|
||||
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
static volatile uint tx_led_debounce;
|
||||
static uint tx_led_debounce;
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_UART_RX_LED
|
||||
@@ -58,23 +56,11 @@ void cdc_uart_init(void) {
|
||||
gpio_set_pulls(PROBE_UART_RX, 1, 0);
|
||||
uart_init(PROBE_UART_INTERFACE, PROBE_UART_BAUDRATE);
|
||||
|
||||
#ifdef PROBE_UART_HWFC
|
||||
/* HWFC implies that hardware flow control is implemented and the
|
||||
* UART operates in "full-duplex" mode (See USB CDC PSTN120 6.3.12).
|
||||
* Default to pulling in the active direction, so an unconnected CTS
|
||||
* behaves the same as if CTS were not enabled. */
|
||||
gpio_set_pulls(PROBE_UART_CTS, 0, 1);
|
||||
gpio_set_function(PROBE_UART_RTS, GPIO_FUNC_UART);
|
||||
gpio_set_function(PROBE_UART_CTS, GPIO_FUNC_UART);
|
||||
uart_set_hw_flow(PROBE_UART_INTERFACE, true, true);
|
||||
#else
|
||||
#ifdef PROBE_UART_RTS
|
||||
gpio_init(PROBE_UART_RTS);
|
||||
gpio_set_dir(PROBE_UART_RTS, GPIO_OUT);
|
||||
gpio_put(PROBE_UART_RTS, 1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_UART_DTR
|
||||
gpio_init(PROBE_UART_DTR);
|
||||
gpio_set_dir(PROBE_UART_DTR, GPIO_OUT);
|
||||
@@ -82,12 +68,11 @@ void cdc_uart_init(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool cdc_task(void)
|
||||
void cdc_task(void)
|
||||
{
|
||||
static int was_connected = 0;
|
||||
static uint cdc_tx_oe = 0;
|
||||
uint rx_len = 0;
|
||||
bool keep_alive = false;
|
||||
|
||||
// Consume uart fifo regardless even if not connected
|
||||
while(uart_is_readable(PROBE_UART_INTERFACE) && (rx_len < sizeof(rx_buf))) {
|
||||
@@ -141,44 +126,23 @@ bool cdc_task(void)
|
||||
gpio_put(PROBE_UART_TX_LED, 0);
|
||||
#endif
|
||||
}
|
||||
/* Pending break handling */
|
||||
if (timed_break) {
|
||||
if (((int)break_expiry - (int)xTaskGetTickCount()) < 0) {
|
||||
timed_break = false;
|
||||
uart_set_break(PROBE_UART_INTERFACE, false);
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
tx_led_debounce = 0;
|
||||
#endif
|
||||
} else {
|
||||
keep_alive = true;
|
||||
}
|
||||
}
|
||||
} else if (was_connected) {
|
||||
tud_cdc_write_clear();
|
||||
uart_set_break(PROBE_UART_INTERFACE, false);
|
||||
timed_break = false;
|
||||
was_connected = 0;
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
tx_led_debounce = 0;
|
||||
#endif
|
||||
cdc_tx_oe = 0;
|
||||
}
|
||||
return keep_alive;
|
||||
}
|
||||
|
||||
void cdc_thread(void *ptr)
|
||||
{
|
||||
BaseType_t delayed;
|
||||
last_wake = xTaskGetTickCount();
|
||||
bool keep_alive;
|
||||
/* Threaded with a polling interval that scales according to linerate */
|
||||
while (1) {
|
||||
keep_alive = cdc_task();
|
||||
if (!keep_alive) {
|
||||
delayed = xTaskDelayUntil(&last_wake, interval);
|
||||
if (delayed == pdFALSE)
|
||||
last_wake = xTaskGetTickCount();
|
||||
}
|
||||
cdc_task();
|
||||
delayed = xTaskDelayUntil(&last_wake, interval);
|
||||
if (delayed == pdFALSE)
|
||||
last_wake = xTaskGetTickCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,39 +229,10 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
||||
gpio_put(PROBE_UART_RX_LED, 0);
|
||||
rx_led_debounce = 0;
|
||||
#endif
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
#ifdef PROBE_UART_RX_LED
|
||||
gpio_put(PROBE_UART_TX_LED, 0);
|
||||
tx_led_debounce = 0;
|
||||
#endif
|
||||
} else
|
||||
vTaskResume(uart_taskhandle);
|
||||
}
|
||||
|
||||
void tud_cdc_send_break_cb(uint8_t itf, uint16_t wValue) {
|
||||
switch(wValue) {
|
||||
case 0:
|
||||
uart_set_break(PROBE_UART_INTERFACE, false);
|
||||
timed_break = false;
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
tx_led_debounce = 0;
|
||||
#endif
|
||||
break;
|
||||
case 0xffff:
|
||||
uart_set_break(PROBE_UART_INTERFACE, true);
|
||||
timed_break = false;
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
gpio_put(PROBE_UART_TX_LED, 1);
|
||||
tx_led_debounce = 1 << 30;
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
uart_set_break(PROBE_UART_INTERFACE, true);
|
||||
timed_break = true;
|
||||
#ifdef PROBE_UART_TX_LED
|
||||
gpio_put(PROBE_UART_TX_LED, 1);
|
||||
tx_led_debounce = 1 << 30;
|
||||
#endif
|
||||
break_expiry = xTaskGetTickCount() + (wValue * (configTICK_RATE_HZ / 1000));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
void cdc_thread(void *ptr);
|
||||
void cdc_uart_init(void);
|
||||
bool cdc_task(void);
|
||||
void cdc_task(void);
|
||||
|
||||
extern TaskHandle_t uart_taskhandle;
|
||||
|
||||
|
||||
@@ -80,16 +80,14 @@ void usb_thread(void *ptr)
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
// Declare pins in binary information
|
||||
bi_decl_config();
|
||||
|
||||
board_init();
|
||||
usb_serial_init();
|
||||
cdc_uart_init();
|
||||
tusb_init();
|
||||
stdio_uart_init();
|
||||
|
||||
DAP_Setup();
|
||||
stdio_uart_init();
|
||||
|
||||
led_init();
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ 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 == 0 ? GPIO_OUT : GPIO_IN);
|
||||
gpio_set_dir(PROBE_PIN_RESET, state);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -170,9 +170,6 @@ void probe_deinit(void)
|
||||
probe_read_mode();
|
||||
pio_sm_set_enabled(pio0, PROBE_SM, 0);
|
||||
pio_remove_program(pio0, &probe_program, probe.offset);
|
||||
|
||||
probe_assert_reset(1); // de-assert nRESET
|
||||
|
||||
probe.initted = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
#include "probe_config.h"
|
||||
#include "pico/binary_info.h"
|
||||
|
||||
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
|
||||
|
||||
void bi_decl_config()
|
||||
{
|
||||
#ifdef PROBE_PIN_RESET
|
||||
bi_decl(bi_1pin_with_name(PROBE_PIN_RESET, "PROBE RESET"));
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_PIN_SWCLK
|
||||
bi_decl(bi_1pin_with_name(PROBE_PIN_SWCLK, "PROBE SWCLK"));
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_PIN_SWDIO
|
||||
bi_decl(bi_1pin_with_name(PROBE_PIN_SWDIO, "PROBE SWDIO"));
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_PIN_SWDI
|
||||
bi_decl(bi_1pin_with_name(PROBE_PIN_SWDI, "PROBE SWDI"));
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_PIN_SWDIOEN
|
||||
bi_decl(bi_1pin_with_name(PROBE_PIN_SWDIOEN, "PROBE SWDIOEN"));
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_CDC_UART
|
||||
bi_decl(bi_program_feature("PROBE UART INTERFACE " STR(PROBE_UART_INTERFACE)));
|
||||
bi_decl(bi_program_feature("PROBE UART BAUDRATE " STR(PROBE_UART_BAUDRATE)));
|
||||
bi_decl(bi_1pin_with_name(PROBE_UART_TX, "PROBE UART TX"));
|
||||
bi_decl(bi_1pin_with_name(PROBE_UART_RX, "PROBE UART RX"));
|
||||
#endif
|
||||
|
||||
#ifdef PROBE_UART_CTS
|
||||
bi_decl(bi_1pin_with_name(PROBE_UART_CTS, "PROBE UART CTS"));
|
||||
#endif
|
||||
#ifdef PROBE_UART_RTS
|
||||
bi_decl(bi_1pin_with_name(PROBE_UART_RTS, "PROBE UART RTS"));
|
||||
#endif
|
||||
#ifdef PROBE_UART_DTR
|
||||
bi_decl(bi_1pin_with_name(PROBE_UART_DTR, "PROBE UART DTR"));
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -72,8 +72,6 @@ do { \
|
||||
#endif
|
||||
//#include "board_example_config.h"
|
||||
|
||||
// Add the configuration to binary information
|
||||
void bi_decl_config();
|
||||
|
||||
#define PROTO_DAP_V1 1
|
||||
#define PROTO_DAP_V2 2
|
||||
|
||||
@@ -48,7 +48,7 @@ tusb_desc_device_t const desc_device =
|
||||
|
||||
.idVendor = 0x2E8A, // Pi
|
||||
.idProduct = 0x000c, // CMSIS-DAP Debug Probe
|
||||
.bcdDevice = 0x0201, // Version 02.01
|
||||
.bcdDevice = 0x0103, // Version 01.03
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
@@ -97,7 +97,7 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf)
|
||||
return desc_hid_report;
|
||||
}
|
||||
|
||||
uint8_t desc_configuration[] =
|
||||
uint8_t const desc_configuration[] =
|
||||
{
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0, 100),
|
||||
// Interface 0
|
||||
@@ -121,8 +121,6 @@ uint8_t desc_configuration[] =
|
||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
{
|
||||
(void) index; // for multiple configurations
|
||||
/* Hack in CAP_BREAK support */
|
||||
desc_configuration[CONFIG_TOTAL_LEN - TUD_CDC_DESC_LEN + 8 + 9 + 5 + 5 + 4 - 1] = 0x6;
|
||||
return desc_configuration;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user