How to use state machines generated by Sinelabore with the CubeMX tool from STM

This example shows how easy it is to add statemachines to STM32 CubeMX projects.

The example was created for the STM32F103C8T, for which very cheap eval boards are available.

The graphic shows the typical development flow for a CubeMX project and where the Sinelabore State Machine Generator comes into play.

Example project generated with the CubeMX and Sinelabore

In the example, CMSIS RTOS API is used with 2 tasks, a message queue and a timer. The state machine runs in Task02 and receives its events from the timer callback function cyclicTimer0Callback. And also from the default task. The state machine is kept simple and generates a blinking pattern that is terminated after some time by a FailSafe event.

The Statemachine was created with the integrated Statediagram Editor. To modify the machine, start the editor, load the model and regenerate the code after your changes.

Follow the steps below to create the example itself. It is assumed that you have installed the GNU Arm compiler tools and a debug interface. Links to the tools you need can be found below.

Download the demo project zip and unzip it

Create a project folder

Copy the project file to your project folder and load the project with the CubeMX programme.

Generate the complete project code from it into the project folder.

Replace the generated Makefile with the modified Makefile provided in the demo project folder. The modified Makefile contains the state machine C/H path.

Finally replace main.c in the Core/Src folder with the demo version. It contains the application from two tasks.

Now you can call make and flash the created elf file into the board with the debugger.

In one console run the debug stub;

/opt/homebrew/bin/st-util

In another console run the debugger:

/Applications/ARM/bin/arm-none-eabi-gdb

target remote 192.168.6.191:4242

load build/example.elf

file build/example.elf

c

The ARM Tools and CubeMX make it super easy to get started with the STM uC family and the Sinelabore Statemachine Generator completes the toolschain perfectly.

Links

Required project files: stm_tutorial.zip

Blue Pill Development Board: https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html

Docu of the STM32CubeIDE ST-LINK GDB server: https://www.st.com/resource/en/user_manual/um2576-stm32cubeide-stlink-gdb-server-stmicroelectronics.pdf

CMSIS-RTOS2 Docu: https://www.keil.com/pack/doc/CMSIS/RTOS2/html/genRTOS2IF.html

Arm GNU Toolchain Downloads: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads

Open source version of the STMicroelectronics STLINK Tools: https://github.com/stlink-org/stlink