Skip to content

Commit

Permalink
Merge pull request #44 from rgrr/feature/debug-probe-minor
Browse files Browse the repository at this point in the history
CDC reconnect repaired
  • Loading branch information
rgrr committed May 1, 2023
2 parents 74b3cc2 + 0bf7eee commit 8a6a9ad
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

VERSION_MAJOR := 1
VERSION_MINOR := 13
VERSION_MINOR := 14

BUILD_DIR := build
PROJECT := picoprobe
Expand All @@ -20,7 +20,7 @@ CMAKE_FLAGS += -DCMAKE_EXPORT_COMPILE_COMMANDS=True

ifeq ($(PICO_BOARD),)
# pico|pico_w|pico_debug_probe
PICO_BOARD := pico_debug_probe
PICO_BOARD := pico
endif


Expand Down
11 changes: 10 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ For details about probe pin assignments see the link:doc/hardware.adoc[hardware

|pyOCD 0.34.x
|yes
|no
|yes
|`pyocd flash -f 400000 -t nrf52840 firmware.elf`

|cp / copy
Expand Down Expand Up @@ -509,9 +509,18 @@ make create-images
| https://documentation-service.arm.com/static/5f900b1af86e16515cdc0642[Debug Interface v5.2 Architecture Specification]
| if the link does not work, try https://developer.arm.com/documentation/ihi0031/latest/[this]

| https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst[Semihosting Information]
|

| https://github.com/raspberrypi/pico-sdk[Raspberry Pi Pico SDK]
|

| https://github.com/pyocd/pyOCD[pyOCD on github]
|

| https://github.com/openocd-org/openocd[OpenOCD on github]
| https://openocd.org/[Official Homepage]

|===


Expand Down
33 changes: 33 additions & 0 deletions doc/hardware.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,41 @@

## Hardware

### Existing Probe Hardware
[%autowidth]
[%header]
|===
| Name | Comment

| https://www.raspberrypi.com/products/debug-probe/[Raspberry Pi Debug Probe]
| the "original"

| https://mcuoneclipse.com/2023/04/08/open-source-picolink-raspberry-pi-rp2040-cmsis-dap-debug-probe/[picoLink]
| Open Source picoLink: Raspberry Pi RP2040 CMSIS-DAP Debug Probe

| https://github.com/tjko/tiny-picoprobe[tiny-picoprobe]
| small PCB to mount a regular Pico Pi board to work without breadboard

| https://github.com/Fabien-Chouteau/picoprobe-pcb[Pimoroni Probe PCB]
| converts a Pi Pico into a simple probe (with standard SWD connector)

| https://github.com/ene9ba/PicoProbeHolder[Pico Probe Holder]
| Adapter which also provides 3.3V and 5V to the target

| https://github.com/martijnvwezel/pico-probe-programmer[Pico Probe Programmer]
| Another PCB adapter

|===

All unfortunately without level shifters and without the possibility to use
YaPicoprobes sigrok features. So there is some space left for other hardware
(ideas).


### Pin Assignments

.Pins Assignments Rasberry Pi Pico
[%autowidth]
[%header]
|===
| Pin | Description
Expand All @@ -29,6 +61,7 @@
|===

.Other Pin Assigments Raspberry Pi Pico
[%autowidth]
[%header]
|===
| Pin | Description | Pico W
Expand Down
29 changes: 21 additions & 8 deletions src/cdc_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void cdc_debug_thread(void *ptr)
if ( !m_connected) {
// wait here until connected (and until my terminal program is ready)
while ( !m_connected) {
vTaskDelay(pdMS_TO_TICKS(100));
xEventGroupWaitBits(events, EV_TX_COMPLETE | EV_STREAM, pdTRUE, pdFALSE, pdMS_TO_TICKS(1000));
}
vTaskDelay(pdMS_TO_TICKS(100));
}
Expand All @@ -99,6 +99,16 @@ void cdc_debug_thread(void *ptr)
}
}
}

if (tud_cdc_n_available(CDC_UART_N)) {
//
// eat receive characters (don't know if this has any effects, but who knows)
//
uint8_t ch;

tud_cdc_n_read(CDC_UART_N, &ch, sizeof(ch));
}

#else
xStreamBufferReceive(stream_printf, cdc_debug_buf, sizeof(cdc_debug_buf), pdMS_TO_TICKS(500));
#endif
Expand All @@ -108,14 +118,17 @@ void cdc_debug_thread(void *ptr)


void cdc_debug_line_state_cb(bool dtr, bool rts)
/**
* Flush tinyusb buffers on connect/disconnect.
* This seems to be necessary to survive e.g. a restart of the host (Linux)
*/
{
// CDC drivers use linestate as a bodge to activate/deactivate the interface.
if ( !dtr && !rts) {
m_connected = false;
}
else {
m_connected = true;
}
#if CFG_TUD_CDC_DEBUG
tud_cdc_n_write_clear(CDC_DEBUG_N);
tud_cdc_n_read_flush(CDC_DEBUG_N);
m_connected = (dtr || rts);
xEventGroupSetBits(events, EV_TX_COMPLETE);
#endif
} // cdc_debug_line_state_cb


