Skip to content

Commit 27d91e5

Browse files
committed
debloat the workaround
Signed-off-by: HiFiPhile <admin@hifiphile.com>
1 parent 37ace45 commit 27d91e5

4 files changed

Lines changed: 41 additions & 63 deletions

File tree

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ void dcd_int_handler(uint8_t rhport) {
393393
const uint32_t ep_reg = ep_read(ep_id);
394394

395395
if (ep_reg & U_EP_CTR_RX) {
396-
#ifdef CFG_TUSB_FSDEV_32BIT
396+
#if defined(TUP_USBIP_FSDEV_STM32) && defined(CFG_TUSB_FSDEV_32BIT)
397397
fsdev_btable_workaround_delay(false);
398398
#endif
399399

src/portable/st/stm32_fsdev/fsdev_common.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -307,24 +307,6 @@ typedef struct {
307307
#error "Unknown USB IP"
308308
#endif
309309

310-
#if defined(TUP_USBIP_FSDEV_STM32) && defined(CFG_TUSB_FSDEV_32BIT)
311-
#ifndef CFG_TUSB_FSDEV_BTABLE_FS_DELAY_COUNT
312-
#if defined(FSDEV_STM32_CPU_MHZ)
313-
#define CFG_TUSB_FSDEV_BTABLE_FS_DELAY_COUNT (FSDEV_STM32_CPU_MHZ / 4U)
314-
#else
315-
#error "Define CFG_TUSB_FSDEV_BTABLE_FS_DELAY_COUNT or FSDEV_STM32_CPU_MHZ for STM32 FSDEV 32-bit"
316-
#endif
317-
#endif
318-
319-
#ifndef CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT
320-
#if defined(FSDEV_STM32_CPU_MHZ)
321-
#define CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT (FSDEV_STM32_CPU_MHZ * 2U)
322-
#else
323-
#error "Define CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT or FSDEV_STM32_CPU_MHZ for STM32 FSDEV 32-bit"
324-
#endif
325-
#endif
326-
#endif
327-
328310
//--------------------------------------------------------------------+
329311
// Endpoint Helper
330312
// - CTR is write 0 to clear
@@ -467,25 +449,6 @@ uint16_t pma_align_buffer_size(uint16_t size, uint8_t *blsize, uint8_t *num_bloc
467449
// Set RX buffer size
468450
void btable_set_rx_bufsize(uint32_t ep_id, uint8_t buf_id, uint16_t wCount);
469451

470-
/* STM32 FSDEV PMA Buffer Description Table errata workaround:
471-
* - ES0561 (STM32H503), ES0587 (STM32U535/U545)
472-
* - CTR may trigger before final PMA SRAM accesses complete on OUT transfers.
473-
* - Insert delay before reading PMA count/data.
474-
*
475-
* Low-speed path uses CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT, otherwise full-speed count.
476-
*/
477-
TU_ATTR_ALWAYS_INLINE static inline void fsdev_btable_workaround_delay(bool low_speed) {
478-
#if defined(TUP_USBIP_FSDEV_STM32) && defined(CFG_TUSB_FSDEV_32BIT)
479-
uint32_t cycle_count = low_speed ? CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT : CFG_TUSB_FSDEV_BTABLE_FS_DELAY_COUNT;
480-
volatile uint32_t delay_count = cycle_count;
481-
while (delay_count > 0U) {
482-
delay_count--;
483-
}
484-
#else
485-
(void) low_speed;
486-
#endif
487-
}
488-
489452
#ifdef __cplusplus
490453
}
491454
#endif

src/portable/st/stm32_fsdev/fsdev_stm32.h

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,6 @@
138138
#error "FSDEV_HAS_SBUF_ISO not defined"
139139
#endif
140140

141-
#ifndef FSDEV_STM32_CPU_MHZ
142-
// Max CPU frequency in MHz, used to derive conservative FSDEV PMA delay defaults.
143-
#if CFG_TUSB_MCU == OPT_MCU_STM32H5
144-
#define FSDEV_STM32_CPU_MHZ 250U
145-
#elif CFG_TUSB_MCU == OPT_MCU_STM32U5
146-
#define FSDEV_STM32_CPU_MHZ 160U
147-
#elif CFG_TUSB_MCU == OPT_MCU_STM32U3
148-
#define FSDEV_STM32_CPU_MHZ 96U
149-
#elif CFG_TUSB_MCU == OPT_MCU_STM32U0
150-
#define FSDEV_STM32_CPU_MHZ 56U
151-
#elif CFG_TUSB_MCU == OPT_MCU_STM32G0
152-
#define FSDEV_STM32_CPU_MHZ 64U
153-
#elif CFG_TUSB_MCU == OPT_MCU_STM32C0
154-
#define FSDEV_STM32_CPU_MHZ 48U
155-
#elif defined(CFG_TUSB_FSDEV_32BIT) && \
156-
(!defined(CFG_TUSB_FSDEV_BTABLE_FS_DELAY_COUNT) || !defined(CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT))
157-
#error "Define FSDEV_STM32_CPU_MHZ or both CFG_TUSB_FSDEV_BTABLE_{FS,LS}_DELAY_COUNT for this STM32 MCU"
158-
#endif
159-
#endif
160-
161141
#ifndef CFG_TUD_FSDEV_DOUBLE_BUFFERED_ISO_EP
162142
// Default configuration for double-buffered isochronous endpoints:
163143
// - Enable double buffering on devices with >1KB Packet Memory Area (PMA)
@@ -271,6 +251,45 @@ TU_ATTR_ALWAYS_INLINE static inline void fsdev_int_disable(uint8_t rhport) {
271251
// CMSIS has a membar after disabling interrupts
272252
}
273253

254+
//--------------------------------------------------------------------+
255+
// STM32 FSDEV PMA Buffer Description Table errata workaround:
256+
//--------------------------------------------------------------------+
257+
258+
// ES0561 (STM32H503), ES0587 (STM32U535/U545)
259+
// CTR may trigger before final PMA SRAM accesses complete on OUT transfers.
260+
// Insert delay before reading PMA count/data.
261+
262+
// Max CPU frequency in MHz, used to derive conservative FSDEV PMA delay defaults.
263+
#if CFG_TUSB_MCU == OPT_MCU_STM32H5
264+
#define FSDEV_STM32_CPU_MHZ 250U
265+
#elif CFG_TUSB_MCU == OPT_MCU_STM32U5
266+
#define FSDEV_STM32_CPU_MHZ 160U
267+
#elif CFG_TUSB_MCU == OPT_MCU_STM32U3
268+
#define FSDEV_STM32_CPU_MHZ 96U
269+
#elif CFG_TUSB_MCU == OPT_MCU_STM32U0
270+
#define FSDEV_STM32_CPU_MHZ 56U
271+
#elif CFG_TUSB_MCU == OPT_MCU_STM32G0
272+
#define FSDEV_STM32_CPU_MHZ 64U
273+
#elif CFG_TUSB_MCU == OPT_MCU_STM32C0
274+
#define FSDEV_STM32_CPU_MHZ 48U
275+
#endif
276+
277+
#ifndef CFG_TUSB_FSDEV_BTABLE_FS_DELAY_COUNT
278+
#define CFG_TUSB_FSDEV_BTABLE_FS_DELAY_COUNT (FSDEV_STM32_CPU_MHZ / 4U)
279+
#endif
280+
281+
#ifndef CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT
282+
#define CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT (FSDEV_STM32_CPU_MHZ * 2U)
283+
#endif
284+
285+
TU_ATTR_ALWAYS_INLINE static inline void fsdev_btable_workaround_delay(bool low_speed) {
286+
uint32_t cycle_count = low_speed ? CFG_TUSB_FSDEV_BTABLE_LS_DELAY_COUNT : CFG_TUSB_FSDEV_BTABLE_FS_DELAY_COUNT;
287+
volatile uint32_t delay_count = cycle_count;
288+
while (delay_count > 0U) {
289+
delay_count--;
290+
}
291+
}
292+
274293
//--------------------------------------------------------------------+
275294
// Connect / Disconnect
276295
//--------------------------------------------------------------------+

src/portable/st/stm32_fsdev/hcd_stm32_fsdev.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,7 @@ bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
197197

198198
// If DCON_STAT is already set, the controller sometimes misses the initial connection interrupt
199199
if (FSDEV_REG->ISTR & U_ISTR_DCON_STAT) {
200-
// Wait DP/DM stabilize time
201-
volatile uint32_t cycle_count = FSDEV_STM32_CPU_MHZ / 4U;
202-
while (cycle_count > 0U) {
203-
cycle_count--;
204-
}
200+
tusb_time_delay_ms_api(2);
205201
port_status_handler(rhport, false);
206202
}
207203

0 commit comments

Comments
 (0)