Skip to content

Commit

Permalink
STM32F1, AT32F4, USB: Simplify ISTR handling
Browse files Browse the repository at this point in the history
We should only clear set bits, and we should only do that in the
ISTR central dispatcher.
  • Loading branch information
keirf committed Aug 17, 2023
1 parent c5b6894 commit 12c2c35
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/usb/hw_usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ static void usbd_init(void)
/* Exit reset state. */
usb->cntr &= ~USB_CNTR_FRES;
delay_us(10);

/* Clear IRQ state. */
usb->istr = 0;
}

static void usbd_deinit(void)
Expand Down Expand Up @@ -306,7 +303,6 @@ static void handle_reset(void)
buf_end = 64;
usb_configure_ep(0, EPT_CONTROL, EP0_MPS);
usb->daddr = USB_DADDR_EF | USB_DADDR_ADD(0);
usb->istr &= ~USB_ISTR_RESET;
}

static void clear_ctr(uint8_t ep, uint16_t ctr)
Expand Down Expand Up @@ -352,7 +348,7 @@ static void handle_tx_transfer(uint8_t ep)
static void usbd_process(void)
{
uint16_t istr = usb->istr;
usb->istr = ~istr & 0x7f00;
usb->istr = ~istr;

if (istr & USB_ISTR_CTR) {
uint8_t ep = USB_ISTR_GET_EP_ID(istr);
Expand Down
6 changes: 1 addition & 5 deletions src/usb/hw_usbd_at32f4.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ static void usbd_init(void)
usb->cntr &= ~USB_CNTR_FRES;
delay_us(10);

/* Clear IRQ state. */
usb->istr = 0;

IRQx_set_prio(USB_HP_IRQ, USB_IRQ_PRI);
IRQx_enable(USB_HP_IRQ);
}
Expand Down Expand Up @@ -321,7 +318,6 @@ static void handle_reset(void)
buf_end = 64;
usb_configure_ep(0, EPT_CONTROL, EP0_MPS);
usb->daddr = USB_DADDR_EF | USB_DADDR_ADD(0);
usb->istr &= ~USB_ISTR_RESET;
}

static void clear_ctr(uint8_t ep, uint16_t ctr)
Expand Down Expand Up @@ -376,7 +372,7 @@ static void handle_tx_transfer(uint8_t epnr)
static void usbd_process(void)
{
uint16_t istr = usb->istr;
usb->istr = ~istr & 0x7f00;
usb->istr = ~istr;

if (istr & USB_ISTR_CTR) {
uint8_t ep = USB_ISTR_GET_EP_ID(istr);
Expand Down

0 comments on commit 12c2c35

Please sign in to comment.