Embedded system development @ BNU-HKBU UIC RoboMaster
You can follow the instructions below to set up the necessary environments for building the source code and flashing the embedded chips.
Install ARM Toolchain (manual)
-
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/yry0008/gcc-arm-none-eabi-10.3-2021.10/bin. -
For Windows users, add the following line (replace
<path>with the actual binary path found in step 3) toPATHenvironment variable.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
Install OpenOCD (manual)
-
Go to the official download page for OpenOCD.
-
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/yry0008/openocd-0.11.0-2021.10/bin. -
For Windows users, add the following line (replace
<path>with the actual binary path found in step 3) toPATHenvironment variable. 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
Install CMake
- Go to the official download page for CMake.
If you are using Clion, this step is not required.
Install Ninja (Windows only)
- Go to the official download page
With CLion (Recommended)
You can directly open the project in CLion and build it. You need to set the path of the embedded toolchain in the CLion settings.
In Windows, you should open `Settings`, `Build, Execution, Deployment`, `CMake`, then set the `Generator` to Ninja.
Compile manually
-
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
In Windows, you should add the option to let cmake use ninja to build.
cmake -DCMAKE_BUILD_TYPE=Release ... -G "Ninja"Using ninja to build.
ninja -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.
Flash using CLion
Choose the target you want to flash and click the Run button.
The default configuration is for CMSIS-DAP debugger. If you are using ST-LINK, you need to change the configuration in the CLion settings.
Flash using OpenOCD TODO
You will need Doxygen.
- For Mac users,
brew install doxygencould be a shortcut. - For Ubuntu users,
sudo apt install doxygencould be a shortcut. - For Arch users,
sudo pacman -S doxygencould be a shortcut. - For Linux users, either use prebuilt binaries, or build from source following their compile manual.
To generate documentations after compiling the project.
- Run
make docin thebuild/directory - In windows, you need to run
ninja docin thebuild/directory
To view the generated document:
- Run
firefox docs/html/index.html, or - Open
docs/html/index.htmlin your browser.
Use the following guide when making contributions to this repo.
You can use any editor you like, but we recommend using CLion.
The continuous integration system will check the source code against a specific coding style. If the code does not follow the style, the formatting check will fail and the code will not be merged. 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 18. (otherwise CMake will not create the format target)
-
For Linux users:
-
Recommend
sudo apt install clang-format-18 -
LLVM released packages(fallback) x86_64 (most common) aarch64 (ARM64) Install by:
tar -xf clang+llvm-18.1.8-*.tar.xz export PATH=$PWD/clang+llvm-18.1.8/bin:$PATH
-
-
For Mac users:
-
x86_64 (Intel Mac) x86_64 (Apple Silicon) Install by:
tar -xf clang+llvm-18.1.8-*.tar.xz export PATH=$PWD/clang+llvm-18.1.8/bin:$PATH
-
-
For Windows users:
- Official Installer which files are going to locate
C:\Program Files\LLVM\bin\clang-format.exeafter installation.
- Official Installer which files are going to locate
Format using CLion
Choose the CMake target and compile it. CLion will automatically format the code for you.
check-format: Checkdiffbetween current source and formatted source (without modifying any source file)format: Format all source files (Modifies file in place)
Format manually
You can run the following commands inside build/ to 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 in place)
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.
Clion Debugger
This is the easiest way to debug. Choose the target and Directly click the Debug button in CLion.
OpenOCD
Thought directly using openocd is possible, but it is only recommended for advanced users.
The main branch is protected. You need to create a new branch and make a pull request to merge your changes. You need to pass the CI check (formatting check and build check) before merging.
You should write a meaningful commit message like
feat: add a new module to control the gimbal.
The type must be one of the following:
- feat for a new feature for the user, not a new feature for build script.
- fix for a bug fix for the user, not a fix to a build script.
- perf for performance improvements.
- docs for changes to the documentation.
- style for formatting changes, missing semicolons, etc.
- refactor for refactoring production code, e.g. renaming a variable.
- test for adding missing tests, refactoring tests; no production code change.
- build for updating build configuration, development tools or other changes irrelevant to the user.