STM32WLE immediately exist Stop2 when using UTILS_ENTER_CRITICAL_SECTION()
I am doing a LoRaWAN project on the STM32WLE and so I want to power it down in Stop2 mode to lower the power consumption.
Using the following code, this works fine :
UTILS_ENTER_CRITICAL_SECTION(); // mask interrupts
if (applicationEventBuffer.isEmpty() && loraWanEventBuffer.isEmpty()) { // If no events are pending in any of the eventBuffers...
HAL_SuspendTick(); // stop Systick
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI); // go into Sleep - STOP2
HAL_ResumeTick(); // re-enable Systick
} //
UTILS_EXIT_CRITICAL_SECTION(); // re-enable interruptsHowever, when some of my other code uses UTILS_ENTER_CRITICAL_SECTION(); to make things thread safe between the main thread and the interrupt-handlers, the device does not stay into Stop2 but wakes up immediately..
Commenting out the UTILS_ENTER_CRITICAL_SECTION(); UTILS_EXIT_CRITICAL_SECTION(); it works as it should, but then the code is not thread safe anymore...
Here's what those macro's are doing (utilities_conf.h)
#define UTILS_ENTER_CRITICAL_SECTION() uint32_t primask_bit= __get_PRIMASK();\
__disable_irq()
#define UTILS_EXIT_CRITICAL_SECTION() __set_PRIMASK(primask_bit)Any hints on how to solve this in a clean way ?
Thank you!