Skip to content
0:00 / 0:00

#statemachines#uml#qmmodelingtool

#41 State Machines Part-7:Automatic Code Generation

Quantum Leaps, LLC

74K subscribers • 20 videos on Hallway

YouTube
  • Recommended by 1 person: 1 in engineering communities.
  • A classic. People kept recommending it from 2021 to 2025.
  • Presented by Miro Samek, founder of Quantum Leaps
  • Linked in the descriptionQuantumLeaps/modern-embedded-programming-course
  • Made by the vendor. The company whose product it covers made or sponsored it.

Intermediate. Assumes working knowledge.

13K views5 years ago1 recommendation

Systems programmingSoftware designEmbedded systemsDesign patternsSoftware architecture

Miro Samek demonstrates how to use the QM modeling tool to automatically generate C code from hierarchical state machine diagrams.

This lesson continues the subject of STATE MACHINES. Today you will see how automatic code generation works in practice. Graphical modeling and automatic code generation do not seem to be mainstream yet, but they are very much parts of the *modern* approach and I believe they are the future of embedded software development. Downloading and installing QP-bundle with the free QM modeling tool Launching the QM modeling tool & opening model files Viewing state diagrams in QM Adding actions in C to the state machine Adding attributes to the state machine class Adding operations (functions) to the state machine class Logical Design vs. Physical Design Doing Physical Design in QM Adding code directories to the model Adding code files to the model Editing the file content in QM The $declare code generation directive The $define code generation directive Generating code in QM Compiling and running the generated code Why should you bother with modeling and code generation? Effective and ineffective visual representations The UML visual notation The intuitive nature of state diagrams (David Harel's story) Code generation as critical for the success of modeling Concerns about correctness and efficiency of the generated code The real challenges of automatic code generation The problem of "fighting the tool" A quick overview of other modeling tools "Fighting the tool" example of the State Machine Compiler (SMC) Complete code generation in QM Generating code for parts of the model (packages, operations) Generating code for individual states The non-recursive $define1 directive Traceability from the code to model Traceability from the model to code (e.g., debugging the model) Bi-directional traceability between model and code Model differencing and merging Scaling models for big teams External packages Conclusion ------- Resources: Companion web page for this video course: state-machine.com/quickstart GitHub repository for projects for this video course: github.com/QuantumLeaps/modern-embedded-programming-course Transcript of this lesson: state-machine.com/course/lesson41.txt Recommended Reading: "The Pragmatics of Model-Driven Development" by Bran Selic, IEEE Computer Society 2003 (computer.org/software-magazine) PDF (state-machine.com/doc/Selic-Pragmatics.pdf) "Statecharts in the Making: A Personal Account" by David Harel, Communications of the ACM 2010 (wisdom.weizmann.ac.il/~harel/papers/Statecharts.History.CACM…) "Large Scale C++ Software Design" by John Lakos, Addison Wesley Longman, Inc. 1996 ISBN 0-201-63362-0 Music credits: The background music comes from: bensound.com/royalty-free-music/track/straight

Why it's here

1 person recommends this

What people say. Recommended as part of a comprehensive series on implementing state machines in embedded systems.

u/active-objectin r/embedded • Recommends

On “Do you use HSM (Hierarcical State Machines)?”

Yes, I've been using and advocating HSMs for the past 20 years. I've found them to be very useful in even the smallest embedded MCUs (e.g., see my article "UML Statecharts at $10.99") Regarding the overhead of ENTRY, EXIT, INIT, etc. it can be small, but you need the right HSM implementation in C or C++. (The boost::sml suggested in the other comment is NOT the right implementation for deeply embedded systems, like ARM Cortex-M MCUs). Here, I would recommend my YouTube video "Optimal State Machine Implementation in C". While you are at it, you might want to also watch the following YouTube videos about Hierarchical State Machines: * What is a Hierarchical State Machine? * [Automatic Co…

u/active-objectin r/embedded • Recommends

On “Your experience with UML for embedded firmware design and debugging”

"Napkin-style UML" used to sketch some informal class, sequence, and state diagrams has certain benefits because it allows some (more visual) people to better "see" the design. But there is much more potential, which is very rarely realized and that is code generation. Here the most constructive for code generation are the UML hierarchical state machines. Typically, I see quite negative (and sometimes even hostile) reactions when UML is mentioned in embedded forums. This is probably the effect of heavyweight tools and high-ceremony methodologies. But parts of the UML can be had with much more lightweight, "low ceremony" tools as well.

u/active-objectin r/embedded • Recommends

On “State Machines in embedded?”

Here is the YouTube playlist that explains state machines in the context of embedded systems: * State Machines Part-1: What is a state machine? * State Machines Part-2: Guard conditions * State Machines Part-3: Input-Driven State Machines * State Machines Part-4: State Tables and Entry/Exit Actions * State Machines Part-5: Optimal Implementation in C * State Machines Part-6: What is a Hierarchical State Machine? * State Machines Part-7:Automatic Code Generation * State Machines Part-8: Semantics of Hierarchical State Machines

u/active-objectin r/embedded • Recommends

#41 State Machines Part-7:Automatic Code Generation