STOP MODE in STM32 || CubeIDE || Low Power Mode

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to controllers tech few days ago I made a video about sleep mode in stm32 this video will cover the second topic on low-power modes in stm32 and today we will use the stock mode stop mode is based on deep sleep mode and it is more aggressive than the sleep mode of course the MCU will consume less current in stop mode but wake up latency also increases in it let's take a look at the datasheet of f4 for 6r II controller [Music] [Music] as you can see we have many configurations in stop mode we can stop the main regulator or power down the flash also or stop the low-power regulator also I am only going to cover the first one where we are only going to stop the main regulator let's start by creating the project in cube IDE first I am using stm32f4 for 6r II board give some name to the project and click finish [Music] in the cube MX I am enabling the external crystal for the input clock [Music] pimp ei5 is connected to the onboard led I am enabling you are to communicate to the computer PC 13 is selected as external interrupt pin now go to GPIO NVIC tab and turn on the external interrupts line now we will go to the clock setup I am using external crystal which is 8 megahertz HSE means high speed external oscillator I want the MCU to run at 180 megahertz this completes the setup and let's just save it so that the code can be generated [Music] this is our main dot C file let's start writing our program first of all I am blinking the LED 20 times at a delay of 200 milliseconds next we will display this string on the serial console before going into the stop mode now just like in the sleep mode here also we need to suspend the ticks before going into stop mode or else the systick interrupt will wake the device up and now finally we will enter the stop mode how power enter stop mode takes two parameters let's take a look at this function the regulator can be configured as if we want to keep the main regulator on or keep the low-power regulator on I am choosing the later one for low current consumption I am choosing the entry mode as wfi so as to wake from sleep using the interrupt after wake up from the stop mode first of all we must reconfigure the system clocks this is because the main regulator was turned off and we must initialize all the clocks again next we will resume the Cystic so that we can work with hard alais I am blinking the LED here every 2 seconds to indicate the wakeup and finally this string will be sent to the console let's build this code now I am using Hercules for the serial console I will directly run the code as we can't debug in the stock mode you once the board is reset the LED will toggle few times before going into the stock mode the string is printed on the console and the controller is in the stock mode now once I press the button external interrupts gets triggered and MCU will wake up from sleep you can see the LED blinking every two seconds and finally the string gets printed on the console if I reset the MCU same thing will happen again [Music] [Music] now I am going to write the external interrupts callback function I am going to resume both of these functions here and this string is to confirm that the MCU is waking up from the external interrupts [Music] looks like I got the warning about the callback function [Music] okay we are good to go now we can also wake up the MCU using the RTC interrupt this is the vital part of this tutorial as we are going to use it in the standby mode also first set up the values off asynchronous prescaler divider and synchronous prescaler divider let's take a look at the data sheet again [Music] [Music] this is the formula to calculate the espree clock to obtain the one Hertz of espree clock the values are 128 and 256 for thirty two point seven six eight kilohertz clock which are already set by default so we will leave it as it is in the wakeup section select the internal wake up and make sure that you turn on on the interrupt Here I am not changing anything we don't care about the current time as it's going to be a periodic wake up leave the wake up counter to zero we are going to set it in the code itself in the NVIC tab do the cross check if all the interrupts are active let's save this and we will go back to our main file here is our RTC initialization function first copy this wakeup function and comment it out from here we will paste it in our main function now we need to do the calculation for the counter value I took this calculation part from the examples in the SD folder this part is self-explanatory and I will just show you the calculation I am going to set the wake up period of ten seconds this value is 16 and we need to divide it by LSI which in my case is 32 kilohertz now we need to divide the ten seconds by this result and then convert the value to the hex format you and finally feed this value to the counter rest of the functions will remain same [Music] I will just modify this string for better indication just like the external interrupts we are going to write the RTC wake-up call back function copy this entire code and paste it here modify this string after the MCU wakes up we must deactivate the periodic wakeup or else the callback function will keep executing every 10 seconds let's build this now no errors so we are good to go run the program as you can see the LED blinks few time the string got printed the MCU have entered the stop mode now you can time the video and wait for 10 seconds after 10 seconds the string from our TC callback is printed MCU is awake and LED is blinking every 1 second and finally the string in the main function is printed let's reset the MCU and this time I will wake it by using the external interrupt pin [Music] now even after 10 seconds the periodic task is not going to run because it got disabled in the main loop after the MCU wakes up now let's take a look at the last part of this tutorial that is the sleep on exit function I did covered it the sleep mode also before entering the stop mode just enable the sleep on exit [Music] these callback functions are the only functions that are going to execute as this is the interrupt operation only as soon as the control comes out of the interrupt MC you will enter the stop mode the MC you have entered the stop mode we will wait for 10 seconds for the RTC interrupt it wakes up after executing the interrupt the MC you will go back to the stop mode we will wait for another 10 seconds to see this we can wake the MCU using the external interrupt also the RTC wakeup is periodic because the control never comes back to the main function and that's why the RTC wake up is never deactivated I will modify this operation a little if the wake up is from external interrupts let's disable the sleep on exit and I am changing this time to five seconds as ten seconds is too long remember if the control reaches main function the RTC wakeup will be disabled and rest of this code will work let's run this program now the LED blinks few times string gets printed and the MCU enters the stop mode we will wait for the RTC periodic wake up now 5 seconds later the MCU wakes up processes the interrupt and go back to sleep this will keep happening until we press the button now the sleep on exit is disabled so the rest of the functions in the main will execute now also note that the RTC periodic wakeup is deactivated as that was one of the instructions in the main function and if we wait for another 5 seconds or so nothing happens this is it guys I hope you understood the stop mode I will cover standby mode in the upcoming video by the way the current consumption during stop mode was around 0.18 milli ampair compared to 1 point 8 milli ampair in sleep mode and 36 milli ampair during normal run you can download the code from the link in the description have a nice day
Info
Channel: ControllersTech
Views: 22,264
Rating: undefined out of 5
Keywords: stm32, f4, f103, low, power, mode, stop, sleep, how to, example, current, consumption, tutorial, cubeide
Id: UtQhc4XV8k4
Channel Id: undefined
Length: 19min 24sec (1164 seconds)
Published: Thu Mar 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.