Zephyr: State Machine Framework Refactor Lab
BME554L - Fall 2026 - Palmeri
Lab
Git Version Control
- Use best practices for version control (branching, commit messages, etc.).
- Do all development on a dedicated branch that is merged into
mainonce it is functional. - Commits should be very specific to the changes/additions you are making to your code. This will help you and others understand what you did and why you did it.
- On a given development branch, try to implement one small piece of functionality at a time, commit it, and then move on to the next piece of functionality.
Important
You do not want one, monolithic git commit right before you submit your project.
Refactor: State Machine Framework
- Create a new development branch in your forked repository you have used the last few weeks called
refactor_smf. - Refactor your code to use the Zephyr State Machine Framework (SMF).
- Use
entryandexitsubstates to handle state transitions where something should be done “once” when entering or exiting a state. - Refactor code to make sure that state-specific things are done in that state. For example:
- If an error LED should only be on in the
ERRORstate, then the code to turn on the LED should be in theERRORentry state and not done in the exit of the previous state. - If a button should only be active in a certain state, it should be enabled/disabled in the entry/exit of that state.
- If an error LED should only be on in the
- Make sure that your device initialization is done in an
INITstate (so that, in the future, a soft reset can allow the device to be completely re-initialized).
- Use
- Refactor your
ACTION(blinking) state to use a heirachical state machine (HSM) to handle the blinking LED. TheACTIONstate should have substates for each of the blinking frequencies (2 Hz, 3 Hz, etc.). TheACTIONstate should also have anentrysubstate that initializes the action timer to the correct period for the current frequency. - Make sure that your state diagram is updated to reflect these entry / exit actions. This diagram should exactly match your firmware implementation of the SMF.
- Qualitatively make sure that your device continues to function as expected.
Additional Testing
Preserving Action Timer Fractional-Period Across Sleep
- Your firmware from the previous lab should have preserved the remaining time on the action timers when you enter the
SLEEPstate. Add a section to your previous technical report that demonstrates the functionality of this feature. This can be done viaLOGGINGby showing the remaining time on the action timers before enteringSLEEPand then showing that the remaining time is preserved for the first timing period after exitingSLEEP.
How do I ask for help?
- If you have a general / non-coding question, you should ask your TAs / Dr. Palmeri on Ed to allow any of them to respond in a timely manner.
- Push you code to your GitLab repository, ideally with your active development on a non-
mainbranch. - Create an Issue in your repository.
- Add as much detail as possible as to your problem, and add links to specific lines / section of code when possible.
- Assign the label “Bug” or “Question”, as appropriate.
- Be sure to specify what branch you are working on.
- Assign the Issue to one of the TAs.
- If your TA cannot solve your Issue, they can escalate the Issue to Dr. Palmeri.
- You will get a response to your Issue, and maybe a new branch of code will be pushed to help you with some example syntax that you can use
git diffto visualize.
What to Submit
- As with the previous labs, push this development branch to Gitlab and merge it into
main. - Create an annotated tag for that merged commit called
v1.5.0. - Create an Issue assigned to Dr. Palmeri, labeled
Review, to review your code forv1.5.0.