|
138 | 138 | #error "FSDEV_HAS_SBUF_ISO not defined" |
139 | 139 | #endif |
140 | 140 |
|
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 | | - |
161 | 141 | #ifndef CFG_TUD_FSDEV_DOUBLE_BUFFERED_ISO_EP |
162 | 142 | // Default configuration for double-buffered isochronous endpoints: |
163 | 143 | // - 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) { |
271 | 251 | // CMSIS has a membar after disabling interrupts |
272 | 252 | } |
273 | 253 |
|
| 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 | + |
274 | 293 | //--------------------------------------------------------------------+ |
275 | 294 | // Connect / Disconnect |
276 | 295 | //--------------------------------------------------------------------+ |
|
0 commit comments