Skip to content

Commit 3cd6d3b

Browse files
committed
stm32: Fix compilation issues for static USB mode.
- Fix incomplete if statements in machine_usb_device.c and mp_usbd_descriptor.c that were causing nested function errors - Add MICROPY_HW_STM_USB_STACK guards to pyb_usb_storage_medium usage in main.c for TinyUSB compatibility Signed-off-by: Andrew Leech <[email protected]>
1 parent a51aae5 commit 3cd6d3b

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

extmod/machine_usb_device.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ static mp_obj_t usb_device_make_new(const mp_obj_type_t *type, size_t n_args, si
8787
extern mp_usbd_class_state_t mp_usbd_class_state;
8888
uint8_t flags = 0;
8989
if (mp_usbd_class_state.cdc_enabled) {
90+
flags |= USB_BUILTIN_FLAG_CDC;
91+
}
92+
if (mp_usbd_class_state.msc_enabled) {
93+
flags |= USB_BUILTIN_FLAG_MSC;
94+
}
95+
#if MICROPY_HW_NETWORK_USBNET
96+
if (mp_usbd_class_state.ncm_enabled) {
97+
flags |= USB_BUILTIN_FLAG_NCM;
98+
}
99+
#endif
90100

91101
// Create appropriate builtin object based on current state
92102
if (flags == USB_BUILTIN_FLAG_NONE) {

ports/stm32/usb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ typedef struct _usb_device_t {
9090
} usb_device_t;
9191

9292
usb_device_t usb_device = {0};
93+
#if MICROPY_HW_USB_MSC
9394
pyb_usb_storage_medium_t pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_NONE;
95+
#endif
9496

9597
#if !MICROPY_HW_USB_IS_MULTI_OTG
9698

ports/stm32/usb.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ typedef enum {
4343
USB_PHY_HS_ID = 1,
4444
} USB_PHY_ID;
4545

46+
// Storage medium variable used by both USB stacks when MSC is enabled
47+
#if MICROPY_HW_USB_MSC
48+
extern pyb_usb_storage_medium_t pyb_usb_storage_medium;
49+
#endif
50+
4651
#if MICROPY_HW_STM_USB_STACK
4752

4853
typedef struct _pyb_usb_vcp_obj_t pyb_usb_vcp_obj_t;
4954

5055
extern mp_uint_t pyb_usb_flags;
51-
extern pyb_usb_storage_medium_t pyb_usb_storage_medium;
5256
extern const struct _mp_rom_obj_tuple_t pyb_usb_hid_mouse_obj;
5357
extern const struct _mp_rom_obj_tuple_t pyb_usb_hid_keyboard_obj;
5458
extern const mp_obj_type_t pyb_usb_vcp_type;

shared/tinyusb/mp_usbd_descriptor.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ static uint8_t mp_usbd_dynamic_desc_cfg[MP_USBD_BUILTIN_DESC_CFG_LEN];
233233
static uint8_t mp_usbd_class_state_to_flags(void) {
234234
uint8_t flags = USB_BUILTIN_FLAG_NONE;
235235
if (mp_usbd_class_state.cdc_enabled) {
236+
flags |= USB_BUILTIN_FLAG_CDC;
237+
}
238+
if (mp_usbd_class_state.msc_enabled) {
239+
flags |= USB_BUILTIN_FLAG_MSC;
240+
}
241+
if (mp_usbd_class_state.ncm_enabled) {
242+
flags |= USB_BUILTIN_FLAG_NCM;
243+
}
236244
return flags;
237245
}
238246

0 commit comments

Comments
 (0)