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.
- 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.
- 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.
- Move your existing project folder to a backup folder, e.g.
mv platform-stm32f401-nucleo platform-stm32f401-nucleo.bak
Note – You may want to pick another backup folder name if the one shown above already exists.
- Decompress the tgz file with:
tar xvzf platform-stm32f401-nucleo_assignment3.tgz
The project folder will be expanded to ~/Projects/stm32/platform-stm32f401-nucleo.
- Launch Eclipse. Hit F5 to refresh the project content.
Or you can right-click on the project in Project Explorer and then click “Refresh”.
- Clean and rebuild the project. Download it to the board and make sure it runs.
In minicom, type the command “led ?” and verify you see the following help text:
22562 CONSOLE_UART2> led ? [Commands] test Test function on Start a pattern off Stop a pattern
? List commands
Type the command “led on 0” and verify that the USER LED does NOT blink.
- The statechart was created with the free tools named UMLet. You can download the latest version (14.3) with this link:
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.
- Imagine the following requirements are handed to you about an LED module:
- Upon a pattern request event, the module should show the specified LED pattern.
- If the pattern request includes a “repeated” flag, the module should show the specified LED pattern repeatedly.
- Upon an off request event, the module should turn off the LED.
- Think about the above requirements. Could you find any gaps in the specifications?
- 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?
- 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.
- 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.
- 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