2222 * THE SOFTWARE.
2323 */
2424
25- #include " tusb_option.h"
25+ #include " tusb_option.h"
2626
27- #if (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32)) && CFG_TUD_ENABLED
27+ #if (defined(ARDUINO_ARCH_STM32) || \
28+ defined (ARDUINO_ARCH_ARDUINO_CORE_STM32)) && \
29+ CFG_TUD_ENABLED
2830
2931#define USE_HAL_DRIVER
30- #include " stm32f4xx_hal.h"
31- #include " stm32f4xx_hal_rcc.h"
3232#include " Arduino.h"
3333#include " arduino/Adafruit_TinyUSB_API.h"
34+ #include " stm32f4xx_hal.h"
35+ #include " stm32f4xx_hal_rcc.h"
3436#include " tusb.h"
3537
3638// --------------------------------------------------------------------+
3739// Forward USB interrupt events to TinyUSB IRQ Handler
3840// --------------------------------------------------------------------+
3941extern " C" {
4042
41- void OTG_FS_IRQHandler (void )
42- {
43- tud_int_handler (0 );
44- }
43+ void OTG_FS_IRQHandler (void ) { tud_int_handler (0 ); }
4544
46- void yield (void )
47- {
48- tud_task ();
49- if (tud_cdc_connected ()) {
50- tud_cdc_write_flush ();
51- }
45+ void yield (void ) {
46+ tud_task ();
47+ if (tud_cdc_connected ()) {
48+ tud_cdc_write_flush ();
49+ }
5250}
5351
5452} // extern "C"
5553
5654// --------------------------------------------------------------------+
5755// Porting API
5856// --------------------------------------------------------------------+
59- void TinyUSB_Port_InitDevice (uint8_t rhport)
60- {
61- (void ) rhport;
62-
63- // Enable clocks FIRST
64- __HAL_RCC_GPIOA_CLK_ENABLE ();
65- __HAL_RCC_USB_OTG_FS_CLK_ENABLE ();
66-
67- // Configure USB pins (PA11 = DM, PA12 = DP)
68- GPIO_InitTypeDef GPIO_InitStruct = {};
69- GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
70- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
71- GPIO_InitStruct.Pull = GPIO_NOPULL;
72- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
73- GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
74- HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
75-
76- // Enable USB IRQ
77- NVIC_SetPriority (OTG_FS_IRQn, 0 );
78- NVIC_EnableIRQ (OTG_FS_IRQn);
79-
80- // Disable VBUS sensing (we're bus-powered, don't need it)
81- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
82- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
83- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
84-
85- // Initialize TinyUSB device stack
86- tud_init (rhport);
87-
57+ void TinyUSB_Port_InitDevice (uint8_t rhport) {
58+ (void )rhport;
59+
60+ // Enable clocks FIRST
61+ __HAL_RCC_GPIOA_CLK_ENABLE ();
62+ __HAL_RCC_USB_OTG_FS_CLK_ENABLE ();
63+
64+ // Configure USB pins (PA11 = DM, PA12 = DP)
65+ GPIO_InitTypeDef GPIO_InitStruct = {};
66+ GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
67+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
68+ GPIO_InitStruct.Pull = GPIO_NOPULL;
69+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
70+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
71+ HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
72+
73+ // Enable USB IRQ
74+ NVIC_SetPriority (OTG_FS_IRQn, 0 );
75+ NVIC_EnableIRQ (OTG_FS_IRQn);
76+
77+ // Disable VBUS sensing (we're bus-powered, don't need it)
78+ USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
79+ USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
80+ USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
81+
82+ // Initialize TinyUSB device stack
83+ tud_init (rhport);
8884}
8985
90- void TinyUSB_Port_EnterDFU (void ) {
91- // Optional - implement bootloader entry if needed
86+ void TinyUSB_Port_EnterDFU (void ) {
87+ // Optional - implement bootloader entry if needed
9288}
9389
94- uint8_t TinyUSB_Port_GetSerialNumber (uint8_t serial_id[16 ])
95- {
96- volatile uint32_t *uid = (volatile uint32_t *)0x1FFF7A10 ; // STM32F411 UID base
97- uint32_t *serial_32 = (uint32_t *)serial_id;
98- serial_32[0 ] = uid[0 ];
99- serial_32[1 ] = uid[1 ];
100- serial_32[2 ] = uid[2 ];
101- return 12 ;
90+ uint8_t TinyUSB_Port_GetSerialNumber (uint8_t serial_id[16 ]) {
91+ volatile uint32_t *uid =
92+ (volatile uint32_t *)0x1FFF7A10 ; // STM32F411 UID base
93+ uint32_t *serial_32 = (uint32_t *)serial_id;
94+ serial_32[0 ] = uid[0 ];
95+ serial_32[1 ] = uid[1 ];
96+ serial_32[2 ] = uid[2 ];
97+ return 12 ;
10298}
10399
104100#endif // ARDUINO_ARCH_STM32
0 commit comments