2023-02-03 07:48 AM
If I write to address 0, it prevents from entering shutdown mode.
The vector table is relocated to code.
As far as I understand, writing to address 0 in this case is not illegal. For sure it does not generates a fault.
The following code enters shutdown mode successfully:
#include "stm32wlxx_hal.h"
int main(void)
{
HAL_Init();
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
HAL_PWREx_EnterSHUTDOWNMode();
while (1)
{
}
}
The following code fails entering shutdown mode:
#include "stm32wlxx_hal.h"
int main(void)
{
HAL_Init();
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
*(int *)0 = 0x20008000; // End of SRAM
HAL_PWREx_EnterSHUTDOWNMode();
while (1)
{
}
}
I believe the second snippet should enter shutdown mode, or I missed something.
Regards
2023-02-03 10:23 AM
I don't know about the STM32WL family, but the other families can re-map address zero to FLASH, Bootloader ROM or RAM depending on boot mode. Is it possible that you have RAM mapped to 0x0 and you are therefore overwriting some variable?
As an aside, why would you (or anyone) purposely write to 0x0? That is usually the behavior of dereferencing a NULL pointer, which is bad. All of my programs configure the MMU to trap any write access to 0x0 specifically to catch those kind of issues.