2016-12-15 01:59 PM
I have a STM32L152 device which spends most of its time in STOP mode, waking perhaps once an hour. I'd like to add IWDG support, but need to 'freeze' the IWDG during STOP mode, which per STM docs can be done.
I have not found an example, but it looks like I need to:
1) unlock the flash options (HAL_FLASH_OB_Unlock)
2) set my bits (HAL_FLASHEx_OBProgram)
3) load in the bits (HAL_FLASH_OB_Launch)
4) re-lock the flash options (HAL_FLASH_OB_Lock)
It seems easy enough, but I believe the 'launch' step resets the CPU, so one cannot just re-write IWDG_STOP every time I boot - is there any way to READ first to see if this bit needs to be written (there doesn't seem to be a HAL function to read the option bytes)? Any one worked with this action before & have suggestions - things to watch out for?
#stop-mode #stm32l #iwdg2016-12-16 12:42 PM
Hi,
Don't remember well, however it should be possible to read out the option bytes. Just check the reference manual or datasheet where the option bytes are placed in memory and read from that address like:
volatile uin32_t * optByte1 = (volatile uint32_t *) 0xXXXX XXXX;
if (IWDG_STOP == (*optByte1 & IWDG_STOP))
{
/* Do what you need to do here */
}
Code not tested, but should work. The memory should be normally readable.
Hope this helps,
Renegade