28
28
29
29
// This file contains source copied from ST's HAL, and thus should have their copyright statement.
30
30
31
- // PMA_LENGTH is PMA buffer size in bytes.
31
+ // FSDEV_PMA_SIZE is PMA buffer size in bytes.
32
32
// On 512-byte devices, access with a stride of two words (use every other 16-bit address)
33
33
// On 1024-byte devices, access with a stride of one word (use every 16-bit address)
34
34
37
37
38
38
#if CFG_TUSB_MCU == OPT_MCU_STM32F0
39
39
#include "stm32f0xx.h"
40
- #define PMA_LENGTH (1024u)
40
+ #define FSDEV_PMA_SIZE (1024u)
41
41
// F0x2 models are crystal-less
42
42
// All have internal D+ pull-up
43
43
// 070RB: 2 x 16 bits/word memory LPM Support, BCD Support
44
44
// PMA dedicated to USB (no sharing with CAN)
45
45
46
46
#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
47
47
#include "stm32f1xx.h"
48
- #define PMA_LENGTH (512u)
48
+ #define FSDEV_PMA_SIZE (512u)
49
49
// NO internal Pull-ups
50
50
// *B, and *C: 2 x 16 bits/word
51
51
56
56
defined(STM32F303xB ) || defined(STM32F303xC ) || \
57
57
defined(STM32F373xC )
58
58
#include "stm32f3xx.h"
59
- #define PMA_LENGTH (512u)
59
+ #define FSDEV_PMA_SIZE (512u)
60
60
// NO internal Pull-ups
61
61
// *B, and *C: 1 x 16 bits/word
62
62
// PMA dedicated to USB (no sharing with CAN)
65
65
defined(STM32F302xD ) || defined(STM32F302xE ) || \
66
66
defined(STM32F303xD ) || defined(STM32F303xE )
67
67
#include "stm32f3xx.h"
68
- #define PMA_LENGTH (1024u)
68
+ #define FSDEV_PMA_SIZE (1024u)
69
69
// NO internal Pull-ups
70
70
// *6, *8, *D, and *E: 2 x 16 bits/word LPM Support
71
71
// When CAN clock is enabled, USB can use first 768 bytes ONLY.
72
72
73
73
#elif CFG_TUSB_MCU == OPT_MCU_STM32L0
74
74
#include "stm32l0xx.h"
75
- #define PMA_LENGTH (1024u)
75
+ #define FSDEV_PMA_SIZE (1024u)
76
76
77
77
#elif CFG_TUSB_MCU == OPT_MCU_STM32L1
78
78
#include "stm32l1xx.h"
79
- #define PMA_LENGTH (512u)
79
+ #define FSDEV_PMA_SIZE (512u)
80
80
81
81
#elif CFG_TUSB_MCU == OPT_MCU_STM32G4
82
82
#include "stm32g4xx.h"
83
- #define PMA_LENGTH (1024u)
83
+ #define FSDEV_PMA_SIZE (1024u)
84
84
85
85
#elif CFG_TUSB_MCU == OPT_MCU_STM32G0
86
86
#include "stm32g0xx.h"
87
- #define PMA_32BIT_ACCESS
88
- #define PMA_LENGTH (2048u)
87
+ #define FSDEV_BUS_32BIT
88
+ #define FSDEV_PMA_SIZE (2048u)
89
89
#undef USB_PMAADDR
90
90
#define USB_PMAADDR USB_DRD_PMAADDR
91
91
#define USB_TypeDef USB_DRD_TypeDef
112
112
113
113
#elif CFG_TUSB_MCU == OPT_MCU_STM32H5
114
114
#include "stm32h5xx.h"
115
- #define PMA_32BIT_ACCESS
116
- #define PMA_LENGTH (2048u)
115
+ #define FSDEV_BUS_32BIT
116
+ #define FSDEV_PMA_SIZE (2048u)
117
117
#undef USB_PMAADDR
118
118
#define USB_PMAADDR USB_DRD_PMAADDR
119
119
#define USB_TypeDef USB_DRD_TypeDef
141
141
142
142
#elif CFG_TUSB_MCU == OPT_MCU_STM32WB
143
143
#include "stm32wbxx.h"
144
- #define PMA_LENGTH (1024u)
144
+ #define FSDEV_PMA_SIZE (1024u)
145
145
/* ST provided header has incorrect value */
146
146
#undef USB_PMAADDR
147
147
#define USB_PMAADDR USB1_PMAADDR
148
148
149
149
#elif CFG_TUSB_MCU == OPT_MCU_STM32L4
150
150
#include "stm32l4xx.h"
151
- #define PMA_LENGTH (1024u)
151
+ #define FSDEV_PMA_SIZE (1024u)
152
152
153
153
#elif CFG_TUSB_MCU == OPT_MCU_STM32L5
154
154
#include "stm32l5xx.h"
155
- #define PMA_LENGTH (1024u)
155
+ #define FSDEV_PMA_SIZE (1024u)
156
156
157
157
#ifndef USB_PMAADDR
158
158
#define USB_PMAADDR (USB_BASE + (USB_PMAADDR_NS - USB_BASE_NS))
164
164
#endif
165
165
166
166
// For purposes of accessing the packet
167
- #if ((PMA_LENGTH ) == 512u )
168
- #define PMA_STRIDE (2u)
169
- #elif ((PMA_LENGTH ) == 1024u )
170
- #define PMA_STRIDE (1u)
167
+ #if ((FSDEV_PMA_SIZE ) == 512u )
168
+ #define FSDEV_PMA_STRIDE (2u)
169
+ #elif ((FSDEV_PMA_SIZE ) == 1024u )
170
+ #define FSDEV_PMA_STRIDE (1u)
171
171
#endif
172
172
173
+ // The fsdev_bus_t type can be used for both register and PMA access necessities
173
174
// For type-safety create a new macro for the volatile address of PMAADDR
174
175
// The compiler should warn us if we cast it to a non-volatile type?
175
- #ifdef PMA_32BIT_ACCESS
176
+ #ifdef FSDEV_BUS_32BIT
176
177
typedef uint32_t fsdev_bus_t ;
177
178
static __IO uint32_t * const pma32 = (__IO uint32_t * )USB_PMAADDR ;
178
179
@@ -184,7 +185,7 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
184
185
TU_ATTR_ALWAYS_INLINE static inline __IO uint16_t * pcd_btable_word_ptr (USB_TypeDef * USBx , size_t x )
185
186
{
186
187
size_t total_word_offset = (((USBx )-> BTABLE )>>1 ) + x ;
187
- total_word_offset *= PMA_STRIDE ;
188
+ total_word_offset *= FSDEV_PMA_STRIDE ;
188
189
return & (pma [total_word_offset ]);
189
190
}
190
191
@@ -215,7 +216,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t pcd_aligned_buffer_size(uint16_t si
215
216
/* SetENDPOINT */
216
217
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_endpoint (USB_TypeDef * USBx , uint32_t bEpIdx , uint32_t wRegValue )
217
218
{
218
- #ifdef PMA_32BIT_ACCESS
219
+ #ifdef FSDEV_BUS_32BIT
219
220
(void ) USBx ;
220
221
__O uint32_t * reg = (__O uint32_t * )(USB_DRD_BASE + bEpIdx * 4 );
221
222
* reg = wRegValue ;
@@ -227,7 +228,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_endpoint(USB_TypeDef * USBx, ui
227
228
228
229
/* GetENDPOINT */
229
230
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_endpoint (USB_TypeDef * USBx , uint32_t bEpIdx ) {
230
- #ifdef PMA_32BIT_ACCESS
231
+ #ifdef FSDEV_BUS_32BIT
231
232
(void ) USBx ;
232
233
__I uint32_t * reg = (__I uint32_t * )(USB_DRD_BASE + bEpIdx * 4 );
233
234
#else
@@ -282,7 +283,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_clear_tx_ep_ctr(USB_TypeDef * USBx,
282
283
*/
283
284
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_cnt (USB_TypeDef * USBx , uint32_t bEpIdx )
284
285
{
285
- #ifdef PMA_32BIT_ACCESS
286
+ #ifdef FSDEV_BUS_32BIT
286
287
(void ) USBx ;
287
288
return (pma32 [2 * bEpIdx ] & 0x03FF0000 ) >> 16 ;
288
289
#else
@@ -293,7 +294,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_cnt(USB_TypeDef * USB
293
294
294
295
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_cnt (USB_TypeDef * USBx , uint32_t bEpIdx )
295
296
{
296
- #ifdef PMA_32BIT_ACCESS
297
+ #ifdef FSDEV_BUS_32BIT
297
298
(void ) USBx ;
298
299
return (pma32 [2 * bEpIdx + 1 ] & 0x03FF0000 ) >> 16 ;
299
300
#else
@@ -320,7 +321,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_address(USB_TypeDef * USBx,
320
321
321
322
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_address (USB_TypeDef * USBx , uint32_t bEpIdx )
322
323
{
323
- #ifdef PMA_32BIT_ACCESS
324
+ #ifdef FSDEV_BUS_32BIT
324
325
(void ) USBx ;
325
326
return pma32 [2 * bEpIdx ] & 0x0000FFFFu ;
326
327
#else
@@ -330,7 +331,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_address(USB_TypeDef *
330
331
331
332
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_address (USB_TypeDef * USBx , uint32_t bEpIdx )
332
333
{
333
- #ifdef PMA_32BIT_ACCESS
334
+ #ifdef FSDEV_BUS_32BIT
334
335
(void ) USBx ;
335
336
return pma32 [2 * bEpIdx + 1 ] & 0x0000FFFFu ;
336
337
#else
@@ -340,7 +341,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_address(USB_TypeDef *
340
341
341
342
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_address (USB_TypeDef * USBx , uint32_t bEpIdx , uint32_t addr )
342
343
{
343
- #ifdef PMA_32BIT_ACCESS
344
+ #ifdef FSDEV_BUS_32BIT
344
345
(void ) USBx ;
345
346
pma32 [2 * bEpIdx ] = (pma32 [2 * bEpIdx ] & 0xFFFF0000u ) | (addr & 0x0000FFFCu );
346
347
#else
@@ -350,7 +351,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_address(USB_TypeDef * USB
350
351
351
352
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_address (USB_TypeDef * USBx , uint32_t bEpIdx , uint32_t addr )
352
353
{
353
- #ifdef PMA_32BIT_ACCESS
354
+ #ifdef FSDEV_BUS_32BIT
354
355
(void ) USBx ;
355
356
pma32 [2 * bEpIdx + 1 ] = (pma32 [2 * bEpIdx + 1 ] & 0xFFFF0000u ) | (addr & 0x0000FFFCu );
356
357
#else
@@ -360,7 +361,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_address(USB_TypeDef * USB
360
361
361
362
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_cnt (USB_TypeDef * USBx , uint32_t bEpIdx , uint32_t wCount )
362
363
{
363
- #ifdef PMA_32BIT_ACCESS
364
+ #ifdef FSDEV_BUS_32BIT
364
365
(void ) USBx ;
365
366
pma32 [2 * bEpIdx ] = (pma32 [2 * bEpIdx ] & ~0x03FF0000u ) | ((wCount & 0x3FFu ) << 16 );
366
367
#else
@@ -371,7 +372,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_cnt(USB_TypeDef * USBx, u
371
372
372
373
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_cnt (USB_TypeDef * USBx , uint32_t bEpIdx , uint32_t wCount )
373
374
{
374
- #ifdef PMA_32BIT_ACCESS
375
+ #ifdef FSDEV_BUS_32BIT
375
376
(void ) USBx ;
376
377
pma32 [2 * bEpIdx + 1 ] = (pma32 [2 * bEpIdx + 1 ] & ~0x03FF0000u ) | ((wCount & 0x3FFu ) << 16 );
377
378
#else
@@ -383,7 +384,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx, u
383
384
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_blsize_num_blocks (USB_TypeDef * USBx , uint32_t rxtx_idx , uint32_t blocksize , uint32_t numblocks )
384
385
{
385
386
/* Encode into register. When BLSIZE==1, we need to subtract 1 block count */
386
- #ifdef PMA_32BIT_ACCESS
387
+ #ifdef FSDEV_BUS_32BIT
387
388
(void ) USBx ;
388
389
pma32 [rxtx_idx ] = (pma32 [rxtx_idx ] & 0x0000FFFFu ) | (blocksize << 31 ) | ((numblocks - blocksize ) << 26 );
389
390
#else
0 commit comments