usb: Only enable the SOF interrupt if user_callback_sof is given.

Otherwise we get 1 kHz of SOF interrupts even if we don't need them.

Originally reported by Uwe in https://github.com/libopencm3/libopencm3/pull/274
but BuFran provided a reworked implementation.
This commit is contained in:
Frantisek Burian 2014-12-19 00:53:21 +01:00 committed by Karl Palsson
parent 13004f81ee
commit 0cc0134f21
4 changed files with 14 additions and 4 deletions

View File

@ -343,4 +343,10 @@ static void stm32f103_poll(usbd_device *dev)
dev->user_callback_sof();
}
}
if (usbd_dev->user_callback_sof) {
BBIO_PERIPH(USB_CNTR_REG, USB_CNTR_SOFM) = 1;
} else {
BBIO_PERIPH(USB_CNTR_REG, USB_CNTR_SOFM) = 0;
}
}

View File

@ -82,8 +82,7 @@ static usbd_device *stm32f107_usbd_init(void)
OTG_FS_GINTMSK_RXFLVLM |
OTG_FS_GINTMSK_IEPINT |
OTG_FS_GINTMSK_USBSUSPM |
OTG_FS_GINTMSK_WUIM |
OTG_FS_GINTMSK_SOFM;
OTG_FS_GINTMSK_WUIM;
OTG_FS_DAINTMSK = 0xF;
OTG_FS_DIEPMSK = OTG_FS_DIEPMSK_XFRCM;

View File

@ -82,8 +82,7 @@ static usbd_device *stm32f207_usbd_init(void)
OTG_HS_GINTMSK_RXFLVLM |
OTG_HS_GINTMSK_IEPINT |
OTG_HS_GINTMSK_USBSUSPM |
OTG_HS_GINTMSK_WUIM |
OTG_HS_GINTMSK_SOFM;
OTG_HS_GINTMSK_WUIM;
OTG_HS_DAINTMSK = 0xF;
OTG_HS_DIEPMSK = OTG_HS_DIEPMSK_XFRCM;

View File

@ -326,6 +326,12 @@ void stm32fx07_poll(usbd_device *usbd_dev)
}
REBASE(OTG_GINTSTS) = OTG_FS_GINTSTS_SOF;
}
if (usbd_dev->user_callback_sof) {
BBIO_PERIPH(OTG_FS_GINTMSK, OTG_FS_GINTMSK_SOFM) = 1;
} else {
BBIO_PERIPH(OTG_FS_GINTMSK, OTG_FS_GINTMSK_SOFM) = 0;
}
}
void stm32fx07_disconnect(usbd_device *usbd_dev, bool disconnected)