diff --git a/ports/stm/common-hal/microcontroller/__init__.c b/ports/stm/common-hal/microcontroller/__init__.c index b20f49e590..a2d8e02c3a 100644 --- a/ports/stm/common-hal/microcontroller/__init__.c +++ b/ports/stm/common-hal/microcontroller/__init__.c @@ -42,9 +42,12 @@ #include "stm32f4xx_hal.h" void common_hal_mcu_delay_us(uint32_t delay) { - if (__get_PRIMASK() == 0x00000000) { - } else { - } + uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq()/1000000; + delay *= ticks_per_us; + SysTick->LOAD = delay; + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; + while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) {} + SysTick->CTRL = 0; } volatile uint32_t nesting_count = 0; diff --git a/ports/stm/stm32f4xx_hal_conf.h b/ports/stm/stm32f4xx_hal_conf.h index 4c19f8561f..0a8d272d2a 100644 --- a/ports/stm/stm32f4xx_hal_conf.h +++ b/ports/stm/stm32f4xx_hal_conf.h @@ -122,7 +122,7 @@ * @brief External Low Speed oscillator (LSE) value. */ #if !defined (LSE_VALUE) - #define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External Low Speed oscillator in Hz */ + #define LSE_VALUE 32768 /*!< Value of the External Low Speed oscillator in Hz */ #endif /* LSE_VALUE */ #if !defined (LSE_STARTUP_TIMEOUT)