Fix bug where the EPREGs were not being initialized as expected.

This commit is contained in:
Nathan Conrad 2019-09-11 09:43:57 -04:00
parent 9cc355d302
commit 4cf2b30759
2 changed files with 8 additions and 8 deletions

View File

@ -216,10 +216,11 @@ void dcd_init (uint8_t rhport)
USB->ISTR &= ~(USB_ISTR_ALL_EVENTS); // Clear pending interrupts
// Clear all EPREG
for(uint16_t i=0; i<8; i++)
// Reset endpoints to disabled
for(uint i=0; i<STFSDEV_EP_COUNT; i++)
{
EPREG(0) = 0u;
// This doesn't clear all bits since some bits are "toggle", but does set the type to DISABLED.
PCD_GET_ENDPOINT(USB,i) = 0u;
}
// Initialize the BTABLE for EP0 at this point (though setting up the EP0R is unneeded)
@ -327,9 +328,9 @@ static void dcd_handle_bus_reset(void)
USB->DADDR = 0u; // disable USB peripheral by clearing the EF flag
// Clear all EPREG (or maybe this is automatic? I'm not sure)
for(uint16_t i=0; i<8; i++)
for(uint i=0; i<STFSDEV_EP_COUNT; i++)
{
EPREG(0) = 0u;
PCD_GET_ENDPOINT(USB,i) = 0u;
}
ep_buf_ptr = DCD_STM32_BTABLE_BASE + 8*MAX_EP_COUNT; // 8 bytes per endpoint (two TX and two RX words, each)

View File

@ -271,9 +271,6 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
#define PCD_CLEAR_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \
(USB_EP_CTR_RX|USB_EP_CTR_TX|((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPKIND_MASK)))))
#define EPREG(n) (((__IO uint16_t*)USB_BASE)[n*2])
// This checks if the device has "LPM"
#if defined(USB_ISTR_L1REQ)
#define USB_ISTR_L1REQ_FORCED (USB_ISTR_L1REQ)
@ -284,5 +281,7 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
#define USB_ISTR_ALL_EVENTS (USB_ISTR_PMAOVR | USB_ISTR_ERR | USB_ISTR_WKUP | USB_ISTR_SUSP | \
USB_ISTR_RESET | USB_ISTR_SOF | USB_ISTR_ESOF | USB_ISTR_L1REQ_FORCED )
// Number of endpoints in hardware
#define STFSDEV_EP_COUNT (8)
#endif /* PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_ */