rusefi_documentation/Developing-On-Linux.md

99 lines
3.4 KiB
Markdown
Raw Permalink Normal View History

2022-01-25 17:01:06 -08:00
# Developing On Linux
## Compiling
2021-11-19 11:02:18 -08:00
2022-01-24 14:57:52 -08:00
Download the latest ARM GCC from ARM itself: [ARM GCC toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
2021-11-19 11:02:18 -08:00
These can be extracted under your home directory; just add the `bin` directory to your path.
There is also a script that you can run to install the above and also other prerequisites for Ubuntu or Debian:
```shell
./setup_linux_environment.sh
```
2021-11-19 11:02:18 -08:00
2021-11-19 12:01:04 -08:00
Then to compile the firmware,
2023-01-02 11:22:23 -08:00
```shell
./firmware/bin/compile.sh
```
It will give you a list of boards to choose from.
You can also pass it the path to a meta-info file to build for that board instead of being prompted:
```shell
./firmware/bin/compile.sh config/boards/microrusefi/meta-info-mre_f4.env
```
You can also pass it `-b` as the first parameter to build bundle .zip files.
```shell
./firmware/bin/compile.sh -b config/boards/microrusefi/meta-info-mre_f4.env
2021-11-19 12:01:04 -08:00
```
2023-01-02 11:22:23 -08:00
The .zip bundles will be located at ./artifacts.
2021-11-19 12:01:04 -08:00
To compile the simulator,
2023-01-02 11:22:23 -08:00
```shell
2021-11-19 12:01:04 -08:00
cd simulator
make -j$(nproc)
2021-11-19 12:01:04 -08:00
```
To compile the unit tests,
2023-01-02 11:22:23 -08:00
```shell
2021-11-19 12:01:04 -08:00
cd unit_tests
make -j$(nproc)
2021-11-19 12:01:04 -08:00
```
## Working with STM32 Dev/Nucleo boards
2021-11-19 11:46:14 -08:00
These boards are convenient as they include an ST-Link onboard which aids debugging. I believe the main difference is a Development board includes a bunch of peripherals that you may or may not care about, while a Nucleo board is much more stripped down. Some (all?) boards will be powered when you connect to the ST-Link USB board. The ST-Link will include, among other things, a virtual com port, which can be used to run either the console or TunerStudio. However, by default the ports are not accessible by regular users. You can solve this with:
```shell
2021-11-19 11:46:14 -08:00
sudo chmod 666 /dev/ttyACM*
```
Adapt as necessary depending on the permissions you choose to expose.
## Working with OpenOCD
2021-11-19 11:02:18 -08:00
Depending on how new your dev board is, you may need to upgrade OpenOCD. For example, a nucleo-h743 requires OpenOCD 0.11+. Luckily you can download and run the latest version from your local home directory. Unofficial binaries are available here:
2022-01-24 14:57:52 -08:00
[OpenOCD-Xpack releases](https://github.com/xpack-dev-tools/openocd-xpack/releases)
2021-11-19 11:02:18 -08:00
To get started, plug the ST-Link side of the dev board into your computer. Generally this should power the whole board.
2021-11-19 15:13:01 -08:00
OpenOCD can be left running in the background while you develop in other windows. It will provide a GDB server, a telnet connection for issuing commands, and a TCL interface. We'll just ignore the last one for now. To start OpenOCD, you need to pass in a board configuration file. Luckily they exist for most any off the shelf board you care about.
```shell
2021-11-19 15:13:01 -08:00
sudo ~/openocd/xpack-openocd-0.11.0-2/bin/openocd -f ~/openocd/xpack-openocd-0.11.0-2/scripts/board/st_nucleo_h743zi.cfg
```
2023-01-02 11:22:23 -08:00
2021-11-19 15:13:01 -08:00
Adjust as necessary; you may need `sudo` if you don't normally have access to USB devices.
2021-11-19 11:02:18 -08:00
To reprogram, simply do:
2023-01-02 11:22:23 -08:00
```shell
2021-11-19 11:02:18 -08:00
telnet localhost 4444
2021-11-19 14:24:39 -08:00
program build/rusefi.elf reset
2021-11-19 11:02:18 -08:00
exit
```
2023-01-02 11:22:23 -08:00
2021-11-19 15:13:01 -08:00
Or, if you prefer a one-liner:
2023-01-02 11:22:23 -08:00
```shell
2021-11-19 15:13:01 -08:00
(echo "program build/rusefi.elf reset"; echo exit) | nc localhost 4444
```
2023-01-02 11:22:23 -08:00
2021-11-19 11:49:35 -08:00
Conveniently, OpenOCD will retain a history of commands, allowing you to use up-arrows to retrieve previous commands.
2021-11-19 11:02:18 -08:00
On a nucleo-h743, I don't seem to get much indication this worked, but if you connect via gdb:
2023-01-02 11:22:23 -08:00
```shell
2021-11-19 11:02:18 -08:00
gdb build/rusefi.elf
target remote :3333
```
2023-01-02 11:22:23 -08:00
2021-11-19 11:02:18 -08:00
then you might end up in the middle of the ChibiOS idle function, a good indication you've succeeded.