Embedded system development @ Illini RoboMaster
You can follow the instructions below to setup the necessary environments for building the source code and flashing the embedded chips.
-
Go to the official download page for ARM Toolchain.
-
Download the pre-built toolchain according to your operating system.
-
Decompress it to some directory and find an absolute path to the
bindirectory.In my case:
/Users/alvin/gcc-arm-none-eabi-9-2020-q2-update/bin. -
For Linux / Mac users, add the following line (replace
<path>with the actual binary path found in step 3) to~/.bashrcfor bash users or~/.zshrcfor zsh users.export PATH=<path>:$PATH
-
Go to your project root directory in a terminal.
-
Run the following command to build the entire project.
mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release .. make -j
Change build type to
DebugorRelWithDebInfoin order to debug withgdb. Note thatDebugbuild could be much slower than the other two due to lack of compiler optimizations.
-
Install stlink.
- For Mac users,
brew install stlinkcould be a shortcut. - For Linux users, either use prebuilt binaries, or build from source following their compile manual.
- For Mac users,
-
Flash one of the example programs by running
make flash-<xxx>in thebuild/directory created at compilation.e.g.
make flash-example_buzzer-> and you shall hear some music (or noise)
Use the following guide when making contributions to this repo.
The continuous integration system will check the source code against Google C++ Style Guide. All codes are required to be formatted correctly before merging. There are several integrated build commands that can help you automatically format your changes.
Prerequisite: install clang-format (version 10 recommended)
- Windows users will need WSL and can follow the steps for Linux
- Linux users can simpliy install it using
sudo apt install clang-format-10. - Mac users need to download prebuilt binraies from here. For now, we CANNOT use version 11 or above.
With clang-format installed, you can run the following commands inside build
to automatically format your changes.
make check-format: Checkdiffbetween current source and formatted source (without modifying any source file)make format: Format all source files (Modifies file inplace)
To debug embedded systems on a host machine, we would need a remote gdb server. There are 2 choices for such server, with tradeoffs of their own.
-
st-utilThis tool comes with stlink, but be aware that this is a thirdparty implementation and is not stable. The most recent release tested to be working is
v1.5.1. -
OpenOCDThis tool is much more stable but is slightly less intelligent in detecting ST-LINK version and it has not been updated since 2017. To install it,
brew install openocdfor Mac userssudo apt install openocdfor Linux (Ubuntu) users
Follow the steps below to debug an executable
- Launch a
gdbserver by either choicest-utilopenocd -f <project root>/debug/OpenOCD/st-link-v2-1.cfg
- In a seperate terminal,
cdinto thebuilddirectory and runmake debug-xxx(e.g.make debug-example_buzzer). This will open up agdbsession. - Run
target extended-remote :<port>(ortar ext :<port>in short ) to connect to thegdbserver.- For
st-util, replace<port>with4242. - For
openocd, replace<port>with3333.
- For
- Run
loadto flash the executable (Note that you can also runmakehere without exitinggdbto re-build the executable if you modified some source code). - Debug just like any regular
gdbdebugger: use commands likecontinue,run,break,watch,next,stepthe same way you will expect.