UPDATE: See the updated firmware in sdk_app_rust_gpio
This BL602 firmware shows how we may create Rust firmware with the BL602 IoT SDK. Read the article...
Rust source code for the BL602 firmware is here...
Run this script to build, flash and run the BL602 Rust firmware...
This script links the compiled Rust code into the BL602 firmware by overwriting the compiled rust_app
Stub Library...
The script uses a Custom Rust Target riscv32imacf-unknown-none-elf
...
This Custom Rust Target is a minor tweak of the standard Rust target riscv32imac-unknown-none-elf
...
-
We set
features
to+m,+a,+c,+f
to generate RISC-V binaries with Single-Precision Hardware Floating-Point (+f
) -
We set
llvm-abiname
toilp32f
to support Single-Precision Hardware Floating-Point for the Application Binary Interface
We can't use the standard target riscv32imac-unknown-none-elf
because...
-
BL602 IoT SDK was compiled with
gcc -march=rv32imfc -mabi=ilp32f
(Single-Precision Hardware Floating-Point)
-
Linker fails with error
can't link soft-float modules with single-float modules
How did we figure out the tweaks for the Custom Rust Target?
By comparing the Rust Target Specs for riscv32imac-unknown-none-elf
vs riscv64gc-unknown-none-elf
...
-
riscv32imac-unknown-none-elf.json
: 32-bit RISC-V with software floating pointGenerated by...
rustc +nightly -Z unstable-options --print target-spec-json --target riscv32imac-unknown-none-elf
-
riscv64gc-unknown-none-elf.json
: 64-bit RISC-V with double-precision hardware floating pointGenerated by...
rustc +nightly -Z unstable-options --print target-spec-json --target riscv64gc-unknown-none-elf
Read the Twitter Thread...
https://twitter.com/MisterTechBlog/status/1383219945308184578