Skip to content

Commit ddc028f

Browse files
committed
cdc_acm: turn on UART_TX LED when sending break signals
Software typically asserts line break for an extended period (e.g. PuTTY will assert continuously until the next keypress), so provide feedback via the LED. Also declare variables used in both tinyusb callback and uart_thread context as volatile.
1 parent af2540b commit ddc028f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/cdc_uart.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
#include "probe_config.h"
3333

3434
TaskHandle_t uart_taskhandle;
35-
TickType_t last_wake, interval = 100, break_expiry;
36-
bool timed_break;
35+
TickType_t last_wake, interval = 100;
36+
volatile TickType_t break_expiry;
37+
volatile bool timed_break;
3738

3839
/* Max 1 FIFO worth of data */
3940
static uint8_t tx_buf[32];
@@ -43,7 +44,7 @@ static uint8_t rx_buf[32];
4344
static uint debounce_ticks = 5;
4445

4546
#ifdef PROBE_UART_TX_LED
46-
static uint tx_led_debounce;
47+
static volatile uint tx_led_debounce;
4748
#endif
4849

4950
#ifdef PROBE_UART_RX_LED
@@ -145,6 +146,7 @@ bool cdc_task(void)
145146
if (((int)break_expiry - (int)xTaskGetTickCount()) < 0) {
146147
timed_break = false;
147148
uart_set_break(PROBE_UART_INTERFACE, false);
149+
tx_led_debounce = 0;
148150
} else {
149151
keep_alive = true;
150152
}
@@ -154,6 +156,7 @@ bool cdc_task(void)
154156
uart_set_break(PROBE_UART_INTERFACE, false);
155157
timed_break = false;
156158
was_connected = 0;
159+
tx_led_debounce = 0;
157160
cdc_tx_oe = 0;
158161
}
159162
return keep_alive;
@@ -275,11 +278,15 @@ void tud_cdc_send_break_cb(uint8_t itf, uint16_t wValue) {
275278
case 0xffff:
276279
uart_set_break(PROBE_UART_INTERFACE, true);
277280
timed_break = false;
281+
gpio_put(PROBE_UART_TX_LED, 1);
282+
tx_led_debounce = 1 << 30;
278283
break;
279284
default:
280285
uart_set_break(PROBE_UART_INTERFACE, true);
281286
timed_break = true;
287+
gpio_put(PROBE_UART_TX_LED, 1);
282288
break_expiry = xTaskGetTickCount() + (wValue * (configTICK_RATE_HZ / 1000));
289+
tx_led_debounce = 1 << 30;
283290
break;
284291
}
285292
}

0 commit comments

Comments
 (0)