2024-05-19 21:50:29 +02:00
|
|
|
sat-rs example for the STM32F3-Discovery board
|
|
|
|
=======
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
This example application shows how the [sat-rs framework](https://egit.irs.uni-stuttgart.de/rust/satrs-launchpad)
|
|
|
|
can be used on an embedded target.
|
|
|
|
It also shows how a relatively simple OBSW could be built when no standard runtime is available.
|
|
|
|
It uses [RTIC](https://rtic.rs/2/book/en/) as the concurrency framework and the
|
|
|
|
[defmt](https://defmt.ferrous-systems.com/) framework for logging.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
The STM32H743ZIT device was picked because it is one of the more powerful Cortex-M based devices
|
|
|
|
available for STM with which also has a little bit more RAM available and also allows commanding
|
|
|
|
via TCP/IP.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
## Pre-Requisites
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
Make sure the following tools are installed:
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
1. [`probe-rs`](https://probe.rs/): Application used to flash and debug the MCU.
|
|
|
|
2. Optional and recommended: [VS Code](https://code.visualstudio.com/) with
|
|
|
|
[probe-rs plugin](https://marketplace.visualstudio.com/items?itemName=probe-rs.probe-rs-debugger)
|
|
|
|
for debugging.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
## Preparing Rust and the repository
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
Building an application requires the `thumbv7em-none-eabihf` cross-compiler toolchain.
|
|
|
|
If you have not installed it yet, you can do so with
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
```sh
|
|
|
|
rustup target add thumbv7em-none-eabihf
|
2024-05-19 21:44:09 +02:00
|
|
|
```
|
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
A default `.cargo` config file is provided for this project, but needs to be copied to have
|
|
|
|
the correct name. This is so that the config file can be updated or edited for custom needs
|
|
|
|
without being tracked by git.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
```sh
|
|
|
|
cp def_config.toml config.toml
|
2024-05-19 21:44:09 +02:00
|
|
|
```
|
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
The configuration file will also set the target so it does not always have to be specified with
|
|
|
|
the `--target` argument.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
## Building
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
After that, assuming that you have a `.cargo/config.toml` setting the correct build target,
|
|
|
|
you can simply build the application with
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
```sh
|
|
|
|
cargo build
|
2024-05-19 21:44:09 +02:00
|
|
|
```
|
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
## Flashing from the command line
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
You can flash the application from the command line using `probe-rs`:
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
```sh
|
|
|
|
probe-rs run --chip STM32H743ZITx
|
2024-05-19 21:44:09 +02:00
|
|
|
```
|
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
## Debugging with VS Code
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
The STM32F3-Discovery comes with an on-board ST-Link so all that is required to flash and debug
|
|
|
|
the board is a Mini-USB cable. The code in this repository was debugged using [`probe-rs`](https://probe.rs/docs/tools/debuggerA)
|
|
|
|
and the VS Code [`probe-rs` plugin](https://marketplace.visualstudio.com/items?itemName=probe-rs.probe-rs-debugger).
|
|
|
|
Make sure to install this plugin first.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
Sample configuration files are provided inside the `vscode` folder.
|
|
|
|
Use `cp vscode .vscode -r` to use them for your project.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
Some sample configuration files for VS Code were provided as well. You can simply use `Run` and `Debug`
|
|
|
|
to automatically rebuild and flash your application.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
The `tasks.json` and `launch.json` files are generic and you can use them immediately by opening
|
|
|
|
the folder in VS code or adding it to a workspace.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
## Commanding with Python
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
When the SW is running on the Discovery board, you can command the MCU via a serial interface,
|
|
|
|
using COBS encoded PUS packets.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
It is recommended to use a virtual environment to do this. To set up one in the command line,
|
|
|
|
you can use `python3 -m venv venv` on Unix systems or `py -m venv venv` on Windows systems.
|
|
|
|
After doing this, you can check the [venv tutorial](https://docs.python.org/3/tutorial/venv.html)
|
|
|
|
on how to activate the environment and then use the following command to install the required
|
|
|
|
dependency:
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
```sh
|
|
|
|
pip install -r requirements.txt
|
2024-05-19 21:44:09 +02:00
|
|
|
```
|
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
The packets are exchanged using a dedicated serial interface. You can use any generic USB-to-UART
|
|
|
|
converter device with the TX pin connected to the PA3 pin and the RX pin connected to the PA2 pin.
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
A default configuration file for the python application is provided and can be used by running
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
```sh
|
|
|
|
cp def_tmtc_conf.json tmtc_conf.json
|
2024-05-19 21:44:09 +02:00
|
|
|
```
|
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
After that, you can for example send a ping to the MCU using the following command
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
```sh
|
|
|
|
./main.py -p /ping
|
2024-05-19 21:44:09 +02:00
|
|
|
```
|
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
You can configure the blinky frequency using
|
2024-05-19 21:44:09 +02:00
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
```sh
|
|
|
|
./main.py -p /change_blink_freq
|
2024-05-19 21:44:09 +02:00
|
|
|
```
|
|
|
|
|
2024-05-19 21:50:29 +02:00
|
|
|
All these commands will package a PUS telecommand which will be sent to the MCU using the COBS
|
|
|
|
format as the packet framing format.
|