The goal of this assignment is to implement an LED pattern generator using HSM (Hierarchical State Machine). This approach allows the source code (implementation) to be directly traceable to the statechart (design) which can in turn be traced back to the requirements (specifications).
See Session 2.1. Model-Based Software Development of the following publication:
Automatic code generation for instrument flight software. Kiri L. Wagstaff, Edward Benowitz, Dj Byrne, Ken Peters, Garth Watney. Jet Propulsion Laboratory, National Aeronautics and Space Administration, 2007.
1 Setup 1. Carefully unplug any extension modules from your Nucleo board. They are not required and may hinder your view of the USER LED. Besides, the USER LED pin (PA.5) is shared with the SPI CLK pin of the LCD module, and therefore they cannot be used together.
2. Download the compressed project file (platform-stm32f401-nucleo_assignment3.tgz) from the Assignment 3 course site.
Place the downloaded tgz file in your VM under ~/Projects/stm32.
3. Move your existing project folder to a backup folder, e.g.
(or on this page: http://umlet.com/changes.htm. Be careful NOT to click on those advertisement Download links!)
The stand-alone version is more stable. It runs on Java, so it should work in your VM which has Java installed.
Note – UMLet is to be installed (decompressed) in your VM but not on your host machine. Once installed, CD to the installation folder (e.g. ~/Projects/Umlet) and type "./umlet.sh &" to launch it.
2 Tasks 1. Imagine the following requirements are handed to you about an LED module:
(a) Upon a pattern request event, the module should show the specified LED pattern.
(b) If the pattern request includes a "repeated" flag, the module should show the specified LED pattern repeatedly.
(c) Upon an off request event, the module should turn off the LED.
2. Think about the above requirements. Could you find any gaps in the specifications?
3. Even for a single LED, specifying its behaviors is not as simple as it appears. Now review the provided statechart in src/UserLed/UserLed.uxf. Does it tell us more about how the LED module should behave?
4. Copy and paste the two LED patterns you added in the previous assignment to src/UserLed/LedPattern.cpp (appending them after the two sample patterns). Remember to update the total count to 4.
5. Implement the statechart in src/UserLed/UserLed.cpp and src/UserLed/UserLed.h.
The header file already contains declarations for all the state functions, internal events, timers, member variables required by the statechart design. Refer to the washing machine example for the coding rules.
6. Test your code with the console command: led on <pattern index from 0 to 3 <0 for non-repeating; 1 for repeating
(e.g. "led on 2 1" to show pattern 2 repeatedly.) led off
See how you can start a new pattern or stop it at any time. For example you can stop a pattern in the middle of a cycle. You can change the pattern before a cycle has finished. This design is reactive and responsive, which is the essence of real-time systems.