Skip to content

Commit

Permalink
usb: Fixed up the number of endpoints defined in the control structures
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux committed Aug 11, 2024
1 parent 1677cb8 commit 157b826
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/usb/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ usbd_device *usbd_init(const usbd_driver *driver,
usbd_dev->user_callback_ctr[0][USB_TRANSACTION_IN] =
_usbd_control_in;

int i;
for (i = 0; i < MAX_USER_SET_CONFIG_CALLBACK; i++) {
for (size_t i = 0; i < MAX_USER_SET_CONFIG_CALLBACK; i++) {
usbd_dev->user_callback_set_config[i] = NULL;
}

Expand Down
13 changes: 4 additions & 9 deletions lib/usb/usb_dwc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
#define dev_base_address (usbd_dev->driver->base_address)
#define REBASE(x) MMIO32((x) + (dev_base_address))

/* The max number of endpoints is core-dependant - for the F4 it's 4, for the H7 it's 8 */
#if defined(STM32H7)
#define DWC_ENDPOINT_COUNT 8U
#else
#define DWC_ENDPOINT_COUNT 4U
#endif

void dwc_set_address(usbd_device *usbd_dev, uint8_t addr)
{
REBASE(OTG_DCFG) = (REBASE(OTG_DCFG) & ~OTG_DCFG_DAD) | (addr << 4);
Expand Down Expand Up @@ -122,7 +115,7 @@ void dwc_endpoints_reset(usbd_device *usbd_dev)
usbd_dev->fifo_mem_top = usbd_dev->fifo_mem_top_ep0;

/* Disable any currently active endpoints */
for (size_t i = 1; i < DWC_ENDPOINT_COUNT; i++) {
for (size_t i = 1; i < ENDPOINT_COUNT; i++) {
if (REBASE(OTG_DOEPCTL(i)) & OTG_DOEPCTL0_EPENA) {
REBASE(OTG_DOEPCTL(i)) |= OTG_DOEPCTL0_EPDIS;
}
Expand Down Expand Up @@ -340,8 +333,10 @@ void dwc_poll(usbd_device *usbd_dev)
/*
* There is no global interrupt flag for transmit complete.
* The XFRC bit must be checked in each OTG_DIEPINT(x).
*
* Iterate over the IN endpoints, triggering any post-transmit actions.
*/
for (size_t i = 0; i < DWC_ENDPOINT_COUNT; i++) { /* Iterate over endpoints. */
for (size_t i = 0; i < ENDPOINT_COUNT; i++) {
if (REBASE(OTG_DIEPINT(i)) & OTG_DIEPINTX_XFRC) {
/* Transfer complete. */
REBASE(OTG_DIEPINT(i)) = OTG_DIEPINTX_XFRC;
Expand Down
11 changes: 9 additions & 2 deletions lib/usb/usb_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ LGPL License Terms @ref lgpl_license

#define MIN(a, b) ((a) < (b) ? (a) : (b))

/* The max number of endpoints is core-dependant - for the F4 it's 4, for the H7 it's 8 */
#if defined(STM32H7)
#define ENDPOINT_COUNT 8U
#else
#define ENDPOINT_COUNT 4U
#endif

/** Internal collection of device information. */
struct _usbd_device {
const struct usb_device_descriptor *desc;
Expand Down Expand Up @@ -105,12 +112,12 @@ struct _usbd_device {

uint16_t fifo_mem_top;
uint16_t fifo_mem_top_ep0;
uint8_t force_nak[4];
uint8_t force_nak[ENDPOINT_COUNT];
/*
* We keep a backup copy of the out endpoint size registers to restore
* them after a transaction.
*/
uint32_t doeptsiz[4];
uint32_t doeptsiz[ENDPOINT_COUNT];
/*
* Received packet size for each endpoint. This is assigned in
* stm32f107_poll() which reads the packet status push register GRXSTSP
Expand Down

0 comments on commit 157b826

Please sign in to comment.