From baff1691a0ece1fd72c787a1a1e35000c459d4c1 Mon Sep 17 00:00:00 2001 From: cepetr Date: Fri, 31 May 2024 13:25:47 +0200 Subject: [PATCH] feat(core/embed): prepare usb driver for low power mode [no changelog] --- core/embed/bootloader/main.c | 4 +- core/embed/bootloader_ci/main.c | 4 +- .../extmod/modtrezorio/modtrezorio-usb.h | 9 +- core/embed/prodtest/main.c | 4 +- .../trezorhal/stm32f4/usb/{usbd.c => usb.c} | 354 +++++++++++------- .../usb/{usbd_class_hid.c => usb_class_hid.c} | 4 +- .../usb/{usbd_class_vcp.c => usb_class_vcp.c} | 4 +- ...usbd_class_webusb.c => usb_class_webusb.c} | 4 +- .../usb/{usbd_internal.h => usb_internal.h} | 1 + core/embed/trezorhal/stm32f4/usb/usbd_def.h | 1 + core/embed/trezorhal/unix/usb.c | 7 +- core/embed/trezorhal/usb.h | 70 +++- core/site_scons/models/D001/discovery.py | 8 +- core/site_scons/models/D002/discovery2.py | 8 +- core/site_scons/models/T1B1/trezor_1.py | 8 +- core/site_scons/models/T2B1/trezor_r_v10.py | 8 +- core/site_scons/models/T2B1/trezor_r_v3.py | 8 +- core/site_scons/models/T2B1/trezor_r_v4.py | 8 +- core/site_scons/models/T2B1/trezor_r_v6.py | 8 +- core/site_scons/models/T2T1/trezor_t.py | 8 +- .../models/T3T1/trezor_t3t1_revE.py | 8 +- core/site_scons/models/T3T1/trezor_t3t1_v4.py | 8 +- 22 files changed, 348 insertions(+), 198 deletions(-) rename core/embed/trezorhal/stm32f4/usb/{usbd.c => usb.c} (70%) rename core/embed/trezorhal/stm32f4/usb/{usbd_class_hid.c => usb_class_hid.c} (99%) rename core/embed/trezorhal/stm32f4/usb/{usbd_class_vcp.c => usb_class_vcp.c} (99%) rename core/embed/trezorhal/stm32f4/usb/{usbd_class_webusb.c => usb_class_webusb.c} (99%) rename core/embed/trezorhal/stm32f4/usb/{usbd_internal.h => usb_internal.h} (99%) diff --git a/core/embed/bootloader/main.c b/core/embed/bootloader/main.c index af6dce6b16..4596373540 100644 --- a/core/embed/bootloader/main.c +++ b/core/embed/bootloader/main.c @@ -122,11 +122,11 @@ static void usb_init_all(secbool usb21_landing) { .polling_interval = 1, }; - usb_init(&dev_info); + ensure(usb_init(&dev_info), NULL); ensure(usb_webusb_add(&webusb_info), NULL); - usb_start(); + ensure(usb_start(), NULL); } static usb_result_t bootloader_usb_loop(const vendor_header *const vhdr, diff --git a/core/embed/bootloader_ci/main.c b/core/embed/bootloader_ci/main.c index ca60278ee3..f9dfe64a24 100644 --- a/core/embed/bootloader_ci/main.c +++ b/core/embed/bootloader_ci/main.c @@ -78,11 +78,11 @@ static void usb_init_all(secbool usb21_landing) { .polling_interval = 1, }; - usb_init(&dev_info); + ensure(usb_init(&dev_info), NULL); ensure(usb_webusb_add(&webusb_info), NULL); - usb_start(); + ensure(usb_start(), NULL); } static secbool bootloader_usb_loop(const vendor_header *const vhdr, diff --git a/core/embed/extmod/modtrezorio/modtrezorio-usb.h b/core/embed/extmod/modtrezorio/modtrezorio-usb.h index bdc036d57e..3afcc7846d 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-usb.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-usb.h @@ -190,7 +190,9 @@ STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t self, mp_obj_get_array(MP_OBJ_FROM_PTR(&o->ifaces), &iface_cnt, &iface_objs); // Initialize the USB stack - usb_init(&o->info); + if (sectrue != usb_init(&o->info)) { + mp_raise_msg(&mp_type_RuntimeError, "failed to initialize usb driver"); + } int vcp_iface_num = -1; @@ -224,7 +226,10 @@ STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t self, } // Start the USB stack - usb_start(); + if (sectrue != usb_start()) { + usb_deinit(); + mp_raise_msg(&mp_type_RuntimeError, "failed to start usb driver"); + } o->state = USB_OPENED; // If we found any VCP interfaces, use the last one for stdio, diff --git a/core/embed/prodtest/main.c b/core/embed/prodtest/main.c index 2a50696adb..ced3767a46 100644 --- a/core/embed/prodtest/main.c +++ b/core/embed/prodtest/main.c @@ -155,9 +155,9 @@ static void usb_init_all(void) { .max_packet_len = VCP_PACKET_LEN, }; - usb_init(&dev_info); + ensure(usb_init(&dev_info), NULL); ensure(usb_vcp_add(&vcp_info), "usb_vcp_add"); - usb_start(); + ensure(usb_start(), NULL); } static void draw_border(int width, int padding) { diff --git a/core/embed/trezorhal/stm32f4/usb/usbd.c b/core/embed/trezorhal/stm32f4/usb/usb.c similarity index 70% rename from core/embed/trezorhal/stm32f4/usb/usbd.c rename to core/embed/trezorhal/stm32f4/usb/usb.c index 8b9f35f620..e82ccebaa5 100644 --- a/core/embed/trezorhal/stm32f4/usb/usbd.c +++ b/core/embed/trezorhal/stm32f4/usb/usb.c @@ -19,12 +19,11 @@ #include STM32_HAL_H +#include "usb.h" #include "common.h" #include "random_delays.h" #include "secbool.h" -#include "usb.h" -#include "usbd_core.h" -#include "usbd_internal.h" +#include "usb_internal.h" #define USB_MAX_CONFIG_DESC_SIZE 256 #define USB_MAX_STR_SIZE 62 @@ -55,6 +54,8 @@ typedef struct { } usb_iface_t; typedef struct { + // Set if the driver is initialized + secbool initialized; // Handle to the USB device (lower layer driver) USBD_HandleTypeDef dev_handle; // Device descriptor @@ -75,10 +76,17 @@ typedef struct { secbool usb21_enabled; secbool usb21_landing; + // Time (in ticks) when we've seen the USB ready last time + uint32_t ready_time; + // Set to `sectrue` if the USB stack was ready sinced the last start + secbool was_ready; + } usb_driver_t; // USB driver instance -static usb_driver_t g_usb_driver; +static usb_driver_t g_usb_driver = { + .initialized = secfalse, +}; // forward declarations of dispatch functions static const USBD_ClassTypeDef usb_class; @@ -90,126 +98,198 @@ static secbool __wur check_desc_str(const char *s) { return sectrue; } -void usb_init(const usb_dev_info_t *dev_info) { - usb_driver_t *usb = &g_usb_driver; +secbool usb_init(const usb_dev_info_t *dev_info) { + usb_driver_t *drv = &g_usb_driver; + + if (drv->initialized == sectrue) { + // Already initialized + return sectrue; + } + + memset(drv, 0, sizeof(usb_driver_t)); // enable/disable USB 2.1 features - usb->usb21_enabled = dev_info->usb21_enabled; - usb->usb21_landing = dev_info->usb21_landing; + drv->usb21_enabled = dev_info->usb21_enabled; + drv->usb21_landing = dev_info->usb21_landing; // Device descriptor - usb->dev_desc.bLength = sizeof(usb_device_descriptor_t); - usb->dev_desc.bDescriptorType = USB_DESC_TYPE_DEVICE; - usb->dev_desc.bcdUSB = - (sectrue == usb->usb21_enabled) ? 0x0210 : 0x0200; // USB 2.1 or USB 2.0 - usb->dev_desc.bDeviceClass = dev_info->device_class; - usb->dev_desc.bDeviceSubClass = dev_info->device_subclass; - usb->dev_desc.bDeviceProtocol = dev_info->device_protocol; - usb->dev_desc.bMaxPacketSize0 = USB_MAX_EP0_SIZE; - usb->dev_desc.idVendor = dev_info->vendor_id; - usb->dev_desc.idProduct = dev_info->product_id; - usb->dev_desc.bcdDevice = dev_info->release_num; - usb->dev_desc.iManufacturer = + drv->dev_desc.bLength = sizeof(usb_device_descriptor_t); + drv->dev_desc.bDescriptorType = USB_DESC_TYPE_DEVICE; + drv->dev_desc.bcdUSB = + (sectrue == drv->usb21_enabled) ? 0x0210 : 0x0200; // USB 2.1 or USB 2.0 + drv->dev_desc.bDeviceClass = dev_info->device_class; + drv->dev_desc.bDeviceSubClass = dev_info->device_subclass; + drv->dev_desc.bDeviceProtocol = dev_info->device_protocol; + drv->dev_desc.bMaxPacketSize0 = USB_MAX_EP0_SIZE; + drv->dev_desc.idVendor = dev_info->vendor_id; + drv->dev_desc.idProduct = dev_info->product_id; + drv->dev_desc.bcdDevice = dev_info->release_num; + drv->dev_desc.iManufacturer = USBD_IDX_MFC_STR; // Index of manufacturer string - usb->dev_desc.iProduct = USBD_IDX_PRODUCT_STR; // Index of product string - usb->dev_desc.iSerialNumber = + drv->dev_desc.iProduct = USBD_IDX_PRODUCT_STR; // Index of product string + drv->dev_desc.iSerialNumber = USBD_IDX_SERIAL_STR; // Index of serial number string - usb->dev_desc.bNumConfigurations = 1; + drv->dev_desc.bNumConfigurations = 1; // String table - ensure(check_desc_str(dev_info->manufacturer), NULL); - ensure(check_desc_str(dev_info->product), NULL); - ensure(check_desc_str(dev_info->serial_number), NULL); - ensure(check_desc_str(dev_info->interface), NULL); + if (sectrue != check_desc_str(dev_info->manufacturer)) { + return secfalse; + } + if (sectrue != check_desc_str(dev_info->product)) { + return secfalse; + } + if (sectrue != check_desc_str(dev_info->serial_number)) { + return secfalse; + } + if (sectrue != check_desc_str(dev_info->interface)) { + return secfalse; + } - usb->str_table.manufacturer = dev_info->manufacturer; - usb->str_table.product = dev_info->product; - usb->str_table.serial_number = dev_info->serial_number; - usb->str_table.interface = dev_info->interface; + drv->str_table.manufacturer = dev_info->manufacturer; + drv->str_table.product = dev_info->product; + drv->str_table.serial_number = dev_info->serial_number; + drv->str_table.interface = dev_info->interface; - usb->config_desc = (usb_config_descriptor_t *)(usb->desc_buffer); + drv->config_desc = (usb_config_descriptor_t *)(drv->desc_buffer); // Configuration descriptor - usb->config_desc->bLength = sizeof(usb_config_descriptor_t); - usb->config_desc->bDescriptorType = USB_DESC_TYPE_CONFIGURATION; - usb->config_desc->wTotalLength = + drv->config_desc->bLength = sizeof(usb_config_descriptor_t); + drv->config_desc->bDescriptorType = USB_DESC_TYPE_CONFIGURATION; + drv->config_desc->wTotalLength = sizeof(usb_config_descriptor_t); // will be updated later via // usb_alloc_class_descriptors() - usb->config_desc->bNumInterfaces = + drv->config_desc->bNumInterfaces = 0; // will be updated later via usb_set_iface_class() - usb->config_desc->bConfigurationValue = 0x01; - usb->config_desc->iConfiguration = 0; - usb->config_desc->bmAttributes = + drv->config_desc->bConfigurationValue = 0x01; + drv->config_desc->iConfiguration = 0; + drv->config_desc->bmAttributes = 0x80; // 0x80 = bus powered; 0xC0 = self powered - usb->config_desc->bMaxPower = 0x32; // Maximum Power Consumption in 2mA units + drv->config_desc->bMaxPower = 0x32; // Maximum Power Consumption in 2mA units - ensure(sectrue * - (USBD_OK == USBD_Init(&usb->dev_handle, - (USBD_DescriptorsTypeDef *)&usb_descriptors, - USB_PHY_ID)), - NULL); - ensure(sectrue * - (USBD_OK == USBD_RegisterClass(&usb->dev_handle, - (USBD_ClassTypeDef *)&usb_class)), - NULL); + drv->initialized = sectrue; + + return sectrue; } void usb_deinit(void) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - USBD_DeInit(&usb->dev_handle); - for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { - usb->ifaces[i].class = NULL; + if (drv->initialized != sectrue) { + return; } + + usb_stop(); + + drv->initialized = secfalse; } -void usb_start(void) { - usb_driver_t *usb = &g_usb_driver; +secbool usb_start(void) { + usb_driver_t *drv = &g_usb_driver; - USBD_Start(&usb->dev_handle); + if (drv->initialized != sectrue) { + // The driver is not initialized + return secfalse; + } + + if (drv->dev_handle.dev_state != USBD_STATE_UNINITIALIZED) { + // The driver has been started already + return sectrue; + } + + drv->was_ready = secfalse; + + if (USBD_OK != USBD_Init(&drv->dev_handle, + (USBD_DescriptorsTypeDef *)&usb_descriptors, + USB_PHY_ID)) { + usb_stop(); + return secfalse; + } + + if (USBD_OK != + USBD_RegisterClass(&drv->dev_handle, (USBD_ClassTypeDef *)&usb_class)) { + usb_stop(); + return secfalse; + } + + if (USBD_OK != USBD_Start(&drv->dev_handle)) { + usb_stop(); + return secfalse; + } + + return sectrue; } void usb_stop(void) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - USBD_Stop(&usb->dev_handle); + if (drv->initialized != sectrue) { + // The driver is not initialized + return; + } + + if (drv->dev_handle.dev_state == USBD_STATE_UNINITIALIZED) { + // The driver is already stopped + return; + } + + USBD_DeInit(&drv->dev_handle); + + // Set drv->dev_handle.dev_state to USBD_STATE_INITIALIZED + memset(&drv->dev_handle, 0, sizeof(drv->dev_handle)); } secbool usb_configured(void) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; + + if (drv->initialized != sectrue) { + // The driver is not initialized + return secfalse; + } + + const USBD_HandleTypeDef *pdev = &drv->dev_handle; + + if (pdev->dev_state == USBD_STATE_UNINITIALIZED) { + // The driver has not been started yet + return secfalse; + } + + secbool powered_from_usb = sectrue; // TODO + + secbool ready = secfalse; + + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + // USB is configured, ready to transfer data + ready = sectrue; + } else if (pdev->dev_state == USBD_STATE_SUSPENDED && + pdev->dev_old_state == USBD_STATE_CONFIGURED) { + // USB is suspended, but was configured before + // + // Linux has autosuspend device after 2 seconds by default. + // So a suspended device that was seen as configured is reported as + // configured. + // + ready = sectrue; + } else if ((drv->was_ready == secfalse) && (powered_from_usb == sectrue)) { + // First run after the startup with USB power + drv->was_ready = sectrue; + ready = sectrue; + } + + // This is a workaround to handle the glitches in the USB connection, + // especially for USB-powered-only devices. This should be + // revisited and probably fixed elsewhere. - static uint32_t usb_configured_last_ok = 0; uint32_t ticks = hal_ticks_ms(); - const USBD_HandleTypeDef *pdev = &usb->dev_handle; - if (pdev->dev_state == USBD_STATE_CONFIGURED) { - usb_configured_last_ok = hal_ticks_ms(); - return sectrue; + if (ready == sectrue) { + drv->ready_time = ticks; + } else if ((drv->was_ready == sectrue) && (ticks - drv->ready_time) < 2000) { + // NOTE: When the timer overflows the timeout is shortened. + // We are ignoring it for now. + ready = sectrue; } - // Linux has autosuspend device after 2 seconds by default. - // So a suspended device that was seen as configured is reported as - // configured. - if (pdev->dev_state == USBD_STATE_SUSPENDED && - pdev->dev_old_state == USBD_STATE_CONFIGURED) { - usb_configured_last_ok = hal_ticks_ms(); - return sectrue; - } - - if (usb_configured_last_ok == 0) { - usb_configured_last_ok = ticks; - return sectrue; - } - if (usb_configured_last_ok > ticks) { - // probably overflow of 32bit ms counter, ignore as its just once in a long - // time - return sectrue; - } - if ((hal_ticks_ms() - usb_configured_last_ok) < 2000) { - return sectrue; - } - - return secfalse; + return ready; } // ========================================================================== @@ -217,10 +297,10 @@ secbool usb_configured(void) { // ========================================================================== void *usb_get_iface_state(uint8_t iface_num, const USBD_ClassTypeDef *class) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; if (iface_num < USBD_MAX_NUM_INTERFACES) { - usb_iface_t *iface = &usb->ifaces[iface_num]; + usb_iface_t *iface = &drv->ifaces[iface_num]; if (iface->class == class) { return &iface->state; @@ -232,14 +312,14 @@ void *usb_get_iface_state(uint8_t iface_num, const USBD_ClassTypeDef *class) { } void usb_set_iface_class(uint8_t iface_num, const USBD_ClassTypeDef *class) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; if (iface_num < USBD_MAX_NUM_INTERFACES) { - if (usb->ifaces[iface_num].class == NULL && class != NULL) { - usb->config_desc->bNumInterfaces++; + if (drv->ifaces[iface_num].class == NULL && class != NULL) { + drv->config_desc->bNumInterfaces++; } - usb->ifaces[iface_num].class = class; + drv->ifaces[iface_num].class = class; } } @@ -252,9 +332,9 @@ USBD_HandleTypeDef *usb_get_dev_handle(void) { void *usb_alloc_class_descriptors(size_t desc_len) { usb_driver_t *usb = &g_usb_driver; - if (usb->config_desc->wTotalLength + desc_len < USB_MAX_CONFIG_DESC_SIZE) { - void *retval = &usb->desc_buffer[usb->config_desc->wTotalLength]; - usb->config_desc->wTotalLength += desc_len; + if (drv->config_desc->wTotalLength + desc_len < USB_MAX_CONFIG_DESC_SIZE) { + void *retval = &drv->desc_buffer[drv->config_desc->wTotalLength]; + drv->config_desc->wTotalLength += desc_len; return retval; } else { return NULL; // Not enough space in the descriptor @@ -267,10 +347,10 @@ void *usb_alloc_class_descriptors(size_t desc_len) { static uint8_t *usb_get_dev_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - *length = sizeof(usb->dev_desc); - return (uint8_t *)(&usb->dev_desc); + *length = sizeof(drv->dev_desc); + return (uint8_t *)(&drv->dev_desc); } static uint8_t *usb_get_langid_str_descriptor(USBD_SpeedTypeDef speed, @@ -286,49 +366,49 @@ static uint8_t *usb_get_langid_str_descriptor(USBD_SpeedTypeDef speed, static uint8_t *usb_get_manufacturer_str_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - USBD_GetString((uint8_t *)usb->str_table.manufacturer, usb->str_buf, length); - return usb->str_buf; + USBD_GetString((uint8_t *)drv->str_table.manufacturer, drv->str_buf, length); + return drv->str_buf; } static uint8_t *usb_get_product_str_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - USBD_GetString((uint8_t *)usb->str_table.product, usb->str_buf, length); - return usb->str_buf; + USBD_GetString((uint8_t *)drv->str_table.product, drv->str_buf, length); + return drv->str_buf; } static uint8_t *usb_get_serial_str_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - USBD_GetString((uint8_t *)usb->str_table.serial_number, usb->str_buf, length); - return usb->str_buf; + USBD_GetString((uint8_t *)drv->str_table.serial_number, drv->str_buf, length); + return drv->str_buf; } static uint8_t *usb_get_configuration_str_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - USBD_GetString((uint8_t *)"", usb->str_buf, length); - return usb->str_buf; + USBD_GetString((uint8_t *)"", drv->str_buf, length); + return drv->str_buf; } static uint8_t *usb_get_interface_str_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - USBD_GetString((uint8_t *)usb->str_table.interface, usb->str_buf, length); - return usb->str_buf; + USBD_GetString((uint8_t *)drv->str_table.interface, drv->str_buf, length); + return drv->str_buf; } static uint8_t *usb_get_bos_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - if (sectrue == usb->usb21_enabled) { + if (sectrue == drv->usb21_enabled) { static uint8_t bos[] = { // usb_bos_descriptor { 0x05, // uint8_t bLength @@ -348,7 +428,7 @@ static uint8_t *usb_get_bos_descriptor(USBD_SpeedTypeDef speed, USB_WEBUSB_LANDING_PAGE, // uint8_t iLandingPage // } }; - bos[28] = (sectrue == usb->usb21_landing) ? USB_WEBUSB_LANDING_PAGE : 0; + bos[28] = (sectrue == drv->usb21_landing) ? USB_WEBUSB_LANDING_PAGE : 0; *length = sizeof(bos); return UNCONST(bos); } else { @@ -383,10 +463,10 @@ static const USBD_DescriptorsTypeDef usb_descriptors = { #define USB_WINUSB_REQ_GET_EXTENDED_PROPERTIES_OS_FEATURE_DESCRIPTOR 0x05 static uint8_t usb_class_init(USBD_HandleTypeDef *dev, uint8_t cfg_idx) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { - usb_iface_t *iface = &usb->ifaces[i]; + usb_iface_t *iface = &drv->ifaces[i]; if (iface->class != NULL && iface->class->Init != NULL) { dev->pUserData = iface->state; iface->class->Init(dev, cfg_idx); @@ -399,10 +479,10 @@ static uint8_t usb_class_init(USBD_HandleTypeDef *dev, uint8_t cfg_idx) { } static uint8_t usb_class_deinit(USBD_HandleTypeDef *dev, uint8_t cfg_idx) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { - usb_iface_t *iface = &usb->ifaces[i]; + usb_iface_t *iface = &drv->ifaces[i]; if (iface->class != NULL && iface->class->DeInit != NULL) { dev->pUserData = iface->state; iface->class->DeInit(dev, cfg_idx); @@ -421,7 +501,7 @@ static uint8_t usb_class_deinit(USBD_HandleTypeDef *dev, uint8_t cfg_idx) { static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, USBD_SetupReqTypedef *req) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; if (((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_CLASS) && ((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD) && @@ -431,7 +511,7 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, if ((req->bmRequest & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_VENDOR) { if ((req->bmRequest & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE) { - if (sectrue == usb->usb21_enabled && + if (sectrue == drv->usb21_enabled && req->bRequest == USB_WEBUSB_VENDOR_CODE) { if (req->wIndex == USB_WEBUSB_REQ_GET_URL && req->wValue == USB_WEBUSB_LANDING_PAGE) { @@ -464,7 +544,7 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, USBD_CtlError(dev, req); return USBD_FAIL; } - } else if (sectrue == usb->usb21_enabled && + } else if (sectrue == drv->usb21_enabled && req->bRequest == USB_WINUSB_VENDOR_CODE) { if (req->wIndex == USB_WINUSB_REQ_GET_COMPATIBLE_ID_FEATURE_DESCRIPTOR) { @@ -497,7 +577,7 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, } if ((req->bmRequest & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_INTERFACE) { - if (sectrue == usb->usb21_enabled && + if (sectrue == drv->usb21_enabled && req->bRequest == USB_WINUSB_VENDOR_CODE) { if (req->wIndex == USB_WINUSB_REQ_GET_EXTENDED_PROPERTIES_OS_FEATURE_DESCRIPTOR && @@ -544,7 +624,7 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, return USBD_FAIL; } - usb_iface_t *iface = &usb->ifaces[req->wIndex]; + usb_iface_t *iface = &drv->ifaces[req->wIndex]; if (iface->class != NULL && iface->class->Setup != NULL) { dev->pUserData = iface->state; iface->class->Setup(dev, req); @@ -559,14 +639,14 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, } static uint8_t usb_class_data_in(USBD_HandleTypeDef *dev, uint8_t ep_num) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; #ifdef RDI rdi_refresh_session_delay(); #endif for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { - usb_iface_t *iface = &usb->ifaces[i]; + usb_iface_t *iface = &drv->ifaces[i]; if (iface->class != NULL && iface->class->DataIn != NULL) { dev->pUserData = iface->state; iface->class->DataIn(dev, ep_num); @@ -579,14 +659,14 @@ static uint8_t usb_class_data_in(USBD_HandleTypeDef *dev, uint8_t ep_num) { } static uint8_t usb_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; #ifdef RDI rdi_refresh_session_delay(); #endif for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { - usb_iface_t *iface = &usb->ifaces[i]; + usb_iface_t *iface = &drv->ifaces[i]; if (iface->class != NULL && iface->class->DataOut != NULL) { dev->pUserData = iface->state; iface->class->DataOut(dev, ep_num); @@ -599,10 +679,10 @@ static uint8_t usb_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) { } static uint8_t usb_class_sof(USBD_HandleTypeDef *dev) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { - usb_iface_t *iface = &usb->ifaces[i]; + usb_iface_t *iface = &drv->ifaces[i]; if (iface->class != NULL && iface->class->SOF != NULL) { dev->pUserData = iface->state; iface->class->SOF(dev); @@ -615,17 +695,17 @@ static uint8_t usb_class_sof(USBD_HandleTypeDef *dev) { } static uint8_t *usb_class_get_cfg_desc(uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - *length = usb->config_desc->wTotalLength; - return usb->desc_buffer; + *length = drv->config_desc->wTotalLength; + return drv->desc_buffer; } static uint8_t *usb_class_get_usrstr_desc(USBD_HandleTypeDef *dev, uint8_t index, uint16_t *length) { - usb_driver_t *usb = &g_usb_driver; + usb_driver_t *drv = &g_usb_driver; - if (sectrue == usb->usb21_enabled && index == USB_WINUSB_EXTRA_STRING_INDEX) { + if (sectrue == drv->usb21_enabled && index == USB_WINUSB_EXTRA_STRING_INDEX) { static const uint8_t winusb_string_descriptor[] = { 0x12, // bLength USB_DESC_TYPE_STRING, // bDescriptorType diff --git a/core/embed/trezorhal/stm32f4/usb/usbd_class_hid.c b/core/embed/trezorhal/stm32f4/usb/usb_class_hid.c similarity index 99% rename from core/embed/trezorhal/stm32f4/usb/usbd_class_hid.c rename to core/embed/trezorhal/stm32f4/usb/usb_class_hid.c index cddb6f10b4..54ea28b83b 100644 --- a/core/embed/trezorhal/stm32f4/usb/usbd_class_hid.c +++ b/core/embed/trezorhal/stm32f4/usb/usb_class_hid.c @@ -20,10 +20,8 @@ #include "common.h" #include "random_delays.h" -#include "usbd_core.h" -#include "usbd_internal.h" - #include "usb_hid.h" +#include "usb_internal.h" #define USB_CLASS_HID 0x03 diff --git a/core/embed/trezorhal/stm32f4/usb/usbd_class_vcp.c b/core/embed/trezorhal/stm32f4/usb/usb_class_vcp.c similarity index 99% rename from core/embed/trezorhal/stm32f4/usb/usbd_class_vcp.c rename to core/embed/trezorhal/stm32f4/usb/usb_class_vcp.c index d30f308bbd..bb1d5c55b6 100644 --- a/core/embed/trezorhal/stm32f4/usb/usbd_class_vcp.c +++ b/core/embed/trezorhal/stm32f4/usb/usb_class_vcp.c @@ -19,9 +19,7 @@ #include "common.h" -#include "usbd_core.h" -#include "usbd_internal.h" - +#include "usb_internal.h" #include "usb_vcp.h" // Communications Device Class Code (bFunctionClass, bInterfaceClass) diff --git a/core/embed/trezorhal/stm32f4/usb/usbd_class_webusb.c b/core/embed/trezorhal/stm32f4/usb/usb_class_webusb.c similarity index 99% rename from core/embed/trezorhal/stm32f4/usb/usbd_class_webusb.c rename to core/embed/trezorhal/stm32f4/usb/usb_class_webusb.c index 55fc5448c5..8916a4b9af 100644 --- a/core/embed/trezorhal/stm32f4/usb/usbd_class_webusb.c +++ b/core/embed/trezorhal/stm32f4/usb/usb_class_webusb.c @@ -20,9 +20,7 @@ #include "common.h" #include "random_delays.h" -#include "usbd_core.h" -#include "usbd_internal.h" - +#include "usb_internal.h" #include "usb_webusb.h" #define USB_CLASS_WEBUSB 0xFF diff --git a/core/embed/trezorhal/stm32f4/usb/usbd_internal.h b/core/embed/trezorhal/stm32f4/usb/usb_internal.h similarity index 99% rename from core/embed/trezorhal/stm32f4/usb/usbd_internal.h rename to core/embed/trezorhal/stm32f4/usb/usb_internal.h index 9becc8dcc5..0ff961d5bc 100644 --- a/core/embed/trezorhal/stm32f4/usb/usbd_internal.h +++ b/core/embed/trezorhal/stm32f4/usb/usb_internal.h @@ -21,6 +21,7 @@ #define TREZORHAL_USBD_INTERNAL_H #include +#include "usbd_core.h" #define USB_EP_DIR_MASK 0x80 #define USB_EP_DIR_OUT 0x00 diff --git a/core/embed/trezorhal/stm32f4/usb/usbd_def.h b/core/embed/trezorhal/stm32f4/usb/usbd_def.h index 82e9f08720..ec5a83da95 100644 --- a/core/embed/trezorhal/stm32f4/usb/usbd_def.h +++ b/core/embed/trezorhal/stm32f4/usb/usbd_def.h @@ -118,6 +118,7 @@ #define USB_MAX_EP0_SIZE 64 /* Device Status */ +#define USBD_STATE_UNINITIALIZED 0 #define USBD_STATE_DEFAULT 1 #define USBD_STATE_ADDRESSED 2 #define USBD_STATE_CONFIGURED 3 diff --git a/core/embed/trezorhal/unix/usb.c b/core/embed/trezorhal/unix/usb.c index 0f628e94f7..f5c1a00e75 100644 --- a/core/embed/trezorhal/unix/usb.c +++ b/core/embed/trezorhal/unix/usb.c @@ -53,7 +53,7 @@ static struct { socklen_t slen; } usb_ifaces[USBD_MAX_NUM_INTERFACES]; -void usb_init(const usb_dev_info_t *dev_info) { +secbool usb_init(const usb_dev_info_t *dev_info) { (void)dev_info; for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { usb_ifaces[i].type = USB_IFACE_TYPE_DISABLED; @@ -63,11 +63,12 @@ void usb_init(const usb_dev_info_t *dev_info) { memzero(&usb_ifaces[i].si_other, sizeof(struct sockaddr_in)); usb_ifaces[i].slen = 0; } + return sectrue; } void usb_deinit(void) {} -void usb_start(void) { +secbool usb_start(void) { const char *ip = getenv("TREZOR_UDP_IP"); // iterate interfaces @@ -96,6 +97,8 @@ void usb_start(void) { sizeof(struct sockaddr_in))), NULL); } + + return sectrue; } void usb_stop(void) { diff --git a/core/embed/trezorhal/usb.h b/core/embed/trezorhal/usb.h index 0922340e2b..c68c9f4c12 100644 --- a/core/embed/trezorhal/usb.h +++ b/core/embed/trezorhal/usb.h @@ -27,6 +27,38 @@ #include "usb_vcp.h" #include "usb_webusb.h" +// clang-format off +// +// USB stack high-level state machine +// ------------------------------------ +// +// +---------------+ +// ----> | Uninitialized | - Stack is completely uninitialized +// | +---------------+ +// | | +// | usb_init() +// usb_deinit() | +// | v +// | +---------------+ - Stack is partially initialized +// |-----| Initialized | - Ready for class registration +// | +---------------+ +// | | +// | N x usb_xxx_add() - Multiple class drivers can be registered +// | | +// | v +// | +---------------+ - Stack is completely initialized +// |-----| Stopped | - USB hardware left uninitialized +// | +---------------+ - Can go low power at this mode +// | | ^ +// | usb_start() | +// | | usb_stop() +// | v | +// | +---------------+ - USB hardware initialized +// ------| Running | - Stack is running if the USB host is connected +// +---------------+ +// +// clang-format on + typedef struct { uint8_t device_class; uint8_t device_subclass; @@ -42,10 +74,44 @@ typedef struct { secbool usb21_landing; } usb_dev_info_t; -void usb_init(const usb_dev_info_t *dev_info); +// Initializes USB stack +// +// When the USB driver is initialized, class drivers can be registered. +// After all class drivers are registered, `usb_start()` can be called. +// +// Returns `sectrue` if the initialization is successful. +secbool usb_init(const usb_dev_info_t *dev_info); + +// Deinitialize USB stack +// +// This function completely deinitializes the USB driver and all class drivers. +// After this function is called, `usb_init()` can be called again. void usb_deinit(void); -void usb_start(void); + +// Starts USB driver and its class drivers +// +// Initializes the USB stack (and hardware) and starts all registered class +// drivers. +// +// This function can called after all class drivers are registered or after +// `usb_stop()` is called. +// +// Returns `sectrue` if the USB stack is started successfully. +secbool usb_start(void); + +// Stops USB driver and its class drivers +// +// Unitializes the USB stack (and hardware) but leaves all configuration intact, +// so it can be started again with `usb_start()`. +// +// When the USB stack is stopped, it does not respond to any USB events and +// the CPU can go to stop/standby mode. void usb_stop(void); + +// Returns `sectrue` if the device is connected to the host (or is expected to +// be) +// +// TODO: Review and clarify the logic of this function in the future secbool usb_configured(void); #endif diff --git a/core/site_scons/models/D001/discovery.py b/core/site_scons/models/D001/discovery.py index c8e18fbe3a..68a6be7f62 100644 --- a/core/site_scons/models/D001/discovery.py +++ b/core/site_scons/models/D001/discovery.py @@ -76,14 +76,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32f4/usb/usbd_class_hid.c", - "embed/trezorhal/stm32f4/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32f4/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb_class_hid.c", + "embed/trezorhal/stm32f4/usb/usb_class_vcp.c", + "embed/trezorhal/stm32f4/usb/usb_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb.c", "embed/trezorhal/stm32f4/usb/usbd_conf.c", "embed/trezorhal/stm32f4/usb/usbd_core.c", "embed/trezorhal/stm32f4/usb/usbd_ctlreq.c", "embed/trezorhal/stm32f4/usb/usbd_ioreq.c", - "embed/trezorhal/stm32f4/usb/usbd.c", "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/D002/discovery2.py b/core/site_scons/models/D002/discovery2.py index 94e6fc7598..0fe7f4f9e2 100644 --- a/core/site_scons/models/D002/discovery2.py +++ b/core/site_scons/models/D002/discovery2.py @@ -82,14 +82,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32u5/usb/usbd_class_hid.c", - "embed/trezorhal/stm32u5/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32u5/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32u5/usb/usb_class_hid.c", + "embed/trezorhal/stm32u5/usb/usb_class_vcp.c", + "embed/trezorhal/stm32u5/usb/usb_class_webusb.c", + "embed/trezorhal/stm32u5/usb/usb.c", "embed/trezorhal/stm32u5/usb/usbd_conf.c", "embed/trezorhal/stm32u5/usb/usbd_core.c", "embed/trezorhal/stm32u5/usb/usbd_ctlreq.c", "embed/trezorhal/stm32u5/usb/usbd_ioreq.c", - "embed/trezorhal/stm32u5/usb/usbd.c", "vendor/stm32u5xx_hal_driver/Src/stm32u5xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/T1B1/trezor_1.py b/core/site_scons/models/T1B1/trezor_1.py index df938dfd9d..daaf9ff3c6 100644 --- a/core/site_scons/models/T1B1/trezor_1.py +++ b/core/site_scons/models/T1B1/trezor_1.py @@ -42,14 +42,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32f4/usb/usbd_class_hid.c", - "embed/trezorhal/stm32f4/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32f4/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb_class_hid.c", + "embed/trezorhal/stm32f4/usb/usb_class_vcp.c", + "embed/trezorhal/stm32f4/usb/usb_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb.c", "embed/trezorhal/stm32f4/usb/usbd_conf.c", "embed/trezorhal/stm32f4/usb/usbd_core.c", "embed/trezorhal/stm32f4/usb/usbd_ctlreq.c", "embed/trezorhal/stm32f4/usb/usbd_ioreq.c", - "embed/trezorhal/stm32f4/usb/usbd.c", "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/T2B1/trezor_r_v10.py b/core/site_scons/models/T2B1/trezor_r_v10.py index 7eb33ef442..9cb1723ea6 100644 --- a/core/site_scons/models/T2B1/trezor_r_v10.py +++ b/core/site_scons/models/T2B1/trezor_r_v10.py @@ -65,14 +65,14 @@ def configure( ] if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32f4/usb/usbd_class_hid.c", - "embed/trezorhal/stm32f4/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32f4/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb_class_hid.c", + "embed/trezorhal/stm32f4/usb/usb_class_vcp.c", + "embed/trezorhal/stm32f4/usb/usb_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb.c", "embed/trezorhal/stm32f4/usb/usbd_conf.c", "embed/trezorhal/stm32f4/usb/usbd_core.c", "embed/trezorhal/stm32f4/usb/usbd_ctlreq.c", "embed/trezorhal/stm32f4/usb/usbd_ioreq.c", - "embed/trezorhal/stm32f4/usb/usbd.c", "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/T2B1/trezor_r_v3.py b/core/site_scons/models/T2B1/trezor_r_v3.py index c7889b8f8e..a8809aab6b 100644 --- a/core/site_scons/models/T2B1/trezor_r_v3.py +++ b/core/site_scons/models/T2B1/trezor_r_v3.py @@ -62,14 +62,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32f4/usb/usbd_class_hid.c", - "embed/trezorhal/stm32f4/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32f4/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb_class_hid.c", + "embed/trezorhal/stm32f4/usb/usb_class_vcp.c", + "embed/trezorhal/stm32f4/usb/usb_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb.c", "embed/trezorhal/stm32f4/usb/usbd_conf.c", "embed/trezorhal/stm32f4/usb/usbd_core.c", "embed/trezorhal/stm32f4/usb/usbd_ctlreq.c", "embed/trezorhal/stm32f4/usb/usbd_ioreq.c", - "embed/trezorhal/stm32f4/usb/usbd.c", "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/T2B1/trezor_r_v4.py b/core/site_scons/models/T2B1/trezor_r_v4.py index 1d55473c35..641ebd8ce7 100644 --- a/core/site_scons/models/T2B1/trezor_r_v4.py +++ b/core/site_scons/models/T2B1/trezor_r_v4.py @@ -58,14 +58,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32f4/usb/usbd_class_hid.c", - "embed/trezorhal/stm32f4/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32f4/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb_class_hid.c", + "embed/trezorhal/stm32f4/usb/usb_class_vcp.c", + "embed/trezorhal/stm32f4/usb/usb_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb.c", "embed/trezorhal/stm32f4/usb/usbd_conf.c", "embed/trezorhal/stm32f4/usb/usbd_core.c", "embed/trezorhal/stm32f4/usb/usbd_ctlreq.c", "embed/trezorhal/stm32f4/usb/usbd_ioreq.c", - "embed/trezorhal/stm32f4/usb/usbd.c", "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/T2B1/trezor_r_v6.py b/core/site_scons/models/T2B1/trezor_r_v6.py index ecac28d081..2f562f5dfd 100644 --- a/core/site_scons/models/T2B1/trezor_r_v6.py +++ b/core/site_scons/models/T2B1/trezor_r_v6.py @@ -58,14 +58,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32f4/usb/usbd_class_hid.c", - "embed/trezorhal/stm32f4/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32f4/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb_class_hid.c", + "embed/trezorhal/stm32f4/usb/usb_class_vcp.c", + "embed/trezorhal/stm32f4/usb/usb_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb.c", "embed/trezorhal/stm32f4/usb/usbd_conf.c", "embed/trezorhal/stm32f4/usb/usbd_core.c", "embed/trezorhal/stm32f4/usb/usbd_ctlreq.c", "embed/trezorhal/stm32f4/usb/usbd_ioreq.c", - "embed/trezorhal/stm32f4/usb/usbd.c", "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/T2T1/trezor_t.py b/core/site_scons/models/T2T1/trezor_t.py index 6ad7905850..71b12d6216 100644 --- a/core/site_scons/models/T2T1/trezor_t.py +++ b/core/site_scons/models/T2T1/trezor_t.py @@ -100,14 +100,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32f4/usb/usbd_class_hid.c", - "embed/trezorhal/stm32f4/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32f4/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb_class_hid.c", + "embed/trezorhal/stm32f4/usb/usb_class_vcp.c", + "embed/trezorhal/stm32f4/usb/usb_class_webusb.c", + "embed/trezorhal/stm32f4/usb/usb.c", "embed/trezorhal/stm32f4/usb/usbd_conf.c", "embed/trezorhal/stm32f4/usb/usbd_core.c", "embed/trezorhal/stm32f4/usb/usbd_ctlreq.c", "embed/trezorhal/stm32f4/usb/usbd_ioreq.c", - "embed/trezorhal/stm32f4/usb/usbd.c", "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/T3T1/trezor_t3t1_revE.py b/core/site_scons/models/T3T1/trezor_t3t1_revE.py index 61d13baebc..9d1cea76e7 100644 --- a/core/site_scons/models/T3T1/trezor_t3t1_revE.py +++ b/core/site_scons/models/T3T1/trezor_t3t1_revE.py @@ -100,14 +100,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32u5/usb/usbd_class_hid.c", - "embed/trezorhal/stm32u5/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32u5/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32u5/usb/usb_class_hid.c", + "embed/trezorhal/stm32u5/usb/usb_class_vcp.c", + "embed/trezorhal/stm32u5/usb/usb_class_webusb.c", + "embed/trezorhal/stm32u5/usb/usb.c", "embed/trezorhal/stm32u5/usb/usbd_conf.c", "embed/trezorhal/stm32u5/usb/usbd_core.c", "embed/trezorhal/stm32u5/usb/usbd_ctlreq.c", "embed/trezorhal/stm32u5/usb/usbd_ioreq.c", - "embed/trezorhal/stm32u5/usb/usbd.c", "vendor/stm32u5xx_hal_driver/Src/stm32u5xx_ll_usb.c", ] features_available.append("usb") diff --git a/core/site_scons/models/T3T1/trezor_t3t1_v4.py b/core/site_scons/models/T3T1/trezor_t3t1_v4.py index a9951b895e..f6ffda61df 100644 --- a/core/site_scons/models/T3T1/trezor_t3t1_v4.py +++ b/core/site_scons/models/T3T1/trezor_t3t1_v4.py @@ -102,14 +102,14 @@ def configure( if "usb" in features_wanted: sources += [ - "embed/trezorhal/stm32u5/usb/usbd_class_hid.c", - "embed/trezorhal/stm32u5/usb/usbd_class_vcp.c", - "embed/trezorhal/stm32u5/usb/usbd_class_webusb.c", + "embed/trezorhal/stm32u5/usb/usb_class_hid.c", + "embed/trezorhal/stm32u5/usb/usb_class_vcp.c", + "embed/trezorhal/stm32u5/usb/usb_class_webusb.c", + "embed/trezorhal/stm32u5/usb/usb.c", "embed/trezorhal/stm32u5/usb/usbd_conf.c", "embed/trezorhal/stm32u5/usb/usbd_core.c", "embed/trezorhal/stm32u5/usb/usbd_ctlreq.c", "embed/trezorhal/stm32u5/usb/usbd_ioreq.c", - "embed/trezorhal/stm32u5/usb/usbd.c", "vendor/stm32u5xx_hal_driver/Src/stm32u5xx_ll_usb.c", ] features_available.append("usb")