Getting started with STM32 Dual Core CPUs || STM32H745 || How to DEBUG

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to controllers tech this video is the start of a new series which will focus on the dual core processors by st we will cover a lot of things here some of which are unique to these microcontrollers like inter cpu communication or hardware semaphores etc so let's start with the first step and that is getting started with stm32 dual core processors this video will cover the basic things like how to create project how to debug both the cores simultaneously and how to turn off second core here i am using stm32h75 discovery board it have a cortex m7 mcu and a cortex m4 mcu you can see it have a lcd attached to it so a tutorial on ltdc will be coming soon let's start by creating a project in cube id select the microcontroller give some name to this project and click finish [Music] here you can see two different projects got created for m7 core and m4 core here is our cube mx there are a lot of pins here and they are initialized in their default states let's clear this pin out first first of all i am selecting the external crystal for the clock this is valid for both m7 core and the m4 core let's go to the clock setup now this looks huge let's select pclk and try setting up the clock at 400 megahertz it's showing the error no problem we will do the manual setup let's divide it by 5 and then multiply by 160 and we got the 400 megahertz clock m4 core can run at maximum 240 megahertz so we will divide here by 2. also use the prescalers of 2 here everything looks good now in case you want to run it at maximum 480 megahertz all you need to do is change the multiplier here to 192. and now the clock is at 480 megahertz in case you keep getting error make sure this voltage scale is selected least here in my case it is set to scale 1. also supply source should be direct smps supply let's enable the cache for the cortex m7 we will not be using mpu anytime soon i am going to blink the on-board leds today so let's take a look at the schematics to find out where they are connected to you can see we have 2 leds here led 1 is green and led 2 is red led1 is connected to pin pj2 and led2 is connected to pin pi13 so let's search for these pins and select them as output let's see the gpio setup now here you see the pin context assignment is free by default this means that the pin is not assigned to either of these cores and we can manually add them later but we will not do that and we are going to assign each pin to the individual core i am assigning pi13 to the cortex m7 and pj2 to the cortex m4 basically that's how every peripheral is you can assign each peripheral to the individual core you have to turn the peripheral on for the respective core and then set it up we will cover those things some other time that's all for the setup click save to generate the project this main file is for the m7 core and this one is for the m4 core note here that the system clock is configured in the m7 core and not in the m4 core so it is necessary that the m7 core runs first configures the system clock and all other necessary configurations and then the m4 core can run to make this possible these steps are pre-generated in the code here the cpu1 waits for the cpu-2 to go into the stop mode if you look at the cpu-2 as soon as it boots it enters the stop mode after that cpu 1 initializes the system clock and other necessary things and finally it releases the hardware semaphore cpu2 on the other hand before going into stop mode activates the notification for the semaphore when it receives the notification it wakes up from the stop mode and the rest of the code starts working as usual cpu one also waits for the cpu to to wake up this is how both the cores initializes note that the pin pi13 is initialized in the m7 core just like we set up in the cube mx in the while loop we will toggle this pin every 500 milliseconds similarly in the m4 core we will toggle the pin pj2 so that's it let's build it now we have to separately build both the projects let's debug them now this part is very crucial so pay attention here right now i have selected the m7 cores main file go to debug configuration and double click here it will generate a debug configuration note here that this is for the cm7 go to the debugger tab keep in mind what is this port number for the gdb here we have cortex m7 check this halt all cores this will basically halt both the cores and that way cpu 2 can't run on its own in the beginning shared st link must be checked now go to startup tab here we have the configuration for the cm7 click add select cm4 select debug and click ok we are doing this because we want the cortex m7 configuration to build and load the code for m4 also so that we don't have to load the code separately using the m4 now click apply and click close now we will create the configuration for the cortex m4 so go to the main file of cortex m4 and click debug configuration again double click here and it will generate the configuration for the m4 core go to debugger tab this is the same port number as for the m7 so we will increase it by at least three under the reset behavior select none as we are already halting both the cores using m7 go to startup tab we are already downloading the code using the m7 so we don't need to do it here select edit and uncheck the download option click apply to save this now we will first launch the debugger using the m7 configuration once we are in the debugger again launch the m4 configuration so here we are both the configurations are loaded successfully here you can see both the main files and we can switch between them depending on where we want to be let's set a breakpoint here before initializing the pin i am setting it at the same statement in the m7 also now select both these with control button and click run we need to run them together or else it will stuck it hit the breakpoint in the m4 core if we go to the m7 configuration you can see this is also waiting at breakpoint keep checking the leds on the board i will go to m7 file and step over these statements notice that the only the red led is blinking as i am going through the statements this means that the m4 core is still waiting at that break point we will keep this red led on and go to the second core and as i step over these statements only the green led is blinking so here we are able to debug the cores separately let's run this code now since i am running the m4 code the green led is blinking while the red one is still on let's stop this one and run the m7 core and now only the red led is blinking if you want to run both of them you have to again select using the control button and then hit run everything is okay here but the problem is that you can't reset a single core whenever you want to reset you have to do for both cores even after that if we run it just like we run initially this time the core 2 will not stop at the break point you can see that the core 1 has stopped at the break point but this is not the case with the core 2 and it is still running as you can see the leds keep blinking i don't know why this happens and if anyone have better idea please comment below anyway we can stop the core 2 manually this is it for the debugging part now let's say we want to run only one core and don't want the second core to consume power unnecessarily in that case we must stop the second core from booting this can be done by modifying the option bytes and to do this we will use the sdm 32 cube programmer connect the device here and click option bytes here in the user configuration you can see the bits bc bcm4 and bc m7 these bits controls which cpu will boot and which won't if i uncheck this that means the m4 core will not boot click apply to save this it will take some time maybe around 30 seconds so we don't need this code anymore since the second cpu is not booting so it will definitely not go into the stop mode same thing here also we can't wait for the second core to come out of stop mode since it's not booting at all let's debug the m7 core if i run this you can see only the red led is blinking and that means only the first core is running if we try to debug the second core it won't work so how do we run the second core now we have to check the reference manual for that search for bcm4 here you can see some details are given like which core will boot anyway let's search for boot c2 do here is an interesting thing in the rcc gcr register the third bit controls the cpu too and if we set it to 1 cpu 2 will boot irrespective of the bcm4 value now we will go back to the cpu 1 main file and after everything has been initialized we will set the bit 3 of our ccgcr let's build it also go to the second comain file and comment out all these lines we don't want the cpu2 to go into stop mode now i will debug with m7 core i am in the debugger now if i try to debug the m4 i will get the error this is because the core is still not running so what i will do is i will let this line execute and set the breakpoint here run it now it hit the breakpoint so second core must be running now if we debug the second core this time it will connect so this way we can control the boot for the second core i will leave the bcm4 on let me quickly erase the flash once before we sum up this video i want to show one last thing if the lcd is on and you don't want to use it you can turn off the backlight here you can see the lcd backlight is connected to pin pk 0. so i will set the pk 0 to output associate it with either of those cores and set the output to low let's enable the functions that we disabled also enable the ones for the m4 if we want to run the code we can simply run for the m7 as we have configured that the m7 configuration will also load the program for m4 we don't need to separately do the run for m4 as you can see bot the leds are blinking together so we can directly load the program using the configuration for m7 only if you are directly running the program you don't need to create a separate configuration for m4 just make sure to edit the configuration of m7 so that it can load the program for m4 also this is it for this video i hope things were clear i will make more videos for cortex m7 processors and some for the dual core so keep watching be safe and have a nice day ahead you
Info
Channel: Controllers Tech
Views: 5,811
Rating: undefined out of 5
Keywords: stm32, stm32f4, discovery, nucleo, cortex, m7, dual, core, debugging, debug, turn, off, STM32H7, F7, H7
Id: jI1k6p-fduE
Channel Id: undefined
Length: 22min 30sec (1350 seconds)
Published: Sun May 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.