Skip to content

How To Build On VST104

Selman Özleyen edited this page Apr 22, 2021 · 1 revision

How To Create This Project For Your Stm32 MCU

Generating the C code.

  • Start a stm32 project (for example stm32 cube ide).
  • Select your device.

You must configure the following;

  • FreeRTOS with CMSIS v2 interface.
  • a seperate FreeRTOS task defined externally.
  • UART to communicate with Prust.
  • Other peripherals you want to use.
  • Configure timers

As an example for VST104 board I used Stm32CubeIde and did the following;

  • Select stm32l496zg as mcu.
  • Set async UART5
  • From Middlewares > Interface > CMSIS_V2
  • From the same page select Tasks and Queues and create a task called prustMain
  • Set the task code generation output as external.
  • Gave the highest priority.
  • Since FreeRTOS uses SysTick used TIM6 for Sys mode.
  • PC9 as GpioOutput labeled as USER1_EN
  • PG15 as GpioOutput labeled as USER3_EN
  • PG12 as GpioOutput labeled as USER4_EN
  • PF13 as GpioOutput labeled as USER1_1
  • PF15 as GpioOutput labeled as USER1_2
  • PF12 as GpioOutput labeled as USER3_1
  • PC5 as GpioAnalog and ADC1 in15 as USER4_4

All details about the configurations can be found on the *.ioc file but this is the general idea. When you try to build it it should not build because we have not defined the external function for the task named prustMain.

Rust Lib
Now we will switch to Rust as our OS will do when working, context switching between rust binary to c binary without knowing. You will need rust nightly. You can set it with rustup default nightly command.

You can clone Prust-RTOS and change src/hal module and adapt it to your device and requirements. But this is a summary of what I did.

  • Created an staticlib crate.
  • Don't forget adding ![no_std].
  • Wrote an entry function.
  • Provided a global allocator by wrapping FreeRTOS malloc/free functions
  • Provided OOM and PanicHandler functions. Used cbindgen tool to autogenerate a c header file for prust in build directory by writing a build.rs file. After compiling the crate you will get a file like libprust_rtos.a. You should create a prust_rtos.h file in the same directory.

Linking

Given that you can successfully compile a no_std staticlib with an external declared entry function and you have libprust_rtos.a file and prust_rtos.h file in the build directory, you can now link you binary files.

This is how I did it on STM32CubeIDE: Go to project properties -> c/c++ build -> settings -> MCU G++ linker -> Libraries.
As -L parameter add the directory where *.a file is created as the -l parameter add prust_rtos if you file name libprust_rtos.a, so x for libx.

Link the rust file. Check out the IDE's link setting and link the rust staticlib.
You can see more on here about external functions.

Note: So the external declared prust_main function is defined in Rust code. The C code shouldn't compile without prust_main being defined in Rust.

Run

You can simply run it with the run or debug buttons from the IDE.

Clone this wiki locally