

This will show how it would be smoother (and less verbose) to use the RTIC framework instead if one would want to integrate interrupts in their application. Additionally, as an extra step, in a third post, I will also transfer the whole application to the RTIC framework. Especially since interrupt configuration methods for GPIO are slightly different than the ones for timers. The idea behind the separation is not to introduce much all at once. Integrate interrupts for timer delay event (next post).Configure the application to use GPIO interrupts for the button press (this post).Instead, I will be doing two separate steps, each in a separate post, as follows: However, I won't be doing that all at once. This means that both hardware events causing transitions (button press and timer expiry) can be configured with interrupts. As such, this application can be programmed to run entirely on interrupts.
Gpio led3 nucleo f401re software#
In essence, interrupts are software routines that are triggered by hardware events. The "LED off" state has exactly the same transition conditions as the "LED on" state. The "Button Pressed" state would in turn adjust the amount of timer delay and then return to the state it transitioned from. On the other hand, if a button press is detected the application would transition to a "Button Pressed" state. If the delay expires the application would transition to an "LED off" state that turns off the LED and resets the delay timer. While in the "LED on" state two events could happen to make the system transition to another state either a button press or a timer delay expiration. In this state, a timer would also be started. The application will start in a state where the LED is turned on.

Additionally, the representation assumes that configuration is already completed. I will not be encoding any states in the code. Here's one possible approach:Īlthough I use state machine representation. I've decided it would be best to represent the algorithm using a state machine. I will be detailing the configuration steps in the implementation section. For algorithm design purposes, I will assume that interrupts are configured already. In this section, I will focus on the design of the application algorithm itself rather than the configuration aspects. Meaning, that every time I press the on-board button, I want to see the LED turning on and off at a different rate. In the application developed in this post, I want to cycle through several LED blinking frequencies based on a button press.

Gpio led3 nucleo f401re code#
Note that if the code on the git repo is slightly different then it means that it was modified to enhance the code quality or accommodate any HAL/Rust updates.

As if that weren't enough, I would say the use of Rust adds another level of complexity. Dealing with interrupts on its own from an embedded microcontroller perspective is more complex than polled code.
