Once your environment has been set up and you have some code to run, you need to compile it and push it to the device. As with nearly everything else, this is more complicated for embedded development than other types of software development, so this page aims to explain the process. Although there are a couple of different methods of accomplishing this, each method has the same three goals: compiling a binary, flashing the microcontroller (uC), and handling I/O.
Build instructions can be found in 'EVT-core/README.md'. Instructions are mostly duplicated here
Navigate to EVT-core directory
Run the following commands
mkdir build/
cd build/
cmake -DEVT_CORE_LOG_ENABLE=1 -DTARGET_DEV=STM32F302x8 ../
make -j8
Above commands create build directory, set up cmake build project, then actually compile the code
When building EVT-core in this manner all samples code is compiled.
EVT_CORE_LOG_ENABLE is used to toggle logger functionality.
TARGET_DEV is used to specify what STM32 chip is being compiled for.
Example is for an EVT-core sample, but the procedure is the same for any compiled EVT code
Connect the STM Nucleo board via Mini-USB to your PC
Device should be visible as a removable media device. On my PC the mount path is '/media/<username>/NODE_F302R8'
If it's not, you can manually mount with sudo mount /dev/<device name> <wherever you want to mount it>
To find the device name, use lsblk , it's typically sda and does not contain any partitions
MAKE SURE YOU SELECT THE CORRECT ONE OR YOU COULD CORRUPT A DRIVE
Copy compiled bin file to nucleo board
Example for blink sample
cp <EVT-core dirctory>/build/samples/blink/blink.bin /media/<username>/NODE_F302R8
may need sudo
Note: If debugging with UART I would recommend using gtkterm.
In the top right there should be a drop down menu with build configurations
Click the drop-down
Select Edit Configurations
In the opened window click the '+' in the top left to add a new configuration
Select 'OpenOCD Download & Run' for the template
Set the Desired Name
Select the sample target and executable (example: 'blink')
Click 'Assist...' button next to board config file
Select st_nucleo_f3.cfg from list
Other settings should work as default
Click OK
Select the new config from the dropdown menu
Click the Play button to build and program the connected ST Nucleo board.
Complete the Steps outlined above in 'Building and Programming in Clion'
Add a breakpoint in the code
Click to the left of a line of code
Click the Bug Icon next to the desired build configuration
Clion will automatically connect GDB to the server run on the nucleo device and pause on your breakpoints
If you get a timeout waiting for target to reset issue editing the 'reset_config' line in the board configuration file to
reset_config none separate
Navigate the debugger as desired. See tutorial here: https://www.jetbrains.com/help/clion/debugging-code.html
View variables in right menu with access to full memory view
Click arrows in top row to navigate code execution (Step Over, Step Into, ...)
(Optional) Load SVD file to view peripheral status of STM board.
Download svd files by cloning repo at https://github.com/posborne/cmsis-svd
While debugging within Clion select the peripherals tab
Choose SVD file at <path to cmsis-svd repo>/data/STMicro/STM32F446.svd (for example. actual file may differ)
Specify compilation flags in File -> Settings -> Build, Execution, Deployment -> CMake -> CMake options
EVT_CORE_LOG_ENABLE is used to toggle logger functionality (1 for on, 0 for off).
Ex: -DEVT_CORE_LOG_ENABLE=1 to enable
TARGET_DEV is used to specify what STM32 chip is being compiled for.
Ex: -DTARGET_DEV=STM32F302x8 for F302s
Select the executable you would like to build from the dropdown in the top right
Click the green hammer next to the dropdown to run the build
If the build is successful, there should now be a bin file in your build folder
The location of the bin file should mirror the folder structure of the project you're in
For example, in EVT-core, if you build the adc executable, which is in samples/adc, the bin file is found in {build-folder-name}/samples/adc
This location is based on the structure generated by the CMakeLists.txt files, not the actual file structure, so this may not always be true, although it should be if proper organizational standards are followed
Because the Nucleo has an onboard uC for programming the main chip, you can just plug it into your computer via USB and program it directly. Flashing it can be done with the following steps:
Plug the Nucleo into the computer, and open file explorer
Find and select the Nucleo from the list of devices under This PC → Devices and Drives
Copy and paste the .bin file into the Nucleo's files
If the Nucleo is programming correctly, the LED on it should be flashing between green and red
Once this flashing stops, the Nucleo should be running the code given to it
All of EVT's custom PCBs expose a JTAG header, which can be used for a number of different things, including programming the board and communicating via UART. To interface with this header, you will need an ST-LINK and the STM32CubeProgammer, which can be downloaded here. You do unfortunately need to make an account to download the software, but the process is fairly straightforward. Flashing one of these boards can be done with the following steps:
Plug the ST-LINK into the JTAG header and the computer
If the plastic surrounding the JTAG header is damaged, it is easy to misplace the JTAG connector by a single column of pins, so be sure to check this if there are problems connecting to the board
Open the STM32CubeProgrammer
Select the second option from the options at the top of the left side bar, titled "Erasing and Programming"
On the right side, under ST-LINK configuration, select the serial number of the board you are trying to program, refreshing as necessary
In the top right corner, click Connect
At this point, if the connection is successful, it should say "Connected" in the top right corner
Set the file bath to the .bin file you would like to program the board with
Click "Start Programming"
If the ST-LINK is programming correctly, the LED on it should be flashing between green and red
Once this flashing stops, the board should be running the code given to it
Debugging with PuTTY is often the fastest and easiest way to get output from a board. PuTTY interfaces with the COM ports on your computer, which allows it to send and receive data over UART. PuTTY can be set up with the following steps:
Setup.
Install PuTTY
Determine COM number for STM device
Open Windows Device Manager
Right Click Start Icon
Click 'Device Manager'
Expand 'Ports (COM & LPT)' menu
Device should appear as 'USB Serial Device' or something similar
Take a note of the COMx number (ex. COM5)
Launch PuTTY
Select Connection Type 'Serial'
Enter the COMx value in the Serial Line box
Enter Baud Rate in Speed Box (usually 9600)
Testing
Once PuTTY is open, it can be used to send text to and receive text from the board via UART
Any code that calls uart.printf() will write its text here
Any code that calls uart.getc() will read text you input here
While PuTTY is very simple and easy, it has its limitations because it requires the uC to be able to use UART properly, which, depending on the severity of the error, may not be the case. In these cases, we need software that uses SWD instead of UART to communicate. The software we use as a team to do this is called OpenOCD. This can be set up to work in CLion with the following steps:
Setup
Install OpenOCD
Download windows zip from https://github.com/xpack-dev-tools/openocd-xpack/releases
Select the option that is a .zip file. You may need to select "More options" at the bottom.
Extract Contents to desired install location.
Take note of path and try to avoid spaces
Open the extracted folder and move all of the files in the 'openocd' subdirectory up a level.
Setup Path to OpenOCD in Clion IDE
Within Clion Select File → Settings → Build, Execution, Deployment → Embedded Development
Set OpenOCD Location to the path to the openocd.exe located at <OpenOCD install location>\bin\openocd.exe
In the top right there should be a drop down menu with build configurations
Click the drop-down
Select Edit Configurations
In the opened window click the '+' in the top left to add a new configuration
Select 'OpenOCD Download & Run' for the template
Set the Desired Name
Select the sample target and executable (example: 'blink')
Click 'Assist...' button next to board config file
Select st_nucleo_f3.cfg from list
Other settings should work as default
Click OK
Running
Select the new config from the dropdown menu
Click the Play button to build and program the connected ST Nucleo board.
If you have an issue with libusb errors, follow the following steps
Download USB Driver Tool: https://visualgdb.com/UsbDriverTool/
Launch Tool via .exe
Right Click on ST-Link Device
Select Install LibUSB
Debugging
Add a breakpoint in the code
Click to the left of a line of code
Click the Bug Icon next to the desired build configuration
CLion will automatically connect GDB to the server run on the nucleo device and pause on your breakpoints
Navigate the debugger as desired. See tutorial here: https://www.jetbrains.com/help/clion/debugging-code.html
View variables in right menu with access to full memory view
Click arrows in top row to navigate code execution (Step Over, Step Into, ...)
(Optional) Load SVD file to view peripheral status of STM board.
Download svd files by cloning repo at https://github.com/posborne/cmsis-svd
While debugging within CLion select the peripherals tab
Choose SVD file at <path to cmsis-svd repo>/data/STMicro/STM32F446.svd (for example. actual file may differ)