Add back microsecond delay to STM32

This commit is contained in:
Scott Shawcroft 2020-03-23 16:09:50 -07:00
parent a56170d7f8
commit 653b7619ec
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
2 changed files with 7 additions and 4 deletions

View File

@ -42,9 +42,12 @@
#include "stm32f4xx_hal.h" #include "stm32f4xx_hal.h"
void common_hal_mcu_delay_us(uint32_t delay) { void common_hal_mcu_delay_us(uint32_t delay) {
if (__get_PRIMASK() == 0x00000000) { uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq()/1000000;
} else { 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; volatile uint32_t nesting_count = 0;

View File

@ -122,7 +122,7 @@
* @brief External Low Speed oscillator (LSE) value. * @brief External Low Speed oscillator (LSE) value.
*/ */
#if !defined (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 */ #endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT) #if !defined (LSE_STARTUP_TIMEOUT)