Code Monkey home page Code Monkey logo

boostsml_stm32_hello_world's Introduction

State Machine Library (SML) Hello World on STM32

This is example STM32 C++ project using a boost::sml state machine library.

Boost SML is simple and fast state machine library which can be used in STM32 projects (needs at least c++14). SML is header only library, so you need download end extract library, update include patchs with it and add one include in your cpp code:
#include <boost/sml.hpp>

More info https://boost-ext.github.io/sml/tutorial.html

Program changes a light of onboard LED accordingly to the current state. Project was prepared for the blackpill dev board with STM32F401CCU.

State machine definition

State machine is simple

   stateDiagram-v2
   [*] --> state_led_off
   state_led_off --> state_led_blinking_slow
   state_led_blinking_slow --> state_led_blinking_fast
   state_led_blinking_fast --> state_led_on
   state_led_on --> state_led_off

definition in cpp:

class BlinkingLED {
public:
   auto operator()(){
     return make_transition_table(
       *"state_led_off"_s + event<timer_event> = "state_led_blinking_slow"_s
      , "state_led_blinking_slow"_s + event<timer_event> = "state_led_blinking_fast"_s
      , "state_led_blinking_fast"_s + event<timer_event> / action_led_on = "state_led_on"_s
      , "state_led_on"_s + event<timer_event> / action_led_off = "state_led_off"_s
   );
   }
};

sm<BlinkingLED> state_machine;

Event and actions definitions:

struct timer_event {};

auto action_led_on = [] {
   HAL_GPIO_WritePin(GPIO_LED_GPIO_Port, GPIO_LED_Pin, GPIO_PIN_RESET);
};
auto action_led_off = [] {
   HAL_GPIO_WritePin(GPIO_LED_GPIO_Port, GPIO_LED_Pin, GPIO_PIN_SET);
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.