Skip to main content
Linas L
Senior
November 5, 2022
Question

IWDG disable during Sleep/Stop

  • November 5, 2022
  • 3 replies
  • 6114 views

Hello.

I am running STM32L412 microcontroller in low power GSM design. All works great, but I would also want to add watchdog just in case.

I am in STOP2 mode most of the time, and I am waiting for interrupts from GSM module or MEMS IRQ

I configured IWDG for 30s reset, I reload it just before sleep that takes 4 minutes (IWDG = 30s).

In boot I also RESET IWDG_STOP and IWDG_STBY bits based on reference manual, I also check FLASH OP register to see if bits are truly zeros and they are.

0693W00000WHW63QAH.png0693W00000WHW68QAH.png0693W00000WHW6DQAX.pngBUT I still been RESETED in STOP2 mode, while it should NOT HAPPEN based on my limited understanding.

Any ideas what I am doing wrong ?

 FLASH_UNLOCK();
 FLASH_OB_UNLOCK();
 CLEAR_BIT(FLASH->OPTR,FLASH_OPTR_IWDG_STOP|FLASH_OPTR_IWDG_STDBY);
 
 FLASH_OB_LOCK();
 FLASH_LOCK();
 
 
void FLASH_UNLOCK(void)
{
 if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U)
 {
 FLASH->KEYR = FLASH_KEY1;
 FLASH->KEYR = FLASH_KEY2;
 if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U)
 {
 //return 1;// ERROR
 }
 }
}
 
void FLASH_OB_UNLOCK(void)
{
 if(READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) != 0U)
 {
 FLASH->OPTKEYR = FLASH_OPTKEY1;
 FLASH->OPTKEYR = FLASH_OPTKEY2;
 }
 else
 {
 //return 1;// ERROR
 }
 //return 0;
}

This topic has been closed for replies.

3 replies

Piranha
Principal III
November 5, 2022
Linas L
Linas LAuthor
Senior
November 5, 2022

Could you be more specific whats wrong ? OPTR resgisters are protected at boot and cleared, be me afterwards, but IWDG still resets MCU in STOP2 mode.

What do I am missing or do not understand, clearing FLASH_OPTR_IWDG_STOP should stop IWDG running while in STOP2 mode, and prevent it from reset, right ?

Piranha
Principal III
November 5, 2022

You are missing the part where you are reading the reference manual section about option byte programming! Or just opening the link I gave and looking at an absolutely specific code example in the accepted answer... What's so hard in these actions?

Linas L
Linas LAuthor
Senior
November 6, 2022

Looks like I get it working. Problem was I was not clearing IWDG_SW (to enable Hardware independent watchdog) bit.

And it's very hard to understand why I need to do this, since reference manual does not give simple answer.

And yes, Piranha, your code did that, but I was not clear why. RM is not that clear I needed to do it in low power freze...

0693W00000WHWe0QAH.png

Piranha
Principal III
November 6, 2022

No, EEPROM emulation has nothing to do with option bytes. And no, IWDG_SW has nothing to do with stopping IWDG in low-power modes.

The RM0394 Rev 4 section "3.4.2 Option bytes programming" explains all of this very clearly. But you don't understand it because you haven't done the RTFM. When you will read it, you will also understand what and why my code does.

P.S. The current "best answer" doesn't actually answer anything and is just wrong on IWDG_SW.

Linas L
Linas LAuthor
Senior
November 7, 2022

So can you explain why my code runs now the way I expected ?

update:

Ok, so I looks like I am missing OPTSTRT and OBL_LAUNCH procedure, and IWDG just gets updated registers after reset.

I will add this to my code. I gess I so hang up on seeing that registers are updated, just did not understand/read that they need to be launched to take effect.

Piranha
Principal III
November 9, 2022

See, reading the reference manual helps and my first post was spot on! ;) Good that now you will understand that register and what the code does.