Skip to content

Commit 2d3d148

Browse files
committed
[STM32 FSDEV] Align names for consistency
1 parent 5458213 commit 2d3d148

File tree

2 files changed

+48
-47
lines changed

2 files changed

+48
-47
lines changed

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@
128128
# define DCD_STM32_BTABLE_BASE 0U
129129
#endif
130130

131-
#ifndef DCD_STM32_BTABLE_LENGTH
132-
# define DCD_STM32_BTABLE_LENGTH (PMA_LENGTH - DCD_STM32_BTABLE_BASE)
131+
#ifndef DCD_STM32_BTABLE_SIZE
132+
# define DCD_STM32_BTABLE_SIZE (FSDEV_PMA_SIZE - DCD_STM32_BTABLE_BASE)
133133
#endif
134134

135135
/***************************************************
136136
* Checks, structs, defines, function definitions, etc.
137137
*/
138138

139139
TU_VERIFY_STATIC((MAX_EP_COUNT) <= STFSDEV_EP_COUNT, "Only 8 endpoints supported on the hardware");
140-
TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) + (DCD_STM32_BTABLE_LENGTH))<=(PMA_LENGTH), "BTABLE does not fit in PMA RAM");
140+
TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) + (DCD_STM32_BTABLE_SIZE)) <= (FSDEV_PMA_SIZE), "BTABLE does not fit in PMA RAM");
141141
TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) % 8) == 0, "BTABLE base must be aligned to 8 bytes");
142142

143143
//--------------------------------------------------------------------+
@@ -559,7 +559,7 @@ static void dcd_ep_ctr_rx_handler(uint32_t wIstr)
559559
// Must reset EP to NAK (in case it had been stalling) (though, maybe too late here)
560560
pcd_set_ep_rx_status(USB,0u,USB_EP_RX_NAK);
561561
pcd_set_ep_tx_status(USB,0u,USB_EP_TX_NAK);
562-
#ifdef PMA_32BIT_ACCESS
562+
#ifdef FSDEV_BUS_32BIT
563563
dcd_event_setup_received(0, (uint8_t*)(USB_PMAADDR + pcd_get_ep_rx_address(USB, EPindex)), true);
564564
#else
565565
// The setup_received function uses memcpy, so this must first copy the setup data into
@@ -786,7 +786,7 @@ static uint16_t dcd_pma_alloc(uint8_t ep_addr, uint16_t length)
786786
}
787787

788788
// Ensure allocated buffer is aligned
789-
#ifdef PMA_32BIT_ACCESS
789+
#ifdef FSDEV_BUS_32BIT
790790
length = (length + 3) & ~0x03;
791791
#else
792792
length = (length + 1) & ~0x01;
@@ -798,7 +798,7 @@ static uint16_t dcd_pma_alloc(uint8_t ep_addr, uint16_t length)
798798
ep_buf_ptr = (uint16_t)(ep_buf_ptr + length); // increment buffer pointer
799799

800800
// Verify no overflow
801-
TU_ASSERT(ep_buf_ptr <= PMA_LENGTH, 0xFFFF);
801+
TU_ASSERT(ep_buf_ptr <= FSDEV_PMA_SIZE, 0xFFFF);
802802

803803
epXferCtl->pma_ptr = addr;
804804
epXferCtl->pma_alloc_size = length;
@@ -1227,7 +1227,7 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
12271227
}
12281228
}
12291229

