Run docker-compose up -d
, then use docker-compose exec dev bash
to get a shell with all the tools installed.
-
Download STM32CubeMX from st.com: [https://www.st.com/en/development-tools/stm32cubemx.html]
-
Create new STM32CubeMX makefile project with freertos into project dir. Main task needs at least 256 words of stack. For example:
- new project -> select your board
- pinout configuration, in left panel:
- enable freertos
- usart2 -> mode: asyncronous
- tab configuration:
- usart2 -> usart2 global interrupt enabled
- freertos -> task and queues -> set default task stack size to 256
- menu -> project -> settings -> set repo dir, toolchain: Makefile
- menu -> project -> generate code
-
Add to makefile after
all
target:
# libraries
RUST_LIB_NAME = rust_lib
LIBS += -l$(RUST_LIB_NAME)
RUST_LIB_SRC = rust_lib
RUST_LIB_BUILD = $(RUST_LIB_SRC)/target/thumbv7em-none-eabihf/debug
LIBDIR += -L$(RUST_LIB_BUILD)
.PHONY: $(RUST_LIB_BUILD)/lib$(RUST_LIB_NAME).a
$(RUST_LIB_BUILD)/lib$(RUST_LIB_NAME).a:
cd $(RUST_LIB_SRC) && cargo build --target=thumbv7em-none-eabihf
add $(RUST_LIB_BUILD)/lib$(RUST_LIB_NAME).a
dependency to $(BUILD_DIR)/$(TARGET).elf:
add cd $(RUST_LIB_SRC) && cargo clean
to make clean
target
rm -lc
from linker option
- also add
rust_main_task()
call tomain.c/StartDefaultTask()
, GPIO port/pin macro static exports
void rust_main_task();
GPIO_TypeDef* HAL_LD2_GPIO_Port = LD2_GPIO_Port;
uint16_t HAL_LD2_Pin = LD2_Pin;
-
don't forget binpath in makefile (
BINPATH = /usr/bin/
, for example) -
Compile
make
-
Flash uС
./deploy.sh
-
enjoy!
To debug Rust code use
RUST_GDB=arm-none-eabi-gdb rust-gdb <path to .elf file>
For regenerate bindings change CACHE_BINDINGS
in build.rs
to false and do make
.