0:15
everyone welcome to controllers tech
0:18
this video is the start of a new series
0:21
which will focus on the dual core
0:25
we will cover a lot of things here some
0:27
of which are unique to these
0:30
like inter cpu communication or hardware
0:34
etc so let's start with the first step
0:38
and that is getting started with stm32
0:44
this video will cover the basic things
0:47
like how to create project
0:48
how to debug both the cores
0:50
simultaneously and how to turn off
0:54
here i am using stm32h75
0:58
discovery board it have a cortex
1:01
m7 mcu and a cortex m4
1:05
mcu you can see it have a
1:08
lcd attached to it so a tutorial on
1:11
ltdc will be coming soon
1:18
let's start by creating a project in
1:27
select the microcontroller
1:39
give some name to this project and click
1:48
here you can see two different projects
1:50
got created for m7 core
1:58
here is our cube mx there are a lot of
2:03
and they are initialized in their
2:08
let's clear this pin out first
2:17
first of all i am selecting the external
2:19
crystal for the clock
2:22
this is valid for both m7 core and the
2:29
let's go to the clock setup now this
2:36
let's select pclk and try setting up the
2:40
clock at 400 megahertz
2:50
it's showing the error no problem
2:54
we will do the manual setup
3:03
let's divide it by 5 and then multiply
3:08
and we got the 400 megahertz clock
3:11
m4 core can run at maximum 240 megahertz
3:16
so we will divide here by 2.
3:19
also use the prescalers of 2 here
3:24
everything looks good now in case you
3:27
want to run it at maximum 480 megahertz
3:30
all you need to do is change the
3:32
multiplier here to 192.
3:36
and now the clock is at 480 megahertz
3:46
in case you keep getting error make sure
3:48
this voltage scale is selected least
3:52
in my case it is set to scale 1.
3:55
also supply source should be direct smps
3:59
supply let's enable the cache for the
4:02
m7 we will not be using mpu
4:06
anytime soon i am going to blink the
4:11
so let's take a look at the schematics
4:13
to find out where they are connected to
4:27
you can see we have 2 leds here led 1 is
4:36
led1 is connected to pin pj2 and
4:39
led2 is connected to pin pi13
4:52
so let's search for these pins and
4:54
select them as output
5:11
let's see the gpio setup now
5:15
here you see the pin context assignment
5:20
this means that the pin is not assigned
5:22
to either of these cores
5:23
and we can manually add them later but
5:28
and we are going to assign each pin to
5:34
i am assigning pi13 to the cortex m7 and
5:43
basically that's how every peripheral is
5:47
you can assign each peripheral to the
5:52
you have to turn the peripheral on for
5:55
and then set it up we will cover those
5:58
some other time that's all for the setup
6:03
click save to generate the project
6:07
this main file is for the m7 core
6:10
and this one is for the m4 core
6:24
note here that the system clock is
6:28
core and not in the m4 core
6:35
so it is necessary that the m7 core runs
6:38
configures the system clock and all
6:40
other necessary configurations
6:42
and then the m4 core can run
6:45
to make this possible these steps are
6:47
pre-generated in the code
6:50
here the cpu1 waits for the cpu-2 to go
6:58
if you look at the cpu-2 as soon as it
7:01
boots it enters the stop mode
7:06
after that cpu 1 initializes the system
7:10
and other necessary things and finally
7:13
it releases the hardware semaphore
7:22
cpu2 on the other hand before going into
7:26
activates the notification for the
7:30
when it receives the notification it
7:32
wakes up from the stop mode
7:34
and the rest of the code starts working
7:38
cpu one also waits for the cpu to to
7:43
this is how both the cores initializes
7:48
note that the pin pi13 is initialized in
7:52
just like we set up in the cube mx
7:56
in the while loop we will toggle this
7:58
pin every 500 milliseconds
8:16
similarly in the m4 core we will toggle
8:27
so that's it let's build it now
8:35
we have to separately build both the
8:42
let's debug them now this part is very
8:46
so pay attention here right now i have
8:50
selected the m7 cores main file go to
8:56
and double click here it will generate a
9:00
configuration note here that this is for
9:06
go to the debugger tab keep in mind what
9:10
is this port number for the gdb
9:13
here we have cortex m7
9:16
check this halt all cores this will
9:19
basically halt both the cores and that
9:22
way cpu 2 can't run on its own in the
9:26
shared st link must be checked
9:29
now go to startup tab here we have the
9:33
configuration for the cm7
9:36
click add select cm4 select debug
9:45
we are doing this because we want the
9:47
cortex m7 configuration to build
9:50
and load the code for m4 also
9:53
so that we don't have to load the code
9:55
separately using the m4
9:58
now click apply and click close
10:02
now we will create the configuration for
10:05
m4 so go to the main file of cortex m4
10:09
and click debug configuration
10:12
again double click here and it will
10:15
generate the configuration for the m4
10:17
core go to debugger tab
10:21
this is the same port number as for the
10:24
so we will increase it by at least three
10:28
under the reset behavior select none as
10:32
halting both the cores using m7 go to
10:36
tab we are already downloading the code
10:40
so we don't need to do it here select
10:43
edit and uncheck the download option
10:46
click apply to save this now we will
10:50
first launch the debugger using the m7
11:14
once we are in the debugger again launch
11:16
the m4 configuration
11:29
so here we are both the configurations
11:32
are loaded successfully
11:34
here you can see both the main files and
11:37
we can switch between them
11:38
depending on where we want to be let's
11:41
set a breakpoint here
11:43
before initializing the pin i am setting
11:46
it at the same statement
11:52
now select both these with control
11:56
run we need to run them together
12:00
or else it will stuck it hit the
12:03
breakpoint in the m4
12:12
if we go to the m7 configuration you can
12:15
this is also waiting at breakpoint
12:18
keep checking the leds on the board
12:22
i will go to m7 file and step over these
12:27
notice that the only the red led is
12:29
blinking as i am going through the
12:33
this means that the m4 core is still
12:35
waiting at that break point
12:38
we will keep this red led on and go to
12:42
and as i step over these statements only
12:47
is blinking so here we are able to debug
12:51
separately let's run this code now
12:55
since i am running the m4 code the green
12:59
while the red one is still on let's stop
13:10
and now only the red led is blinking
13:13
if you want to run both of them you have
13:16
to again select using the control button
13:41
everything is okay here but the problem
13:44
is that you can't reset a single core
13:51
whenever you want to reset you have to
14:02
even after that if we run it just like
14:05
this time the core 2 will not stop at
14:09
you can see that the core 1 has stopped
14:13
but this is not the case with the core 2
14:15
and it is still running
14:17
as you can see the leds keep blinking
14:20
i don't know why this happens and if
14:22
anyone have better idea
14:24
please comment below anyway we can stop
14:36
this is it for the debugging part now
14:40
let's say we want to run only one
14:42
core and don't want the second core to
14:45
unnecessarily in that case we must
14:49
stop the second core from booting this
14:52
can be done by modifying the option
14:55
and to do this we will use the sdm 32
14:59
cube programmer connect the device here
15:03
and click option bytes
15:07
here in the user configuration you can
15:10
see the bits bc bcm4
15:12
and bc m7 these bits controls
15:15
which cpu will boot and which won't
15:19
if i uncheck this that means the m4 core
15:22
boot click apply to save this
15:26
it will take some time maybe around 30
15:39
so we don't need this code anymore since
15:42
the second cpu is not booting
15:44
so it will definitely not go into the
15:48
same thing here also we can't wait for
15:51
the second core to come out of stop mode
15:53
since it's not booting at all
15:58
let's debug the m7 core
16:15
if i run this you can see only the red
16:19
and that means only the first core is
16:25
if we try to debug the second core it
16:33
so how do we run the second core now
16:37
we have to check the reference manual
17:01
here you can see some details are given
17:04
like which core will boot
17:08
anyway let's search for boot c2
17:34
here is an interesting thing in the rcc
17:39
the third bit controls the cpu too
17:43
and if we set it to 1 cpu 2 will boot
17:47
irrespective of the bcm4 value
17:52
now we will go back to the cpu 1 main
17:56
and after everything has been
17:57
initialized we will set the bit 3 of
18:29
also go to the second comain file and
18:32
comment out all these lines
18:34
we don't want the cpu2 to go into stop
18:45
now i will debug with m7 core
18:51
i am in the debugger now if i try to
18:56
i will get the error this is because the
18:59
is still not running
19:05
so what i will do is i will let this
19:08
and set the breakpoint here run it now
19:18
it hit the breakpoint so second core
19:25
if we debug the second core this time it
19:34
so this way we can control the boot for
19:55
i will leave the bcm4 on
20:04
let me quickly erase the flash once
20:07
before we sum up this video i want to
20:12
if the lcd is on and you don't want to
20:15
you can turn off the backlight here you
20:20
backlight is connected to pin pk 0.
20:28
so i will set the pk 0 to output
20:37
associate it with either of those cores
20:39
and set the output to low
20:50
let's enable the functions that we
20:58
also enable the ones for the m4
21:08
if we want to run the code we can simply
21:15
as we have configured that the m7
21:17
configuration will also load the program
21:20
we don't need to separately do the run
21:31
as you can see bot the leds are blinking
21:35
so we can directly load the program
21:37
using the configuration for m7 only
21:41
if you are directly running the program
21:43
you don't need to create a separate
21:45
configuration for m4
21:47
just make sure to edit the configuration
21:50
so that it can load the program for m4
21:54
this is it for this video i hope things
21:59
i will make more videos for cortex m7
22:03
and some for the dual core so keep
22:06
be safe and have a nice day ahead