1230-
#ifdef PMA_32BIT_ACCESS
1230+
#ifdef FSDEV_BUS_32BIT
12311231
static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, uint16_t wNBytes)
12321232
{
12331233
const uint8_t* srcVal = src;
@@ -1283,15 +1283,15 @@ static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, ui
12831283
__IO uint16_t *pdwVal;
12841284

12851285
srcVal = src;
1286-
pdwVal = &pma[PMA_STRIDE*(dst>>1)];
1286+
pdwVal = &pma[FSDEV_PMA_STRIDE * (dst >> 1)];
12871287

12881288
while (n--)
12891289
{
12901290
temp1 = (uint16_t)*srcVal;
12911291
srcVal++;
12921292
temp2 = temp1 | ((uint16_t)(((uint16_t)(*srcVal)) << 8U)) ;
12931293
*pdwVal = temp2;
1294-
pdwVal += PMA_STRIDE;
1294+
pdwVal += FSDEV_PMA_STRIDE;
12951295
srcVal++;
12961296
}
12971297

@@ -1323,7 +1323,7 @@ static bool dcd_write_packet_memory_ff(tu_fifo_t * ff, uint16_t dst, uint16_t wN
13231323
// We want to read from the FIFO and write it into the PMA, if LIN part is ODD and has WRAPPED part,
13241324
// last lin byte will be combined with wrapped part
13251325
// To ensure PMA is always access aligned (dst aligned to 16 or 32 bit)
1326-
#ifdef PMA_32BIT_ACCESS
1326+
#ifdef FSDEV_BUS_32BIT
13271327
if((cnt_lin & 0x03) && cnt_wrap)
13281328
{
13291329
// Copy first linear part
@@ -1386,7 +1386,7 @@ static bool dcd_write_packet_memory_ff(tu_fifo_t * ff, uint16_t dst, uint16_t wN
13861386
return true;
13871387
}
13881388

1389-
#ifdef PMA_32BIT_ACCESS
1389+
#ifdef FSDEV_BUS_32BIT
13901390
static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, uint16_t wNBytes)
13911391
{
13921392
uint8_t* dstVal = dst;
@@ -1434,21 +1434,21 @@ static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, uint16_t
14341434
__IO const uint16_t *pdwVal;
14351435
uint32_t temp;
14361436

1437-
pdwVal = &pma[PMA_STRIDE*(src>>1)];
1437+
pdwVal = &pma[FSDEV_PMA_STRIDE * (src >> 1)];
14381438
uint8_t *dstVal = (uint8_t*)dst;
14391439

14401440
while (n--)
14411441
{
14421442
temp = *pdwVal;
1443-
pdwVal += PMA_STRIDE;
1443+
pdwVal += FSDEV_PMA_STRIDE;
14441444
*dstVal++ = ((temp >> 0) & 0xFF);
14451445
*dstVal++ = ((temp >> 8) & 0xFF);
14461446
}
14471447

14481448
if (wNBytes & 0x01)
14491449
{
14501450
temp = *pdwVal;
1451-
pdwVal += PMA_STRIDE;
1451+
pdwVal += FSDEV_PMA_STRIDE;
14521452
*dstVal++ = ((temp >> 0) & 0xFF);
14531453
}
14541454
return true;
@@ -1475,7 +1475,7 @@ static bool dcd_read_packet_memory_ff(tu_fifo_t * ff, uint16_t src, uint16_t wNB
14751475
// We want to read from PMA and write it into the FIFO, if LIN part is ODD and has WRAPPED part,
14761476
// last lin byte will be combined with wrapped part
14771477
// To ensure PMA is always access aligned (src aligned to 16 or 32 bit)
1478-
#ifdef PMA_32BIT_ACCESS
1478+
#ifdef FSDEV_BUS_32BIT
14791479
if((cnt_lin & 0x03) && cnt_wrap)
14801480
{
14811481
// Copy first linear part

src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
// This file contains source copied from ST's HAL, and thus should have their copyright statement.
3030

31-
// PMA_LENGTH is PMA buffer size in bytes.
31+
// FSDEV_PMA_SIZE is PMA buffer size in bytes.
3232
// On 512-byte devices, access with a stride of two words (use every other 16-bit address)
3333
// On 1024-byte devices, access with a stride of one word (use every 16-bit address)
3434

@@ -37,15 +37,15 @@
3737

3838
#if CFG_TUSB_MCU == OPT_MCU_STM32F0
3939
#include "stm32f0xx.h"
40-
#define PMA_LENGTH (1024u)
40+
#define FSDEV_PMA_SIZE (1024u)
4141
// F0x2 models are crystal-less
4242
// All have internal D+ pull-up
4343
// 070RB: 2 x 16 bits/word memory LPM Support, BCD Support
4444
// PMA dedicated to USB (no sharing with CAN)
4545

4646
#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
4747
#include "stm32f1xx.h"
48-
#define PMA_LENGTH (512u)
48+
#define FSDEV_PMA_SIZE (512u)
4949
// NO internal Pull-ups
5050
// *B, and *C: 2 x 16 bits/word
5151

@@ -56,7 +56,7 @@
5656
defined(STM32F303xB) || defined(STM32F303xC) || \
5757
defined(STM32F373xC)
5858
#include "stm32f3xx.h"
59-
#define PMA_LENGTH (512u)
59+
#define FSDEV_PMA_SIZE (512u)
6060
// NO internal Pull-ups
6161
// *B, and *C: 1 x 16 bits/word
6262
// PMA dedicated to USB (no sharing with CAN)
@@ -65,27 +65,27 @@
6565
defined(STM32F302xD) || defined(STM32F302xE) || \
6666
defined(STM32F303xD) || defined(STM32F303xE)
6767
#include "stm32f3xx.h"
68-
#define PMA_LENGTH (1024u)
68+
#define FSDEV_PMA_SIZE (1024u)
6969
// NO internal Pull-ups
7070
// *6, *8, *D, and *E: 2 x 16 bits/word LPM Support
7171
// When CAN clock is enabled, USB can use first 768 bytes ONLY.
7272

7373
#elif CFG_TUSB_MCU == OPT_MCU_STM32L0
7474
#include "stm32l0xx.h"
75-
#define PMA_LENGTH (1024u)
75+
#define FSDEV_PMA_SIZE (1024u)
7676

7777
#elif CFG_TUSB_MCU == OPT_MCU_STM32L1
7878
#include "stm32l1xx.h"
79-
#define PMA_LENGTH (512u)
79+
#define FSDEV_PMA_SIZE (512u)
8080

8181
#elif CFG_TUSB_MCU == OPT_MCU_STM32G4
8282
#include "stm32g4xx.h"
83-
#define PMA_LENGTH (1024u)
83+
#define FSDEV_PMA_SIZE (1024u)
8484

8585
#elif CFG_TUSB_MCU == OPT_MCU_STM32G0
8686
#include "stm32g0xx.h"
87-
#define PMA_32BIT_ACCESS
88-
#define PMA_LENGTH (2048u)
87+
#define FSDEV_BUS_32BIT
88+
#define FSDEV_PMA_SIZE (2048u)
8989
#undef USB_PMAADDR
9090
#define USB_PMAADDR USB_DRD_PMAADDR
9191
#define USB_TypeDef USB_DRD_TypeDef
@@ -112,8 +112,8 @@
112112

113113
#elif CFG_TUSB_MCU == OPT_MCU_STM32H5
114114
#include "stm32h5xx.h"
115-
#define PMA_32BIT_ACCESS
116-
#define PMA_LENGTH (2048u)
115+
#define FSDEV_BUS_32BIT
116+
#define FSDEV_PMA_SIZE (2048u)
117117
#undef USB_PMAADDR
118118
#define USB_PMAADDR USB_DRD_PMAADDR
119119
#define USB_TypeDef USB_DRD_TypeDef
@@ -141,18 +141,18 @@
141141

142142
#elif CFG_TUSB_MCU == OPT_MCU_STM32WB
143143
#include "stm32wbxx.h"
144-
#define PMA_LENGTH (1024u)
144+
#define FSDEV_PMA_SIZE (1024u)
145145
/* ST provided header has incorrect value */
146146
#undef USB_PMAADDR
147147
#define USB_PMAADDR USB1_PMAADDR
148148

149149
#elif CFG_TUSB_MCU == OPT_MCU_STM32L4
150150
#include "stm32l4xx.h"
151-
#define PMA_LENGTH (1024u)
151+
#define FSDEV_PMA_SIZE (1024u)
152152

153153
#elif CFG_TUSB_MCU == OPT_MCU_STM32L5
154154
#include "stm32l5xx.h"
155-
#define PMA_LENGTH (1024u)
155+
#define FSDEV_PMA_SIZE (1024u)
156156

157157
#ifndef USB_PMAADDR
158158
#define USB_PMAADDR (USB_BASE + (USB_PMAADDR_NS - USB_BASE_NS))
@@ -164,15 +164,16 @@
164164
#endif
165165

166166
// 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)
171171
#endif
172172

173+
// The fsdev_bus_t type can be used for both register and PMA access necessities
173174
// For type-safety create a new macro for the volatile address of PMAADDR
174175
// The compiler should warn us if we cast it to a non-volatile type?
175-
#ifdef PMA_32BIT_ACCESS
176+
#ifdef FSDEV_BUS_32BIT
176177
typedef uint32_t fsdev_bus_t;
177178
static __IO uint32_t * const pma32 = (__IO uint32_t*)USB_PMAADDR;
178179

@@ -184,7 +185,7 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
184185
TU_ATTR_ALWAYS_INLINE static inline __IO uint16_t * pcd_btable_word_ptr(USB_TypeDef * USBx, size_t x)
185186
{
186187
size_t total_word_offset = (((USBx)->BTABLE)>>1) + x;
187-
total_word_offset *= PMA_STRIDE;
188+
total_word_offset *= FSDEV_PMA_STRIDE;
188189
return &(pma[total_word_offset]);
189190
}
190191

@@ -215,7 +216,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t pcd_aligned_buffer_size(uint16_t si
215216
/* SetENDPOINT */
216217
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_endpoint(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t wRegValue)
217218
{
218-
#ifdef PMA_32BIT_ACCESS
219+
#ifdef FSDEV_BUS_32BIT
219220
(void) USBx;
220221
__O uint32_t *reg = (__O uint32_t *)(USB_DRD_BASE + bEpIdx*4);
221222
*reg = wRegValue;
@@ -227,7 +228,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_endpoint(USB_TypeDef * USBx, ui
227228

228229
/* GetENDPOINT */
229230
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
231232
(void) USBx;
232233
__I uint32_t *reg = (__I uint32_t *)(USB_DRD_BASE + bEpIdx*4);
233234
#else
@@ -282,7 +283,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_clear_tx_ep_ctr(USB_TypeDef * USBx,
282283
*/
283284
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_cnt(USB_TypeDef * USBx, uint32_t bEpIdx)
284285
{
285-
#ifdef PMA_32BIT_ACCESS
286+
#ifdef FSDEV_BUS_32BIT
286287
(void) USBx;
287288
return (pma32[2*bEpIdx] & 0x03FF0000) >> 16;
288289
#else
@@ -293,7 +294,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_cnt(USB_TypeDef * USB
293294

294295
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_cnt(USB_TypeDef * USBx, uint32_t bEpIdx)
295296
{
296-
#ifdef PMA_32BIT_ACCESS
297+
#ifdef FSDEV_BUS_32BIT
297298
(void) USBx;
298299
return (pma32[2*bEpIdx + 1] & 0x03FF0000) >> 16;
299300
#else
@@ -320,7 +321,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_address(USB_TypeDef * USBx,
320321

321322
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_address(USB_TypeDef * USBx, uint32_t bEpIdx)
322323
{
323-
#ifdef PMA_32BIT_ACCESS
324+
#ifdef FSDEV_BUS_32BIT
324325
(void) USBx;
325326
return pma32[2*bEpIdx] & 0x0000FFFFu ;
326327
#else
@@ -330,7 +331,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_address(USB_TypeDef *
330331

331332
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_address(USB_TypeDef * USBx, uint32_t bEpIdx)
332333
{
333-
#ifdef PMA_32BIT_ACCESS
334+
#ifdef FSDEV_BUS_32BIT
334335
(void) USBx;
335336
return pma32[2*bEpIdx + 1] & 0x0000FFFFu;
336337
#else
@@ -340,7 +341,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_address(USB_TypeDef *
340341

341342
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_address(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t addr)
342343
{
343-
#ifdef PMA_32BIT_ACCESS
344+
#ifdef FSDEV_BUS_32BIT
344345
(void) USBx;
345346
pma32[2*bEpIdx] = (pma32[2*bEpIdx] & 0xFFFF0000u) | (addr & 0x0000FFFCu);
346347
#else
@@ -350,7 +351,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_address(USB_TypeDef * USB
350351

351352
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_address(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t addr)
352353
{
353-
#ifdef PMA_32BIT_ACCESS
354+
#ifdef FSDEV_BUS_32BIT
354355
(void) USBx;
355356
pma32[2*bEpIdx + 1] = (pma32[2*bEpIdx + 1] & 0xFFFF0000u) | (addr & 0x0000FFFCu);
356357
#else
@@ -360,7 +361,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_address(USB_TypeDef * USB
360361

361362
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_cnt(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t wCount)
362363
{
363-
#ifdef PMA_32BIT_ACCESS
364+
#ifdef FSDEV_BUS_32BIT
364365
(void) USBx;
365366
pma32[2*bEpIdx] = (pma32[2*bEpIdx] & ~0x03FF0000u) | ((wCount & 0x3FFu) << 16);
366367
#else
@@ -371,7 +372,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_cnt(USB_TypeDef * USBx, u
371372

372373
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t wCount)
373374
{
374-
#ifdef PMA_32BIT_ACCESS
375+
#ifdef FSDEV_BUS_32BIT
375376
(void) USBx;
376377
pma32[2*bEpIdx + 1] = (pma32[2*bEpIdx + 1] & ~0x03FF0000u) | ((wCount & 0x3FFu) << 16);
377378
#else
@@ -383,7 +384,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx, u
383384
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)
384385
{
385386
/* Encode into register. When BLSIZE==1, we need to subtract 1 block count */
386-
#ifdef PMA_32BIT_ACCESS
387+
#ifdef FSDEV_BUS_32BIT
387388
(void) USBx;
388389
pma32[rxtx_idx] = (pma32[rxtx_idx] & 0x0000FFFFu) | (blocksize << 31) | ((numblocks - blocksize) << 26);
389390
#else

0 commit comments

Comments
 (0)