Skip to content

Commit 06c7792

Browse files
committed
main: kludge for Pi 5 reboot crashes
The Pi 5 bootloader will leave devices it doesn't care about in the Addressed state, so tud_mount_cb never gets called. Handoff from the bootloader to Linux causes a suspend event followed by Reset. Check if the interface association was configured on entry to Suspend or Resume. Also, TinyUSB doesn't expose Bus Reset events for whatever reason, so there's nothing that tears down the interface threads.
1 parent 1752f2a commit 06c7792

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/main.c

+19-9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static uint8_t RxDataBuffer[CFG_TUD_HID_EP_BUFSIZE];
6060

6161
TaskHandle_t dap_taskhandle, tud_taskhandle, mon_taskhandle;
6262

63+
static int was_configured;
64+
6365
void dev_mon(void *ptr)
6466
{
6567
uint32_t sof[3];
@@ -224,17 +226,21 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
224226
void tud_suspend_cb(bool remote_wakeup_en)
225227
{
226228
probe_info("Suspended\n");
227-
/* Join DAP and UART threads? Or just suspend them, for transparency */
228-
vTaskSuspend(uart_taskhandle);
229-
vTaskSuspend(dap_taskhandle);
229+
/* Were we actually configured? If not, threads don't exist */
230+
if (was_configured) {
231+
vTaskSuspend(uart_taskhandle);
232+
vTaskSuspend(dap_taskhandle);
233+
}
230234
/* slow down clk_sys for power saving ? */
231235
}
232236

233237
void tud_resume_cb(void)
234238
{
235239
probe_info("Resumed\n");
236-
vTaskResume(uart_taskhandle);
237-
vTaskResume(dap_taskhandle);
240+
if (was_configured) {
241+
vTaskResume(uart_taskhandle);
242+
vTaskResume(dap_taskhandle);
243+
}
238244
}
239245

240246
void tud_unmount_cb(void)
@@ -244,15 +250,19 @@ void tud_unmount_cb(void)
244250
vTaskSuspend(dap_taskhandle);
245251
vTaskDelete(uart_taskhandle);
246252
vTaskDelete(dap_taskhandle);
253+
was_configured = 0;
247254
}
248255

249256
void tud_mount_cb(void)
250257
{
251258
probe_info("Connected, Configured\n");
252-
/* UART needs to preempt USB as if we don't, characters get lost */
253-
xTaskCreate(cdc_thread, "UART", configMINIMAL_STACK_SIZE, NULL, UART_TASK_PRIO, &uart_taskhandle);
254-
/* Lowest priority thread is debug - need to shuffle buffers before we can toggle swd... */
255-
xTaskCreate(dap_thread, "DAP", configMINIMAL_STACK_SIZE, NULL, DAP_TASK_PRIO, &dap_taskhandle);
259+
if (!was_configured) {
260+
/* UART needs to preempt USB as if we don't, characters get lost */
261+
xTaskCreate(cdc_thread, "UART", configMINIMAL_STACK_SIZE, NULL, UART_TASK_PRIO, &uart_taskhandle);
262+
/* Lowest priority thread is debug - need to shuffle buffers before we can toggle swd... */
263+
xTaskCreate(dap_thread, "DAP", configMINIMAL_STACK_SIZE, NULL, DAP_TASK_PRIO, &dap_taskhandle);
264+
was_configured = 1;
265+
}
256266
}
257267

258268
void vApplicationTickHook (void)

0 commit comments

Comments
 (0)