cancel
Showing results for 
Search instead for 
Did you mean: 

Modify of HAL_PWR_EnterSLEEPMode() function

kisstibor
Associate
Posted on January 17, 2017 at 13:39

I�m working on a time critical application with OpenSTM32 System Workbench for STM32 .

I�d like to reduce the call time of HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry).

The code :

void

Sleep(

uint8_t

SLEEPEntry )

{

 

// Select the regulator state in Sleep mode: Set PDDS and LPSDSR bit according to PWR_Regulator value

  MODIFY_REG(PWR->

CR

, (PWR_CR_PDDS | PWR_CR_LPSDSR), PWR_MAINREGULATOR_ON );

 

// Clear SLEEPDEEP bit of

Cortex

System Control Register

  CLEAR_BIT(SCB->

SCR

, ((

uint32_t

)SCB_SCR_SLEEPDEEP_Msk));

 

// Select SLEEP mode entry

 

if

(SLEEPEntry == PWR_SLEEPENTRY_WFI)

  {

         __WFI();

// Request Wait For Interrupt

  }

 

else

  {

    __SEV();  

// Request Wait For Event

    __WFE();

    __WFE();

  }

}

I do not need the WIFI and WFE selection! I prefer SleepWFI() and SleepWFE()  INLINE functions.

If I remove the if statement the program freeze !

CLEAR_BIT(SCB->

SCR

, ((

uint32_t

)SCB_SCR_SLEEPDEEP_Msk));

// Select SLEEP mode entry

//if

(SLEEPEntry == PWR_SLEEPENTRY_WFI)

{

    __WFI();

// Request Wait For Interrupt

}

I tried with some extra NOP before _WFI() ... without success.

I do not understand !

It is OK :

if

(SLEEPEntry == PWR_SLEEPENTRY_WFI)

{

  __ASM

volatile

(

'NOP'

);

}

__WFI();

// Request Wait For Interrupt

The code can not run without if() !!!!

Thanks for help.

#if-selection-remove-before-__wfi().
0 REPLIES 0