STOP MODE in STM32 || CubeIDE || Low Power Mode
2 views
Mar 26, 2020
Purchase the Products shown in this video from :: https://controllerstech.store ________________________________________________________________________________________ SLEEP MODE ::::: https://youtu.be/2rKcsGkCG0s STANDBY MODE :::: https://youtu.be/TFkU3QD71Pc STM32 Playlist :::: https://www.youtube.com/playlist?list=PLfIJKC1ud8gga7xeUUJ-bRUbeChfTOOBd DOWNLOAD THIS PROJECT FROM :::: https://controllerstech.com/low-power-modes-in-stm32/ ________________________________________________________________________________________ ******* SUPPORT US BY DONATING****** https://paypal.me/controllertech *******Join the Membership******* https://www.youtube.com/channel/UCkdqtSMnhYuMsJkyHOxiPZQ/join Join the Discord Server https://discord.gg/D32JE5wKyD
View Video Transcript
0:07
hello everyone welcome to controllers
0:11
tech few days ago I made a video about
0:15
sleep mode in stm32 this video will
0:19
cover the second topic on low-power
0:21
modes in stm32 and today we will use the
0:25
stock mode stop mode is based on deep
0:29
sleep mode and it is more aggressive
0:31
than the sleep mode of course the MCU
0:34
will consume less current in stop mode
0:37
but wake up latency also increases in it
0:40
let's take a look at the datasheet of f4
0:43
for 6r II controller
0:46
[Music]
0:56
[Music]
0:59
as you can see we have many
1:02
configurations in stop mode we can stop
1:06
the main regulator or power down the
1:08
flash also or stop the low-power
1:11
regulator also I am only going to cover
1:14
the first one where we are only going to
1:17
stop the main regulator let's start by
1:27
creating the project in cube IDE first I
1:32
am using stm32f4 for 6r II board give
1:38
some name to the project and click
1:41
finish
1:43
[Music]
1:49
in the cube MX I am enabling the
1:53
external crystal for the input clock
1:57
[Music]
1:59
pimp ei5 is connected to the onboard led
2:02
I am enabling you are to communicate to
2:10
the computer PC 13 is selected as
2:20
external interrupt pin now go to GPIO
2:27
NVIC tab and turn on the external
2:30
interrupts line now we will go to the
2:34
clock setup
2:35
I am using external crystal which is 8
2:38
megahertz HSE means high speed external
2:43
oscillator
2:44
I want the MCU to run at 180 megahertz
2:49
this completes the setup and let's just
2:53
save it so that the code can be
2:55
generated
3:02
[Music]
3:05
this is our main dot C file let's start
3:10
writing our program first of all I am
3:13
blinking the LED 20 times at a delay of
3:17
200 milliseconds next we will display
3:28
this string on the serial console before
3:30
going into the stop mode
3:50
now just like in the sleep mode here
3:53
also we need to suspend the ticks before
3:56
going into stop mode or else the systick
3:59
interrupt will wake the device up and
4:04
now finally we will enter the stop mode
4:08
how power enter stop mode takes two
4:11
parameters let's take a look at this
4:19
function the regulator can be configured
4:22
as if we want to keep the main regulator
4:24
on or keep the low-power regulator on I
4:28
am choosing the later one for low
4:30
current consumption
4:39
I am choosing the entry mode as wfi so
4:46
as to wake from sleep using the
4:48
interrupt
5:06
after wake up from the stop mode first
5:09
of all we must reconfigure the system
5:11
clocks this is because the main
5:14
regulator was turned off and we must
5:16
initialize all the clocks again next we
5:20
will resume the Cystic so that we can
5:23
work with hard alais I am blinking the
5:26
LED here every 2 seconds to indicate the
5:29
wakeup
5:30
and finally this string will be sent to
5:33
the console
5:44
let's build this code now
6:10
I am using Hercules for the serial
6:14
console I will directly run the code as
6:18
we can't debug in the stock mode
6:26
you
6:38
once the board is reset the LED will
6:41
toggle few times before going into the
6:43
stock mode the string is printed on the
6:46
console and the controller is in the
6:49
stock mode now once I press the button
6:52
external interrupts gets triggered and
6:55
MCU will wake up from sleep you can see
6:58
the LED blinking every two seconds and
7:02
finally the string gets printed on the
7:05
console if I reset the MCU same thing
7:09
will happen again
7:10
[Music]
7:17
[Music]
7:37
now I am going to write the external
7:40
interrupts callback function I am going
7:50
to resume both of these functions here
7:52
and this string is to confirm that the
7:55
MCU is waking up from the external
7:58
interrupts
8:03
[Music]
8:16
looks like I got the warning about the
8:18
callback function
8:20
[Music]
8:25
okay we are good to go now
8:28
we can also wake up the MCU using the
8:31
RTC interrupt this is the vital part of
8:34
this tutorial as we are going to use it
8:37
in the standby mode also first set up
8:53
the values off asynchronous prescaler
8:55
divider and synchronous prescaler
8:58
divider let's take a look at the data
9:01
sheet again
9:06
[Music]
9:14
[Music]
9:25
this is the formula to calculate the
9:28
espree clock to obtain the one Hertz of
9:34
espree clock the values are 128 and 256
9:38
for thirty two point seven six eight
9:40
kilohertz clock which are already set by
9:43
default so we will leave it as it is in
9:48
the wakeup section select the internal
9:50
wake up and make sure that you turn on
9:54
on the interrupt
10:04
Here I am not changing anything we don't
10:08
care about the current time as it's
10:10
going to be a periodic wake up leave the
10:14
wake up counter to zero we are going to
10:16
set it in the code itself
10:29
in the NVIC tab do the cross check if
10:33
all the interrupts are active
10:41
let's save this and we will go back to
10:44
our main file
10:59
here is our RTC initialization function
11:03
first copy this wakeup function and
11:07
comment it out from here
11:32
we will paste it in our main function
11:35
now we need to do the calculation for
11:38
the counter value
11:50
I took this calculation part from the
11:54
examples in the SD folder this part is
11:58
self-explanatory and I will just show
12:01
you the calculation I am going to set
12:04
the wake up period of ten seconds this
12:12
value is 16 and we need to divide it by
12:15
LSI which in my case is 32 kilohertz
12:33
now we need to divide the ten seconds by
12:37
this result and then convert the value
12:39
to the hex format
12:45
you
12:55
and finally feed this value to the
13:00
counter rest of the functions will
13:03
remain same
13:04
[Music]
13:12
I will just modify this string for
13:16
better indication just like the external
13:25
interrupts we are going to write the RTC
13:28
wake-up call back function copy this
13:31
entire code and paste it here modify
13:35
this string after the MCU wakes up
13:48
we must deactivate the periodic wakeup
13:50
or else the callback function will keep
13:52
executing every 10 seconds let's build
13:56
this now no errors so we are good to go
14:08
run the program as you can see the LED
14:12
blinks few time the string got printed
14:15
the MCU have entered the stop mode now
14:18
you can time the video and wait for 10
14:22
seconds after 10 seconds the string from
14:26
our TC callback is printed MCU is awake
14:29
and LED is blinking every 1 second
14:32
and finally the string in the main
14:35
function is printed let's reset the MCU
14:39
and this time I will wake it by using
14:41
the external interrupt pin
14:44
[Music]
14:50
now even after 10 seconds the periodic
14:53
task is not going to run because it got
14:56
disabled in the main loop after the MCU
14:58
wakes up now let's take a look at the
15:11
last part of this tutorial
15:12
that is the sleep on exit function I did
15:16
covered it the sleep mode also before
15:30
entering the stop mode just enable the
15:33
sleep on exit
15:35
[Music]
15:44
these callback functions are the only
15:46
functions that are going to execute as
15:49
this is the interrupt operation only as
15:52
soon as the control comes out of the
15:54
interrupt MC you will enter the stop
15:57
mode the MC you have entered the stop
16:04
mode we will wait for 10 seconds for the
16:07
RTC interrupt it wakes up after
16:15
executing the interrupt the MC you will
16:18
go back to the stop mode we will wait
16:21
for another 10 seconds to see this we
16:24
can wake the MCU using the external
16:26
interrupt also the RTC wakeup is
16:30
periodic because the control never comes
16:32
back to the main function and that's why
16:35
the RTC wake up is never deactivated I
16:37
will modify this operation a little if
16:41
the wake up is from external interrupts
16:44
let's disable the sleep on exit
16:56
and I am changing this time to five
16:58
seconds
16:59
as ten seconds is too long
17:50
remember if the control reaches main
17:53
function the RTC wakeup will be disabled
17:56
and rest of this code will work let's
17:59
run this program now
18:13
the LED blinks few times string gets
18:16
printed and the MCU enters the stop mode
18:20
we will wait for the RTC periodic wake
18:23
up now 5 seconds later the MCU wakes up
18:27
processes the interrupt and go back to
18:30
sleep this will keep happening until we
18:33
press the button now the sleep on exit
18:36
is disabled so the rest of the functions
18:39
in the main will execute now also note
18:42
that the RTC periodic wakeup is
18:45
deactivated as that was one of the
18:47
instructions in the main function and if
18:50
we wait for another 5 seconds or so
18:52
nothing happens this is it guys I hope
18:57
you understood the stop mode I will
19:01
cover standby mode in the upcoming video
19:03
by the way the current consumption
19:06
during stop mode was around 0.18 milli
19:09
ampair compared to 1 point 8 milli
19:12
ampair in sleep mode and 36 milli ampair
19:15
during normal run you can download the
19:19
code from the link in the description
19:21
have a nice day
#Electronics & Electrical
#Engineering & Technology