Skip to content

Commit 412b557

Browse files
committed
Cleanup unnecessary code for 16bit access.
1 parent 818bda1 commit 412b557

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,6 @@ TU_ATTR_ALWAYS_INLINE static inline xfer_ctl_t* xfer_ctl_ptr(uint32_t ep_addr)
210210
return &xfer_status[epnum][dir];
211211
}
212212

213-
// Using a function due to better type checks
214-
// This seems better than having to do type casts everywhere else
215-
TU_ATTR_ALWAYS_INLINE static inline void reg16_clear_bits(__IO uint16_t *reg, uint16_t mask) {
216-
*reg = (uint16_t)(*reg & ~mask);
217-
}
218-
219-
// Bits in ISTR are cleared upon writing 0
220-
TU_ATTR_ALWAYS_INLINE static inline void clear_istr_bits(uint32_t mask) {
221-
USB->ISTR = ~mask;
222-
}
223-
224213
//--------------------------------------------------------------------+
225214
// Controller API
226215
//--------------------------------------------------------------------+
@@ -244,11 +233,7 @@ void dcd_init (uint8_t rhport)
244233
asm("NOP");
245234
}
246235

247-
#ifdef PMA_32BIT_ACCESS // CNTR register is 32bits on STM32G0, 16bit on older versions
248236
USB->CNTR &= ~USB_CNTR_PDWN;
249-
#else
250-
reg16_clear_bits(&USB->CNTR, USB_CNTR_PDWN);// Remove powerdown
251-
#endif
252237

253238
// Wait startup time, for F042 and F070, this is <= 1 us.
254239
for(uint32_t i = 0; i<200; i++) // should be a few us
@@ -492,7 +477,6 @@ static void dcd_handle_bus_reset(void)
492477
//__IO uint16_t * const epreg = &(EPREG(0));
493478
USB->DADDR = 0u; // disable USB peripheral by clearing the EF flag
494479

495-
496480
for(uint32_t i=0; i<STFSDEV_EP_COUNT; i++)
497481
{
498482
// Clear all EPREG (or maybe this is automatic? I'm not sure)
@@ -683,13 +667,13 @@ void dcd_int_handler(uint8_t rhport) {
683667

684668
/* Put SOF flag at the beginning of ISR in case to get least amount of jitter if it is used for timing purposes */
685669
if(int_status & USB_ISTR_SOF) {
686-
clear_istr_bits(USB_ISTR_SOF);
670+
USB->ISTR &=~USB_ISTR_SOF;
687671
dcd_event_sof(0, USB->FNR & USB_FNR_FN, true);
688672
}
689673

690674
if(int_status & USB_ISTR_RESET) {
691675
// USBRST is start of reset.
692-
clear_istr_bits(USB_ISTR_RESET);
676+
USB->ISTR &=~USB_ISTR_RESET;
693677
dcd_handle_bus_reset();
694678
dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
695679
return; // Don't do the rest of the things here; perhaps they've been cleared?
@@ -704,14 +688,10 @@ void dcd_int_handler(uint8_t rhport) {
704688

705689
if (int_status & USB_ISTR_WKUP)
706690
{
707-
#ifdef PMA_32BIT_ACCESS // CNTR register is 32bits on STM32G0, 16bit on older versions
708691
USB->CNTR &= ~USB_CNTR_LPMODE;
709692
USB->CNTR &= ~USB_CNTR_FSUSP;
710-
#else
711-
reg16_clear_bits(&USB->CNTR, USB_CNTR_LPMODE);
712-
reg16_clear_bits(&USB->CNTR, USB_CNTR_FSUSP);
713-
#endif
714-
clear_istr_bits(USB_ISTR_WKUP);
693+
694+
USB->ISTR &=~USB_ISTR_WKUP;
715695
dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
716696
}
717697

@@ -725,7 +705,7 @@ void dcd_int_handler(uint8_t rhport) {
725705
USB->CNTR |= USB_CNTR_LPMODE;
726706

727707
/* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
728-
clear_istr_bits(USB_ISTR_SUSP);
708+
USB->ISTR &=~USB_ISTR_SUSP;
729709
dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
730710
}
731711

@@ -738,7 +718,7 @@ void dcd_int_handler(uint8_t rhport) {
738718
{
739719
remoteWakeCountdown--;
740720
}
741-
clear_istr_bits(USB_ISTR_ESOF);
721+
USB->ISTR &=~USB_ISTR_ESOF;
742722
}
743723
}
744724

@@ -759,13 +739,8 @@ void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * re
759739
uint8_t const dev_addr = (uint8_t) request->wValue;
760740

761741
// Setting new address after the whole request is complete
762-
#ifdef PMA_32BIT_ACCESS
763742
USB->DADDR &= ~USB_DADDR_ADD;
764-
USB->DADDR = (USB->DADDR & ~USB_DADDR_ADD_Msk) | dev_addr; // leave the enable bit set
765-
#else
766-
reg16_clear_bits(&USB->DADDR, USB_DADDR_ADD);
767-
USB->DADDR = (uint16_t)(USB->DADDR | dev_addr); // leave the enable bit set
768-
#endif
743+
USB->DADDR |= dev_addr; // leave the enable bit set
769744
}
770745
}
771746

0 commit comments

Comments
 (0)