summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--stmhal/stm32_it.c2
-rw-r--r--stmhal/timer.c1
-rw-r--r--stmhal/usbd_cdc_interface.c17
-rw-r--r--stmhal/usbd_cdc_interface.h2
-rw-r--r--stmhal/usbd_conf.c5
5 files changed, 11 insertions, 16 deletions
diff --git a/stmhal/stm32_it.c b/stmhal/stm32_it.c
index abef2ca79f..57b5d85302 100644
--- a/stmhal/stm32_it.c
+++ b/stmhal/stm32_it.c
@@ -480,8 +480,6 @@ void EXTI15_10_IRQHandler(void) {
void PVD_IRQHandler(void) {
IRQ_ENTER(PVD_IRQn);
#if defined(MICROPY_HW_USE_ALT_IRQ_FOR_CDC)
- extern void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void);
- USBD_CDC_HAL_TIM_PeriodElapsedCallback();
#endif
Handle_EXTI_Irq(EXTI_PVD_OUTPUT);
IRQ_EXIT(PVD_IRQn);
diff --git a/stmhal/timer.c b/stmhal/timer.c
index e1d659ceb0..850e0c8298 100644
--- a/stmhal/timer.c
+++ b/stmhal/timer.c
@@ -252,7 +252,6 @@ TIM_HandleTypeDef *timer_tim6_init(uint freq) {
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
#if !defined(MICROPY_HW_USE_ALT_IRQ_FOR_CDC)
if (htim == &TIM3_Handle) {
- USBD_CDC_HAL_TIM_PeriodElapsedCallback();
} else
#endif
if (htim == &TIM5_Handle) {
diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c
index 61553e27d3..801bcb753d 100644
--- a/stmhal/usbd_cdc_interface.c
+++ b/stmhal/usbd_cdc_interface.c
@@ -257,12 +257,10 @@ static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length) {
return USBD_OK;
}
-/**
- * @brief TIM period elapsed callback
- * @param htim: TIM handle
- * @retval None
- */
-void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void) {
+// This function is called to process outgoing data. We hook directly into the
+// SOF (start of frame) callback so that it is called exactly at the time it is
+// needed (reducing latency), and often enough (increasing bandwidth).
+void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
if (!dev_is_connected) {
// CDC device is not connected to a host, so we are unable to send any data
return;
@@ -276,9 +274,8 @@ void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void) {
if (UserTxBufPtrOut != UserTxBufPtrOutShadow) {
// We have sent data and are waiting for the low-level USB driver to
// finish sending it over the USB in-endpoint.
- // We have a 15 * 10ms = 150ms timeout
- if (UserTxBufPtrWaitCount < 15) {
- PCD_HandleTypeDef *hpcd = hUSBDDevice.pData;
+ // SOF occurs every 1ms, so we have a 150 * 1ms = 150ms timeout
+ if (UserTxBufPtrWaitCount < 150) {
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
if (USBx_INEP(CDC_IN_EP & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) {
// USB in-endpoint is still reading the data
@@ -457,7 +454,7 @@ void USBD_CDC_TxAlways(const uint8_t *buf, uint32_t len) {
}
// Some unused code that makes sure the low-level USB buffer is drained.
- // Waiting for low-level is handled in USBD_CDC_HAL_TIM_PeriodElapsedCallback.
+ // Waiting for low-level is handled in HAL_PCD_SOFCallback.
/*
start = HAL_GetTick();
PCD_HandleTypeDef *hpcd = hUSBDDevice.pData;
diff --git a/stmhal/usbd_cdc_interface.h b/stmhal/usbd_cdc_interface.h
index 0585d06c8c..f74b42bbee 100644
--- a/stmhal/usbd_cdc_interface.h
+++ b/stmhal/usbd_cdc_interface.h
@@ -31,8 +31,6 @@
extern const USBD_CDC_ItfTypeDef USBD_CDC_fops;
-void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void);
-
int USBD_CDC_IsConnected(void);
void USBD_CDC_SetInterrupt(int chr, void *data);
diff --git a/stmhal/usbd_conf.c b/stmhal/usbd_conf.c
index c6b049874b..5ff824071a 100644
--- a/stmhal/usbd_conf.c
+++ b/stmhal/usbd_conf.c
@@ -276,10 +276,13 @@ void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
* @param hpcd: PCD handle
* @retval None
*/
+/*
+This is now handled by the USB CDC interface.
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
{
USBD_LL_SOF(hpcd->pData);
}
+*/
/**
* @brief Reset callback.
@@ -394,7 +397,7 @@ if (pdev->id == USB_PHY_FS_ID)
pcd_fs_handle.Init.dma_enable = 0;
pcd_fs_handle.Init.low_power_enable = 0;
pcd_fs_handle.Init.phy_itface = PCD_PHY_EMBEDDED;
- pcd_fs_handle.Init.Sof_enable = 0;
+ pcd_fs_handle.Init.Sof_enable = 1;
pcd_fs_handle.Init.speed = PCD_SPEED_FULL;
#if !defined(MICROPY_HW_USB_VBUS_DETECT_PIN)
pcd_fs_handle.Init.vbus_sensing_enable = 0; // No VBUS Sensing on USB0