Skip to content

Flashing code to boards

ChristopherA057 edited this page Feb 11, 2020 · 2 revisions

Things that must be setup prior to following this tutorial: - Must be able to make .bin files on your personal computer using the “make APP=X TARGET=X” command – Refer to 2020 firmware guidelines for more details (link) - Must have an environment for C++ coding, and must be able to include necessary header files which can be found in the 2020 firmware repo • Including necessary header files will vary with IDEs; for example, the process is more tedious on Eclipse than it is on VSCode - Must have the ST-Link Utility installed on your PC (technically can be performed without the utility, but this guide will assume that you’re using it because it’s simple)

Steps: - Coding (using the right inclusions) - Making .bin files - Flashing using nucleo and st-link

Coding: - Before writing any code, it is important to note which board you are programming for, as not all boards use the same MCU; to be more specific, the PinNames.h file you use (can be found in file directory) depends on whether you are coding for the Arm board or not. If you are using the Arm board, please include the PinNames.h file from (directory), and if not, then you can use any other PinNames.h file (list other directories). - As for includes, the most important library which you MUST include is “mbed.h” (can be found in directory) • This file itself runs multiple different include commands, which may or not be taken care of by your IDE; if they are not taken care of automatically (like mine), then manually include the following folders in your project to attain all necessary files (making sure to get the correct target, as that contains the PinNames.h file, which MUST be correct)

  -	If all of these are included successfully, you should be able to compile working code for the boards; to see an example, take a look at the main.cpp files in the (directory), as they demonstrate the code necessary to test buttons and LEDs
  -	Also, make sure to name all code files main.cpp

Making .bin files: - You should know how to run the make command successfully on some of the pre-existing code at this point, so I’m going to trust that you can navigate to wherever the MarsRover2020-firmware repo is located on your computer within your linux subsystem or terminal - Assuming that you don’t want to overwrite code found in one of the pre-existing folders, simply make a new folder in the “apps” directory and call it whatever you want; this will be the APP you make - Now, you can run the make command, making sure to choose the correct target board (for basic purposes such as GPIO testing, this decision really just boils down to ‘arm or not arm’, but you should endeavor to double-check that your pin allocations for everything are correct for the board you’re flashing) - Once the process is complete, you should be able to navigate to the “builds” folder and see a folder named identically to the APP you just made. This folder should house a .bin file which you will be able to flash to the board.

Flashing using the Nucleo and ST-Link: - Before doing anything else on your PC, connect the Nucleo to the board you want to program. Unplug anything connected to the board before starting this process. - Plug the 2x4 pin header into the debug header on the board, making sure to align the blue wire with the CLK pin. Also, you may choose to use 3V3 power, but generally we just use a female-female jumper to connect the 5V out on the Nucleo to the 5V on the power connector on the board. - Connect the Nucleo to your PC using a USB cable. At this point, you should be able to open the ST-Link utility and connect to the board, which you can do by selecting Target at the top of the screen, and hitting Connect. - If no error occurs, you should see a screen (description, pictures) - If an error does occur, check the connections on the Nucleo and the board, and then plug the USB cable into a different slot on your PC, then try again - If you are connected successfully, hit Target again and click Program this time - Select the file and wait (the program should do something) - Program the board - Done

Clone this wiki locally