Api hal timebase: fix lptim lockups caused by flag clear outside of interrupt (#332)
This commit is contained in:
		| @@ -11,6 +11,12 @@ | |||||||
| #define API_HAL_TIMEBASE_TICK_PER_EPOCH (API_HAL_TIMEBASE_TIMER_MAX / API_HAL_TIMEBASE_CLK_PER_TICK) | #define API_HAL_TIMEBASE_TICK_PER_EPOCH (API_HAL_TIMEBASE_TIMER_MAX / API_HAL_TIMEBASE_CLK_PER_TICK) | ||||||
| #define API_HAL_TIMEBASE_MAX_SLEEP (API_HAL_TIMEBASE_TICK_PER_EPOCH - 1) | #define API_HAL_TIMEBASE_MAX_SLEEP (API_HAL_TIMEBASE_TICK_PER_EPOCH - 1) | ||||||
|  |  | ||||||
|  | #ifdef API_HAL_TIMEBASE_DEBUG | ||||||
|  | #include <stm32wbxx_ll_gpio.h> | ||||||
|  | #define LED_GREEN_PORT GPIOA | ||||||
|  | #define LED_GREEN_PIN LL_GPIO_PIN_2 | ||||||
|  | #endif | ||||||
|  |  | ||||||
| typedef struct { | typedef struct { | ||||||
|     // Sleep control |     // Sleep control | ||||||
|     volatile uint16_t insomnia; |     volatile uint16_t insomnia; | ||||||
| @@ -98,7 +104,13 @@ static inline uint32_t api_hal_timebase_sleep(TickType_t expected_idle_ticks) { | |||||||
|  |  | ||||||
|     HAL_SuspendTick(); |     HAL_SuspendTick(); | ||||||
|     // Go to stop2 mode |     // Go to stop2 mode | ||||||
|  | #ifdef API_HAL_TIMEBASE_DEBUG | ||||||
|  |     LL_GPIO_SetOutputPin(LED_GREEN_PORT, LED_GREEN_PIN); | ||||||
|  | #endif | ||||||
|     api_hal_power_deep_sleep(); |     api_hal_power_deep_sleep(); | ||||||
|  | #ifdef API_HAL_TIMEBASE_DEBUG | ||||||
|  |     LL_GPIO_ResetOutputPin(LED_GREEN_PORT, LED_GREEN_PIN); | ||||||
|  | #endif | ||||||
|  |  | ||||||
|     HAL_ResumeTick(); |     HAL_ResumeTick(); | ||||||
|  |  | ||||||
| @@ -111,10 +123,7 @@ static inline uint32_t api_hal_timebase_sleep(TickType_t expected_idle_ticks) { | |||||||
|  |  | ||||||
|     // Store and clear interrupt flags |     // Store and clear interrupt flags | ||||||
|     // we don't want handler to be called after renabling IRQ |     // we don't want handler to be called after renabling IRQ | ||||||
|     bool cmpm_flag = LL_LPTIM_IsActiveFlag_CMPM(API_HAL_TIMEBASE_TIMER); |  | ||||||
|     if (cmpm_flag) LL_LPTIM_ClearFLAG_CMPM(API_HAL_TIMEBASE_TIMER); |  | ||||||
|     bool arrm_flag = LL_LPTIM_IsActiveFlag_ARRM(API_HAL_TIMEBASE_TIMER); |     bool arrm_flag = LL_LPTIM_IsActiveFlag_ARRM(API_HAL_TIMEBASE_TIMER); | ||||||
|     if (arrm_flag) LL_LPTIM_ClearFLAG_ARRM(API_HAL_TIMEBASE_TIMER); |  | ||||||
|  |  | ||||||
|     // Calculate and set next wakeup compare value |     // Calculate and set next wakeup compare value | ||||||
|     const uint16_t next_cmp = (after_tick + 1) * API_HAL_TIMEBASE_CLK_PER_TICK; |     const uint16_t next_cmp = (after_tick + 1) * API_HAL_TIMEBASE_CLK_PER_TICK; | ||||||
|   | |||||||
| @@ -14,6 +14,11 @@ FLASH_ADDRESS	= 0x08000000 | |||||||
| CFLAGS			+= -DNO_BOOTLOADER | CFLAGS			+= -DNO_BOOTLOADER | ||||||
| endif | endif | ||||||
|  |  | ||||||
|  | API_HAL_TIMEBASE_DEBUG ?= 0 | ||||||
|  | ifeq ($(API_HAL_TIMEBASE_DEBUG), 1) | ||||||
|  | CFLAGS			+= -DAPI_HAL_TIMEBASE_DEBUG | ||||||
|  | endif | ||||||
|  |  | ||||||
| OPENOCD_OPTS	= -f interface/stlink.cfg -c "transport select hla_swd" -f ../debug/stm32wbx.cfg -c "stm32wbx.cpu configure -rtos auto" -c "init" | OPENOCD_OPTS	= -f interface/stlink.cfg -c "transport select hla_swd" -f ../debug/stm32wbx.cfg -c "stm32wbx.cpu configure -rtos auto" -c "init" | ||||||
| BOOT_CFLAGS		= -DBOOT_ADDRESS=$(BOOT_ADDRESS) -DFW_ADDRESS=$(FW_ADDRESS) -DOS_OFFSET=$(OS_OFFSET) | BOOT_CFLAGS		= -DBOOT_ADDRESS=$(BOOT_ADDRESS) -DFW_ADDRESS=$(FW_ADDRESS) -DOS_OFFSET=$(OS_OFFSET) | ||||||
| MCU_FLAGS		= -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard | MCU_FLAGS		= -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user