You are on page 1of 8

ELEC-E8001 Embedded Real-Time Systems

Hands on exercises 1 – Getting


started
1. Equipment
For getting started with the embedded development exercises, you will need to have a STM32F411
Nucleo-64 development board, as seen in Figure 1.

Figure 1. STM32F411 development board

Additionally, you will need:


● Computer running Windows
● Mini USB type B cable

2. Setting up the environment


1. Install the STM32CubeIDE from: https://www.st.com/en/development-tools/stm32cubeide.html.
Open the zip file and run the installer.
2. Install the ST-Link driver from: https://www.st.com/en/development-tools/stsw-link009.html.
Extract the zip to a folder. Read the readme file and follow the instructions.
3. Download the ST-Link firmware upgrade software: https://www.st.com/en/development-
tools/stsw-link007.html
4. Connect your development board to the PC with the USB cable. Open the firmware upgrade
software downloaded in step 3 from the Windows folder:

Figure 2. ST-Link Upgrade

Press Device Connect, and then Yes

Figure 3. ST-Link Upgrade

Finally, you should see that the upgrade is successful

Figure 4. ST-Link Upgrade

3. Testing your board and basic debugging


● Open STM32CubeIDE
● Create a workspace and click “Launch”
● Go to File -> Import -> General -> Existing Project into Workspace -> Select archive file -> TODO.zip
Remark 1: You should download the TODO.zip from mycourses.aalto.fi.
Remark 2: If this is the first time you run the IDE, you may need to close the window at the center
before the next step.
● In the IDE, open the Src\main.c file. Select Project -> Build the project. It should build without
errors.
● Go to Run and make sure that “Skip all Breakpoints” is NOT activated.
● Go to Run -> Debug Configurations -> double click “STM32 MCU Debugging”, then click the
Debugger tab, the Debug probe should be as in Figure 5

Figure 5. Debug configuration

● Go to Run -> Debug as -> STM 32 MCU C/C++ Application


Alternatively, you can select the arrow next to the green bug in the Figure 6:

Figure 6. Debug

Click “Switch” to switch debug perspective:

Figure 7. Perspective Switch

Before running, let’s add a debug breakpoint. Go to the line 28 in main.c, right click on the blue column,
next to the line number, and select Toggle Breakpoint (or just double-click on the blue column). A blue
bubble should appear on the blue column:
Figure 8. Debug breakpoint

In order to start running the program, you can press the green play button (or F8)

Figure 9. Resume debugging

The program now should run until line 28, where it stops at the breakpoint:

Figure 10. Breakpoint hit

Look at the board’s green LED. Press F8 again. The green LED should toggle.
Now, right click on the debug breakpoint that was previously placed at line 28, and select Disable
breakpoint. Now, the LED should be blinking at 10Hz.
Press the red button to terminate the program.

Figure 11. Terminate debugging

Modify the main.c file in order to include a counter variable in the infinite while loop, and add a breakpoint
as in the Figure below:

Figure 12. Counter variable

Start debugging again.


Double click on the “ctr” variable. Left click it, and Add Watch Expression
Figure 13. Add to watch

You should now debug the program, and as you run it with F8, you should see the value of the ctr
expression increasing, in the Expressions tab.

Figure 14. Watch variable

You can also inspect special function registers and how their values change between executions of code
lines.

Figure 15. GPIOA SFR before init


Figure 16. GPIOA SFR after init

More information on how the actual debugging takes place:


https://en.wikipedia.org/wiki/In-circuit_emulation
The reason why we have debugging capabilities on this board without having to hook up an external
debugger to it is that it already implements the necessary circuitry for debugging.

Figure 17. Board Manual, document UM1724 of STMicroelectronics


4. Reporting
1. What is the reason for calling the function on line 16 in main.c?
2. What happens if the type qualifier volatile is removed from line 24 when defining the variable?
a. Change Project -> Properties -> C/C++ build -> Settings -> click “Tool Settings Tab”, MCU GCC
Compiler -> optimization, choose “Optimization level” to “–O3”. What is the effect of volatile
now?
3. Write different code to achieve the same behavior of toggling the LED? (HINT: consult HAL description
document GPIO chapter 29, page 405)?
5. Appendix: STM32IDE installation
Select all of the components to install

At this step, choose “Install”

You might also like