This takes the build process and most of the structures from https://github.com/sabaton-systems/threadx-rust/ and builds a ThreadX + NetX variant. Compared to the original we did:
- Fix some UB
- Generate NetX bindings
- Implement simple async executor based on https://github.com/zesterer/pollster
- Implement embedded-nal interface for NetX/Wiced Wifi
- Async interface for buttons
All steps below are for Linux.
sudo apt update
sudo apt upgrade
sudo apt install gcc-arm-none-eabi
sudo apt install build-essential
sudo apt install pkgconf
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Close your Linux shell and open it again to update environment variables.
-
flip-link:
cargo install flip-link
-
Rust target (for MXAZ3166):
rustup target add thumbv7m-none-eabi rustup target add thumbv7em-none-eabihf
-
Other dependencies:
sudo apt install ninja-build libclang-dev cmake usbutils
-
Probe-RS to flash the board:
sudo apt-get install libudev-dev cargo install probe-rs-tools
Follow instructions from probe.rs Linux udev rules
The executor.rs
example switches between 2 screens via tha A button and shows either a welcome screen or the actual temperature. It is a demonstration of the async executor based on ThreadX EventFlags.
Goto threadx-app/cross/app
and run:
cargo run --release --target thumbv7em-none-eabihf --bin executor
This example connects to a WiFi Network and to an MQTT5 broker. It subscribes to the vehicle/parameters
topic and implements a cruise control override system - when cruise control is enabled and the user presses the button, it will disable cruise control by publishing the modified vehicle parameters back to the topic.
In the network_raw_mqtt.rs
example adapt the SSID, WLAN-Passwort and the MQTT settings accordingly.
Goto threadx-app/cross/app
and run:
cargo run --release --target thumbv7em-none-eabihf --bin network_raw_mqtt
This examples connects to a WiFi Network and to an MQTT5 broker and regularly publishes the current temperature as uMessage (see: Link to uProtocol).
In the network.rs
example adapt the SSID, WLAN-Passwort and the MQTT settings accordingly.
Goto threadx-app/cross/app
and run:
cargo run --release --target thumbv7em-none-eabihf --bin network
- Only supports the MXAZ3166 board!
- No production ready error handling
- General structure needs to be improved
- Some more abstractions see embassy
- Only a single socket can be used
- As for now the implementation is unsound as there are no checks to assure that buffers are big enough to hold incoming packets
- 32 parallel async tasks are supported
- Simple executor which blocks the thread it runs on
Control structures should be checked if they are moveable ie. can be copied via a simple memcopy. Often this is not explicitely documented within the ThreadX documentation hence we should assume that they cannot be moved. There are at least 2 obvious solutions:
- Make the control structures static and limit to a fixed number of for example mutexes
- Use the "std library" approach ie. pin box the control structure
Veecle and embassy use statically allocated tasks via the type-impl-in-trait nightly feature. Maybe we should do the same to avoid dynamic allocation and the global allocator.