|
| 1 | +# How to Compile and Flash |
| 2 | + |
| 3 | +## Toolchain |
| 4 | +To compile the project we need a cross-compiler for ARM embedded systems (`arm-none-eabi`). It requires at minimum a version that supports C++17. You should, however, stick to the latest version if possible. |
| 5 | + |
| 6 | +Depending of current Ubuntu version it is not recommended to |
| 7 | +install the toolchain via apt from the Ubuntu archives or a PPA, as these sources usually provide very outdated versions. |
| 8 | +In that case it is better to download and install the toolchain manually: |
| 9 | + |
| 10 | +1. Goto the [download site](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) and download the `arm-none-eabi` tarball for Linux hosts (for e.g. `arm-gnu-toolchain-x.x.x-x86_64-arm-none-eabi.tar.xz`) |
| 11 | +2. Extract the files to the target install directory of your choice, e.g. by `~/toolchains/` |
| 12 | +3. Create symbolic links in `/usr/bin` to make our toolchain callable system wide by using the following command: `sudo ln -s ~/toolchains/[your arm-none-eabi toolchain]/bin/arm-none-eabi-* /usr/bin` |
| 13 | +4. Verify the output of `arm-none-eabi-gcc --version` |
| 14 | + |
| 15 | +## Cmake |
| 16 | + |
| 17 | +Without IDE the simplest approach to generate cmake files in `build` directory is to use this command in root of project: |
| 18 | + |
| 19 | +``` |
| 20 | +cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/arm-none-eabi-gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/arm-none-eabi-g++ -B build |
| 21 | +``` |
| 22 | +Then go into the build directory and now you can compile with `make`. |
| 23 | + |
| 24 | +## VS Code |
| 25 | +Using an IDE will make your life easier. In this case the setup in VS Code will described here. |
| 26 | + |
| 27 | +0. Install VS Code of course. (e.g. `sudo snap install code --classic`) |
| 28 | +1. Install those extensions in VS Code: |
| 29 | + * CMake |
| 30 | + * CMake Tools |
| 31 | + * Cortex-Debug |
| 32 | + |
| 33 | +2. Open the project directory `File > Open Folder...` |
| 34 | +3. Select kit with currently used toolchain. This should prompted by opening a list from top. If not you can select the kit in the bottom bar where `Not kit selected` is labeled. |
| 35 | +4. Then you can hit the `Build` button in the bottom bar to compile. |
| 36 | + |
| 37 | +## Flash |
| 38 | + |
| 39 | +It is recommend to do flashing with VS Code because it is simply and you can attach/debug to the running firmware after flashing. |
| 40 | + |
| 41 | +For flashing we use J-Link debugger from Segger like [J-Link EDU Mini](https://www.segger.com/products/debug-probes/j-link/models/j-link-edu-mini/). |
| 42 | +So at first we need to [download](https://www.segger.com/downloads/jlink/) the software from Segger for our J-Link. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +After we install J-Link software, compile the project and connect the target: |
| 47 | + |
| 48 | +1. go to Tab `Run and debug` on left |
| 49 | +2. at the top right beside the play button you can select the debug profile. Select `Debug (J-Link, RTOS-aware)`. This ensures you target will be flashed with new firmware and after that you can debug with aware-ness of RTOS (like showing tasks list). |
| 50 | +3. Hit F5 or press the play button |
| 51 | + |
| 52 | +You firmware is flashed! |
| 53 | + |
| 54 | +Note: If you want only attach to the running firmware without resetting them, select the debug profile `Attach (J-Link, RTOS-aware)`. |
0 commit comments