Expand Down
19 changes: 11 additions & 8 deletions src/cdc_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void cdc_thread(void *ptr)
if ( !m_connected) {
// wait here until connected (and until my terminal program is ready)
while ( !m_connected) {
vTaskDelay(pdMS_TO_TICKS(100));
xEventGroupWaitBits(events, EV_TX_COMPLETE | EV_STREAM | EV_RX, pdTRUE, pdFALSE, pdMS_TO_TICKS(1000));
}
vTaskDelay(pdMS_TO_TICKS(100));
}
Expand Down Expand Up @@ -191,14 +191,17 @@ void cdc_uart_line_coding_cb(cdc_line_coding_t const* line_coding)


void cdc_uart_line_state_cb(bool dtr, bool rts)
/**
* Flush tinyusb buffers on connect/disconnect.
* This seems to be necessary to survive e.g. a restart of the host (Linux)
*/
{
// CDC drivers use linestate as a bodge to activate/deactivate the interface.
if ( !dtr && !rts) {
m_connected = false;
}
else {
m_connected = true;
}
#if CFG_TUD_CDC_UART
tud_cdc_n_write_clear(CDC_UART_N);
tud_cdc_n_read_flush(CDC_UART_N);
m_connected = (dtr || rts);
xEventGroupSetBits(events, EV_TX_COMPLETE);
#endif
} // cdc_uart_line_state_cb


Expand Down
5 changes: 5 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
cdc_debug_line_state_cb(dtr, rts);
}
#endif
#if CFG_TUD_CDC_SIGROK
if (itf == CDC_SIGROK_N) {
cdc_sigrok_line_state_cb(dtr, rts);
}
#endif
} // tud_cdc_line_state_cb


Expand Down
32 changes: 29 additions & 3 deletions src/pico-sigrok/cdc_sigrok.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ static TaskHandle_t task_cdc_sigrok;
static EventGroupHandle_t events;
static StreamBufferHandle_t stream_sigrok;

static volatile bool m_connected = false;



void cdc_sigrok_tx_complete_cb(void)
Expand All @@ -63,6 +65,22 @@ void cdc_sigrok_tx_complete_cb(void)



void cdc_sigrok_line_state_cb(bool dtr, bool rts)
/**
* Flush tinyusb buffers on connect/disconnect.
* This seems to be necessary to survive e.g. a restart of the host (Linux)
*/
{
#if CFG_TUD_CDC_SIGROK
tud_cdc_n_write_clear(CDC_SIGROK_N);
tud_cdc_n_read_flush(CDC_SIGROK_N);
m_connected = (dtr || rts);;
xEventGroupSetBits(events, EV_STREAM);
#endif
} // cdc_uart_line_state_cb



void cdc_sigrok_write(const char *buf, int length)
{
#if 0
Expand Down Expand Up @@ -304,19 +322,27 @@ void cdc_sigrok_thread()
EventBits_t ev = EV_RX | EV_TX | EV_STREAM;
size_t cdc_rx_chars;

if ( !m_connected) {
// wait here until connected (and until my terminal program is ready)
while ( !m_connected) {
xEventGroupWaitBits(events, EV_RX | EV_TX | EV_STREAM, pdTRUE, pdFALSE, pdMS_TO_TICKS(1000));
}
vTaskDelay(pdMS_TO_TICKS(100));
}

cdc_rx_chars = tud_cdc_n_available(CDC_SIGROK_N);
if (cdc_rx_chars == 0 && xStreamBufferIsEmpty(stream_sigrok)) {
// -> nothing left to do: sleep for a long time
tud_cdc_n_write_flush(CDC_SIGROK_N);
ev = xEventGroupWaitBits(events, EV_RX | EV_TX | EV_STREAM | EV_RX, pdTRUE, pdFALSE, pdMS_TO_TICKS(10000));
ev = xEventGroupWaitBits(events, EV_RX | EV_TX | EV_STREAM, pdTRUE, pdFALSE, pdMS_TO_TICKS(10000));
}
else if (cdc_rx_chars != 0) {
// wait a short period if there are characters host -> probe -> target
ev = xEventGroupWaitBits(events, EV_RX | EV_TX | EV_STREAM | EV_RX, pdTRUE, pdFALSE, pdMS_TO_TICKS(1));
ev = xEventGroupWaitBits(events, EV_RX | EV_TX | EV_STREAM, pdTRUE, pdFALSE, pdMS_TO_TICKS(1));
}
else {
// wait until transmission via USB has finished
ev = xEventGroupWaitBits(events, EV_RX | EV_TX | EV_STREAM | EV_RX, pdTRUE, pdFALSE, pdMS_TO_TICKS(100));
ev = xEventGroupWaitBits(events, EV_RX | EV_TX | EV_STREAM, pdTRUE, pdFALSE, pdMS_TO_TICKS(100));
}

if (ev & EV_RX) {
Expand Down
1 change: 1 addition & 0 deletions src/pico-sigrok/cdc_sigrok.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void cdc_sigrok_init(uint32_t task_prio);
void cdc_sigrok_write(const char *buf, int length);
void cdc_sigrok_rx_cb(void);
void cdc_sigrok_tx_complete_cb(void);
void cdc_sigrok_line_state_cb(bool dtr, bool rts);

void core1_code();

Expand Down

0 comments on commit 8a6a9ad

Please sign in to comment.