Skip to content

Commit edf1ef6

Browse files
authored
Merge pull request hathach#2675 from Okarss/fsdev_toggle_bits
[FSDEV] Simplify toggle bit logic
2 parents 0ac0c37 + fb6a6ac commit edf1ef6

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,19 @@ void dcd_init(uint8_t rhport)
215215
/* The RM mentions to use a special ordering of PDWN and FRES, but this isn't done in HAL.
216216
* Here, the RM is followed. */
217217

218-
for (uint32_t i = 0; i < 200; i++) { // should be a few us
218+
for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us
219219
asm("NOP");
220220
}
221221
// Perform USB peripheral reset
222222
USB->CNTR = USB_CNTR_FRES | USB_CNTR_PDWN;
223-
for (uint32_t i = 0; i < 200; i++) { // should be a few us
223+
for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us
224224
asm("NOP");
225225
}
226226

227227
USB->CNTR &= ~USB_CNTR_PDWN;
228228

229229
// Wait startup time, for F042 and F070, this is <= 1 us.
230-
for (uint32_t i = 0; i < 200; i++) { // should be a few us
230+
for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us
231231
asm("NOP");
232232
}
233233
USB->CNTR = 0; // Enable USB

src/portable/st/stm32_fsdev/fsdev_common.h

+2-22
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx, u
295295
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_status(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t wState) {
296296
uint32_t regVal = pcd_get_endpoint(USBx, bEpIdx);
297297
regVal &= USB_EPTX_DTOGMASK;
298-
299-
/* toggle first bit ? */
300-
if((USB_EPTX_DTOG1 & (wState))!= 0U)
301-
{
302-
regVal ^= USB_EPTX_DTOG1;
303-
}
304-
/* toggle second bit ? */
305-
if((USB_EPTX_DTOG2 & ((uint32_t)(wState)))!= 0U)
306-
{
307-
regVal ^= USB_EPTX_DTOG2;
308-
}
309-
298+
regVal ^= wState;
310299
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
311300
pcd_set_endpoint(USBx, bEpIdx, regVal);
312301
}
@@ -322,16 +311,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_status(USB_TypeDef * USBx
322311
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_status(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t wState) {
323312
uint32_t regVal = pcd_get_endpoint(USBx, bEpIdx);
324313
regVal &= USB_EPRX_DTOGMASK;
325-
326-
/* toggle first bit ? */
327-
if((USB_EPRX_DTOG1 & wState)!= 0U) {
328-
regVal ^= USB_EPRX_DTOG1;
329-
}
330-
/* toggle second bit ? */
331-
if((USB_EPRX_DTOG2 & wState)!= 0U) {
332-
regVal ^= USB_EPRX_DTOG2;
333-
}
334-
314+
regVal ^= wState;
335315
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
336316
pcd_set_endpoint(USBx, bEpIdx, regVal);
337317
}

0 commit comments

Comments
 (0)