Skip to content

Commit 6ff586a

Browse files
authored
Merge pull request #1061 from LedgerHQ/tjo_backport_fix_start_stop_usb
[io/usb]: handle properly the USB stop/start for apps that don't use …
2 parents d1f8334 + 558c053 commit 6ff586a

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

io_legacy/src/os_io_legacy.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ int io_legacy_apdu_rx(uint8_t handle_ux_events)
392392
io_os_legacy_apdu_type, G_io_tx_buffer, buffer_out_length, 0);
393393
io_os_legacy_apdu_type = APDU_TYPE_NONE;
394394
if (post_action == OS_IO_APDU_POST_ACTION_EXIT) {
395+
#ifndef USE_OS_IO_STACK
396+
os_io_stop();
397+
#endif // USE_OS_IO_STACK
395398
os_sched_exit(-1);
396399
}
397400
if (status > 0) {

lib_standard_app/io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ WEAK int io_send_response_buffers(const buffer_t *rdatalist, size_t count, uint1
155155
}
156156
else {
157157
PRINTF("Unrecoverable\n");
158+
#ifndef USE_OS_IO_STACK
159+
os_io_stop();
160+
#endif // USE_OS_IO_STACK
158161
os_sched_exit(-1);
159162
}
160163
}

lib_standard_app/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ bolos_ux_params_t G_ux_params;
3939
*/
4040
WEAK void __attribute__((noreturn)) app_exit(void)
4141
{
42+
#ifndef USE_OS_IO_STACK
43+
os_io_stop();
44+
#endif // USE_OS_IO_STACK
4245
os_sched_exit(-1);
4346
}
4447

lib_stusb/src/usbd_ledger.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ void USBD_LEDGER_init(os_io_init_usb_t *init, uint8_t force_restart)
433433
if ((force_restart) || (usbd_ledger_data.state < USBD_LEDGER_STATE_INITIALIZED)) {
434434
// First time USB is started or forced to restart
435435
memset(&usbd_ledger_data, 0, sizeof(usbd_ledger_data));
436-
usbd_ledger_data.state = USBD_LEDGER_STATE_STOPPED;
436+
usbd_ledger_data.state = USBD_LEDGER_STATE_INITIALIZED;
437437
LOG_IO("USBD_LEDGER_init deep\n");
438438
}
439439
else {
@@ -494,8 +494,8 @@ void USBD_LEDGER_start(void)
494494
// or wanted classes have changed
495495
// or vendor ID has changed
496496

497-
if (usbd_ledger_data.state == USBD_LEDGER_STATE_RUNNING) {
498-
USB_LEDGER_stop();
497+
if (usbd_ledger_data.state != USBD_LEDGER_STATE_STOPPED) {
498+
USBD_Stop(&usbd_ledger_data.usbd_handle);
499499
usbd_ledger_data.state = USBD_LEDGER_STATE_STOPPED;
500500
}
501501

@@ -640,8 +640,7 @@ void USBD_LEDGER_start(void)
640640
USBD_Init(&usbd_ledger_data.usbd_handle, (USBD_DescriptorsTypeDef*)(uintptr_t)&LEDGER_Desc, 0);
641641
USBD_RegisterClass(&usbd_ledger_data.usbd_handle, (USBD_ClassTypeDef *)(uintptr_t)&USBD_LEDGER_CLASS);
642642
}
643-
if ((usbd_ledger_data.state == USBD_LEDGER_STATE_STOPPED)
644-
|| (usbd_ledger_data.state == USBD_LEDGER_STATE_INITIALIZED)) {
643+
if (usbd_ledger_data.state == USBD_LEDGER_STATE_STOPPED) {
645644
USBD_Start(&usbd_ledger_data.usbd_handle);
646645
usbd_ledger_data.state = USBD_LEDGER_STATE_RUNNING;
647646
}

protocol/src/ledger_protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static ledger_protocol_result_t process_apdu_chunk(ledger_protocol_t *handle,
7373
}
7474
else {
7575
// Ledger Live is well known for sending empty apdu chunk
76-
// after the last apdu chunk fits totaly in the MTU
76+
// after the last apdu chunk fits totally in the MTU
7777
return LP_SUCCESS;
7878
}
7979
}

0 commit comments

Comments
 (0)