Stop mode examples in testhal

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Stop mode examples in testhal

Post by dflogeras »

Hi,

In the STM32F4 and STM32F1 examples, the code snippets for putting the processor into low power mode are listed as

Code: Select all

  while (true){
    chThdSleepSeconds(10);

    /* going to anabiosis*/
    chSysLock();
    PWR->CR |= PWR_CR_CWUF | PWR_CR_CSBF;
    PWR->CR |= PWR_CR_PDDS | PWR_CR_LPDS;
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    __WFI();
  }
  return 0;


So chSysLock() is called before putting the processor to sleep, but chSysUnlock() is not called after. In these examples, if I am reading it correctly the processor is going into Standby mode (lack of LPSDSR bit) which means when it gets a wakeup trigger from the RTC, the system will reset, not resume executing the while(). Is that the reason Unlock is not called? If I were only going into Stop mode, I assume it would be imperative that I called chSysUnlock() after waking up again?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Stop mode examples in testhal

Post by Giovanni »

If it goes in reset then it does not matter, the OS is reinitialized.

Giovanni
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: Stop mode examples in testhal

Post by dflogeras »

Ok, that is what I had assumed, so let's now say I wished to go into STOP mode and continue after the WFI instruction.

On STM32 (specifically Lxxx) we had previously discussed that when coming back from STOP the clocks require re-configuring as the device will be using (in the case of Lxxx) the MSI clock. Should I call chSysUnlock() before or after stm32_clock_init() or does it matter?

Also, am I correct in assuming that I can eliminate the possibility of the race condition which I asked about last week (viewtopic.php?f=16&t=2918) with the following procedure:
    - Set up EXT to handle interrupt on desired pin (which sets a semaphore in the callback)
    - chSysLock() which will temporarily disable interrupts
    - check the result of chBSemWaitTimeoutS( &sem, TIME_IMMEDIATE ) to ensure that the interrupt has not occurred between 1 and 2 above
    - Setup PWR registers and call __WFI() to STOP mcu
    - chSysUnlock()
    - stm32_clock_init()
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Stop mode examples in testhal

Post by Giovanni »

Usually the clock initialization is done with interrupts disabled, better unlock after the initialization.

I must say that this scenario has never been tested, the clock initialization code could require changes because usually it is called with the device running from HSI.

Giovanni
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: Stop mode examples in testhal

Post by dflogeras »

Sounds good, I'll unlock after clock init.

Hmm, according to the RM0038 (for stm32L100 151 152 and 162), section 6.2.3

The MSI clock is used as system clock after restart from Reset, wake-up from Stop, and
Standby low power mode. After restart from Reset or wake-up from Standby, the MSI
frequency is set to its default value. The RCC_ICSCR register value is retained in STOP
mode, thus the MSI frequency and calibration after Wake-Up is the same as before entering
STOP mode.


I can confirm that I have indeed used STOP and STANDBY modes in several 151/152 devices with this method.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Stop mode examples in testhal

Post by Giovanni »

The it should be OK, I confused with other STM32s.

Giovanni
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: Stop mode examples in testhal

Post by enrico.dallavia »

Hi,
could I know how to setup the pin PA0 to use it as wake-up pin when the processor goes to StandBy (the lowest achievable power consumption mode)? I'm using an stmf429 processor but the inside manual of st I can't see how to setup it (it is not an alternate function), so I have to only put him as an input? (analog or digital?)

Thanks
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: Stop mode examples in testhal

Post by enrico.dallavia »

Maybe I found something, I have to set to 1 on bit 8 (EWUP) on PWR_CSR (power control/status register) enable WKUP pin (from stm32f429 programming manual)
Post Reply