cancel
Showing results for 
Search instead for 
Did you mean: 

How can I return from sleep mode on stm32f401

DUrbano
Associate III
Posted on October 03, 2014 at 14:28

Hi,

I'm facing with a strange problem, in fact I'm working on Discovery platform to study the stm32f4 low power modes. I'd like to enter and exit from sleep mode and to do this I use an UART to send the command to enter in sleep mode, and the PA0 button to exit. My problem is that while I have not problem to enter in sleep mode, even pushing the button, the mcu does not exit from this mode, and I don't really know where is the problem...could anyone please help me ? The attached file is my main.c where I wrote all the necessary code.

Regards

8 REPLIES 8
chen
Associate II
Posted on October 03, 2014 at 15:31

Hi

I think you need to read and understand the reference manual for the STM32F4 device for power control (the low power modes are in that section).

Also read the section on EXTI

From my quick look through your code:

''My problem is that while I have not problem to enter in sleep mode,''

Yes, it does look like you make the call to enter sleep mode but I bet it is not in there for long.

SleepMode is exited by ANY Interrupt, which includes the SysTick IRQ

'' I use an UART to send the command to enter in sleep mode, and the PA0 button to exit.''

How do you expect the push button on PA0 to exit sleep?

Unless I missed it - I do not see anything that configures PA0 to an EXTI

DUrbano
Associate III
Posted on October 03, 2014 at 15:45

I read your answer and I know the SysTick should be cause the exit from sleep mode, but if you look the while(1) I take every tick value and send it on the UART so I can read it on a PC; in fact when I send via UART the command tho enter in sleep mode, the printing of the tick values immediatly stops and when I push the button I expect to see the new values but it doesn't happen. For the PA0 button, you are right, in fact, using CubeMX the configuration of this pin is in the gpio.c (attached).

Regards

________________

Attachments :

gpio.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1AK&d=%2Fa%2F0X0000000bjI%2FB96czEXHugNOLpMaQpZR2fk8CjpfMsYdeL8UxbvCic0&asPdf=false
chen
Associate II
Posted on October 03, 2014 at 15:56

I say again :

Also read the section on EXTI

SleepMode is exited by ANY Interrupt

I do not see anything that configures PA0 to an EXTI

DUrbano
Associate III
Posted on October 03, 2014 at 16:09

Ok, I'll follow your suggest...the code you search is:

  /*Configure GPIO pin : PA0 */

  GPIO_InitStruct.Pin = GPIO_PIN_0;

  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* EXTI interrupt init*/

  /* Sets the priority grouping field */

  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);

  HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(EXTI0_IRQn);

As I have said, the code above is in gpio.c attached in my previuos message; in the HAL_GPIO_Init the pin is setted like external interrupt...

chen
Associate II
Posted on October 03, 2014 at 16:17

''  HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);''

I assume you mean this line sets PA0 (port A, bit 0) to EXTI

Do not use magic numbers - it makes working out what is going on much harder!

How are you testing whether you are in sleep mode?

I say again :

'' I bet it is not in there for long.

SleepMode is exited by ANY Interrupt, which includes the SysTick IRQ''

DUrbano
Associate III
Posted on October 03, 2014 at 16:34

Listen....I read what you have suggested me, in fact in UART RX Interrupt routine the instructions:

/* Reset SLEEPDEEP bit of Cortex System Control Register */

SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);

/* Reset SLEEPONEXIT bit of Cortex System Control Register */

SCB->SCR &= (uint32_t)0xFFFFFFFD;

have been taken exactly from Reference Manual, page 77/835 (sorry if I use this magic numbers...), paragraph ''Exiting Sleep Mode''. After your suggest, I have modified the main.c introducing the disabling of the sys tick before entering in the sleep mode and enabling after the exit, but I can not re-entering in run mode. I use the pin PA0, linked with the push button, as EXTI0 interrupt line, to exit from sleep mode, while the UART2 is used to connect with a PC from which I can see the the tick values and send the command ''smON '' to enter the mcu in sleep mode. I see the tick values on my PC updating very quickly until I send the UART command; after that they stopped and when I push the button do not resume...

________________

Attachments :

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I19g&d=%2Fa%2F0X0000000bjG%2FI_icDMY_ZoTAo_.bUqnyH4EtM0C4GY1uUFReMr1Dess&asPdf=false
chen
Associate II
Posted on October 03, 2014 at 16:57

Hi

What you have done is make life really hard for yourself!

You have entered Sleep mode in an ISR (The UART ISR)

So when the processor wake, it will continue from where it left off (where is entered).

Now you have exited sleep with an IRQ, the ISR must be executed as per the normal IRQ priority rules.

Now, since the processor when to sleep in an ISR - I cannot tell you what is going to happen.

Make life simple for yourself :

make 1 application which runs with no sleep, make it blink an LED or output count to UART

make 2nd application which does the same as first but goes into sleep while it is not doing anything.

compare the current (mA) difference between the 2.

DUrbano
Associate III
Posted on October 03, 2014 at 17:41

Ok, the problem was the enter in sleep mode in the UART interrupt routine, as you said...now I can enter and exit with any problem...thank you very much for your support.

Regards