Page 2 of 2

Re: Hard fault when exiting stop mode with RTC alarm on STM32F051

Posted: Tue Sep 10, 2019 6:56 pm
by storzinc
There is already one nop after wfi, if I add another one - nothing changes, the program still crash and still in the middle of the bl, but if I add 3 or more nops, or remove all of them - program stops crashing. The function call seems to be important in the reproduction of this crash, I firstly tried to move __disable_irq() directly in the body of the waiting loop, but with that the crash is also disappears, no matter how many nops I add around it, so I moved it in its own noinline function.

Re: Hard fault when exiting stop mode with RTC alarm on STM32F051

Posted: Wed Sep 11, 2019 3:47 pm
by storzinc
Tried this on the STM32F318K8U6 board and there everything works fine, without hard faults. I can not be 100% sure though, the problem is tricky to reproduce, with all these nops in the right places, maybe I just did not made the timing right.

Re: Hard fault when exiting stop mode with RTC alarm on STM32F051

Posted: Sat Sep 14, 2019 3:11 pm
by storzinc
I have reproduced this problem without chibios, using STM32 HAL and STM32CubeIDE 1.0.2, it also turned out that the function call is unnecessary for reproduction and I further simplified RTC_Wait:

Code: Select all

void RTC_Wait()
{
nop();
//nop();

  lexit=0;

  PWR->CR|=PWR_CR_LPDS;              // enter stop mode
  SCB->SCR|=SCB_SCR_SLEEPDEEP_Msk;   //
  while(1)
  {
nop();
    __disable_irq();
    if(lexit)
    {
      __enable_irq();
      break;
    }
    __WFI();
nop();
//nop();
    __enable_irq();
  }
  SCB->SCR&=~SCB_SCR_SLEEPDEEP_Msk;
}

Now the hard fault happens at the address 8000e24, and there is actually no instructions at all!

Code: Select all

 8000e16:   bf30         wfi
 8000e18:   46c0         nop         ; (mov r8, r8)
 8000e1a:   b662         cpsie   i
 8000e1c:   e7f0         b.n   8000e00 <RTC_Wait+0x1c>
 8000e1e:   46c0         nop         ; (mov r8, r8)
 8000e20:   20000020    .word   0x20000020
 8000e24:   40007000    .word   0x40007000
 8000e28:   e000ed00    .word   0xe000ed00

Now it really looks like a hardware bug, it seems as if the execution continues from the wrong address.

If someone is interested in reproducing this my full STM32CubeIDE project is in the attachment.

Re: Hard fault when exiting stop mode with RTC alarm on STM32F051

Posted: Sat Sep 14, 2019 4:01 pm
by Giovanni
Hi,

I would try to post this on the ST forum, it is possible they already handled this problem. Of course we would be interested in hearing the solution of this mystery :)

Giovanni