π Assignment 1 CMPE2250: β Simple Interrupts
-
Begin by creating a new project for the STM32G0B1RET6 Nucleo board, following the steps and best practices covered in class/CMPE1250.
-
Include your library support for GPIO, timer, USART, and clocks.
1οΈβ£ Part A β No interrupt timer (TIM6)
-
Using your timer library, configure
TIM6to generate update events at 25ms intervals. -
Create a program that will toggle the user LED (GPIOA, 5) every 25ms using polling method.
-
You should be principally using your libraries for most of this code.
-
Validate on the scope (PA5), and visually, that the code is generating 25ms intervals on the scope, on the correct pin.
Part A β Analysis
Record your findings/answers as markdown in a readme.md in your repository folder for this assignment.
- Q1 β What code is running the bulk of the time in this program?
- Q2 β What could lead to minor inconsistencies in the pin toggling schedule relative to the ideal?
- Q3 β Did you have to set any alternate function (AFx), Yes or No and Why?
2οΈβ£ Part B β Simple TIM6 update event interrupts
-
Include initialization code for
USART2,38400BAUD RATE. -
Ensure that your library contains the necessary to enable the Timer update interrupt.
-
Add the necessary ISR for the interrupt that you will be generating.
-
Alter a copy of the Part A code to generate the same interval, but now using interrupts.
-
Create a global volatile flag that will be non-zero when the interrupt has occurred.
-
Create a global volatile flag that will count the number of interrupt events that have occurred.
-
Configure
PA6as an output. In the ISR, toggle thePA6pin used for scoping the timer activity. -
In the ISR, increase both global volatile variables.
-
Modify the main loop such that it checks for the volatile flag to be non-zero. If it is, set it to zero and toggle the user LED (PA5). Additionally, every 100 interrupt events, send a β.β character to USART2.
Part B β Analysis
Record your findings/answers as markdown in a readme.md in your repository folder for this assignment.
- Q1 β What code is running the bulk of the time in this program, and how does it differ from Part A?
- Q2 β Does the implementation in Part B improve the consistency of the pin toggling schedule for the scope pin, and if it does, how so?
- Q3 β You were instructed to only have the ISR toggle the scope pin and alter two global volatile variables. Why not have the ISR just perform all of the code from the main loop, and would that even be possible?
- Q4 β Even though one of the volatile variables is meant to be an event flag, you were directed to increase this variable in the ISR, rather than set it to one. What purpose could operating this as a counter have over using the variable as a boolean value?
- Q5 β How often should a β.β character appear on the terminal? Show math.
3οΈβ£ Part C β Waiting for an interrupt
Add only a single line to a copy of Part B β insert a __WFI() instruction at the top of the main loop.
Part C β Analysis
Record your findings/answers as markdown in a readme.md in your repository folder for this assignment.
- Q1 β Functionally, has anything in the program changed?
- Q2 β The main loop could be simplified. What changes could you make to simplify the main loop code without altering the programβs behaviour?
- Q3 β What would happen to the main loop code if there were more than one source of interrupts enabled?