summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-03-02 17:51:48 +0700
committerhathach <[email protected]>2026-03-02 17:51:48 +0700
commit4df7ef54396e1695aa9504aef9dfe4263569c3f6 (patch)
treea46ba124a444a9f68671feb34c409e40a486d7ac
parent0daa444a9b337262c25fe2a2b4598bd3401464e5 (diff)
fix call_after timeout adjustment with rtos
-rw-r--r--hw/bsp/stm32h7/boards/stm32h743eval/board.h4
-rw-r--r--src/host/usbh.c10
-rw-r--r--src/host/usbh_pvt.h2
3 files changed, 10 insertions, 6 deletions
diff --git a/hw/bsp/stm32h7/boards/stm32h743eval/board.h b/hw/bsp/stm32h7/boards/stm32h743eval/board.h
index 0f0eb4ed3..d2f61a5ce 100644
--- a/hw/bsp/stm32h7/boards/stm32h743eval/board.h
+++ b/hw/bsp/stm32h7/boards/stm32h743eval/board.h
@@ -120,10 +120,10 @@ static inline void SystemClock_Config(void) {
// From H743 eval manual ETM can only work at 50 MHz clock by default because ETM signals
// are shared with other peripherals. Trace CLK = PLL1R.
RCC_OscInitStruct.PLL.PLLM = 5;
- RCC_OscInitStruct.PLL.PLLN = 160; // May reduce to 200 Mhz when tracing to avoid overflowing trace buffer
+ RCC_OscInitStruct.PLL.PLLN = 160; // May reduce to 100/200 Mhz when tracing to avoid overflowing trace buffer
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 4;
- RCC_OscInitStruct.PLL.PLLR = 16; // Trace clock is limit to 50 Mhz to meet board requirement
+ RCC_OscInitStruct.PLL.PLLR = RCC_OscInitStruct.PLL.PLLN/10; // Trace clock is limit to 50 Mhz to meet board requirement
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
diff --git a/src/host/usbh.c b/src/host/usbh.c
index a674b040e..5cf0096f2 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -363,7 +363,6 @@ TU_ATTR_ALWAYS_INLINE static inline bool usbh_setup_send(uint8_t daddr, const ui
return ret;
}
-// For non-scheduler deferred callback. For scheduler OS: blocking delay then callback
bool usbh_defer_func_ms_async(uint32_t ms, tusb_defer_func_t func, uintptr_t param) {
TU_ASSERT(_usbh_data.call_after.func == NULL);
TU_LOG_USBH("USBH schedule function after %u ms\r\n", (unsigned int)ms);
@@ -666,8 +665,12 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
TU_LOG_USBH("USBH invoke scheduled function\r\n");
_usbh_data.call_after.func = NULL;
after_cb(_usbh_data.call_after.arg);
- } else if (timeout_ms > (uint32_t)ms) {
- // reduce main event timeout to make sure we don't blocking more than call_after timeout
+ }
+
+ // above after_cb() can re-schedule another function, we need to re-check and reduce timeout of
+ // the main event timeout to make sure we aren't blocking more than call_after timeout.
+ if (_usbh_data.call_after.func != NULL &&
+ timeout_ms > (uint32_t)(_usbh_data.call_after.at_ms - tusb_time_millis_api())) {
timeout_ms = (uint32_t)ms;
}
}
@@ -2033,6 +2036,7 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num) {
static void enum_full_complete(bool success) {
(void)success;
+ TU_LOG_USBH("Enumeration complete: success = %u\r\n", success);
_usbh_data.enumerating_daddr = TUSB_INDEX_INVALID_8; // mark enumeration as complete
_usbh_data.call_after.func = NULL;
diff --git a/src/host/usbh_pvt.h b/src/host/usbh_pvt.h
index bc8658b9a..adb6a8c44 100644
--- a/src/host/usbh_pvt.h
+++ b/src/host/usbh_pvt.h
@@ -71,7 +71,7 @@ void usbh_int_set(bool enabled);
// Invoke this function later in tuh_task() by putting it into task queue
void usbh_defer_func(osal_task_func_t func, void *param, bool in_isr);
-// Schedules a function to be called after certain time in async manner
+// Schedules a function to be called after certain time asynchronously
bool usbh_defer_func_ms_async(uint32_t ms, tusb_defer_func_t func, uintptr_t param);
void usbh_spin_lock(bool in_isr);