Linux - flashing
Follow this guide to flash firmware to your board on Linux.
Last updated
Follow this guide to flash firmware to your board on Linux.
Last updated
For VM and/or WSL users the USB functionalities might not work properly. For WSL user consult the WSL page for instructions on how to set up the USB ports.
First things first, we need to get the software that allows us to use the J-Link debugger. Below is the link to the install page. Choose the download corresponding to your system.
Just execute the downloaded file and an installer will open. Once you have finished installing go to the next step.
The image bellow shows the J-Link debugger used to connect to your PC. Connect the USB connection to your PC and the 7-pin JST GH is connected to the "DEBUG" port in your FMUK66. You will also need to connect a micro-USB cable to the FMU to power it.
Then you can connect both the USB cables displayed below to your computer. The connection should look a bit like the photo below:
Now open a terminal window and type the following:
You should get this output:
Once that is done you can connect your debugger by typing:
This is the output you should get:
The next step is to specify the target device. Follow the table below for the target device identifier needed for your specific board. In our case we are using the board FMUK66 with device name MK66FN2M0XXX18
.
Board Name | Device / Core |
RDDRONE-FMUK66 (HoverGames FMU) | MK66FN2M0XXX18 |
UCANS32K146 | S32K146 |
RDDRONE-BMS772 | S32K144 |
8MMNavQ | ??? |
On Linux, you enter this by hand. But you can also copy the device name above and paste it into the terminal by pressing Ctrl+Shift+V
. The selected device will be remembered in next sessions, meaning you can just press enter to select the saved default.
If you're using a J-Link debugger, enter s
to select SWD as the target interface.
For the speed entry, reference the table below to select the correct target interface speed for the board you are flashing. In our case it is 4000
.
Board Name | Target Device Speed (kHz) |
RDDRONE-FMUK66 | 4000 |
UCANS32K146 | 1000 |
RDDRONE-BMS772 | 1000 |
The J-Link will then connect to the target. You will get a pop up to accept the Term of Use. Accept those terms to continue. You should see something similar to this after:
Now you will need to download the bootloader. The FMU requires a bootloader to run. You will be able to flash this using the J-Link debugger. Please download the file from the Downloads page. Make sure to remember the location of this file.
To flash a .bin file, the general format of loadbin
is as follows:
The path to the binary file is an absolute path, and the target memory address is a hexadecimal address.
When your path includes a whitespace, you will need quotation marks around you path, like so:
loadbin "/another path/to/file.bin" 0x0
Depending on the size of the binary, it might take a while to flash. The console will show the different steps. It will first check the contents of the binary and match it against the contents of the memory on the board. If they are equal, the binary doesn't have to be flashed. Otherwise, the old contents of the memory are first erased. Then the contents of the binary are programmed into the memory, and finally it is verified that it was done correctly.
That is everything. You may need to press reset on the board, or power cycle for the new code to start running on your board.
To know what other commands the J-Link can accept you can type ?
to get a help list of commands that J-Link accepts.
Now with the bootloader set up we can start flashing the firmware to the board. This process is very similar to the previous step with the bootloader. The biggest difference is that the location of the firmware file is in a different place and the target memory address is different.
The file should be located at the location similar to this one:
Now that you know where the location of the file is we can continue. Do the same steps as the bootloader:
Go to the Terminal and write:
JLinkExe
connect
MK66FN2M0XXX18
or "Enter"
S
4000
Now this part is different:
loadbin </path/to/firmware/file.bin> 0x6000
The path for the firmware is the one mentioned in the beginning of the chapter.
It is very important that you get the correct offsets (0x0
, 0x6000
), as the bootloader uses these to find the firmware on your FMU's flash chip.
Once you have finished flashing your board, you can press the RESET button on the side of the FMU to reboot it. It will now be running PX4-Autopilot!
With all the flashing setup we can uplaod example codes to the board. To do so first, use the following code to go to the PX4 directory (this should be done in your WSL):
Once in the correct directory, write the make command bellow:
You have just compiled the file and made it ready to upload. To upload these files, run the following command:
It might take a while and you will get a prompt to unplug and plug back is your USB. Follow those instructions until there is a progress bar uploading your files. Once finished your code will be uploaded and ready to be tested.