📚 Assignment 3 CMPE1250: Delay cycles, GPIO and GPIO Library
By the end of this ICA, students will be able to:
- Configure GPIO pins directly through registers
- Build and use a reusable GPIO library
- Implement delays based on measured CPU cycle timing
- Compare the performance of direct register access vs. library‑based access
- Use the debugger and oscilloscope to characterize microcontroller behavior
📋 Overview
-
You will be implementing your GPIO Library
-
You will use the time delay functions practice in class to obtain some blocking delay events in [ms]
-
You should review the notes and demos on GPIO and be comfortable with navigating the reference manual and datasheet for the
STM32G0B1RE. -
Use the debugger for verificacion, as discussed in class.
1️⃣ Preparatory Work:
-
Remember to connect every GPIO port to be use to the
RCCmodule. -
Create a new compilation unit based on the
gpio,hprovided and implement the function prototypes provided into yourgpio.c
Implement at minimum:
- GPIO_InitOutput()
- GPIO_InitInput()
- GPIO_Set();
- GPIO_Clear();
- GPIO_Toggle();
- GPIO_Read();
-
GPIO_InitAlternateF(); - To be used very soon
Notes:
-
Begin by creating a standard C project in segger as demonstrated in class.
-
Divide your main function into a
‘one-time initializations’section, and aninfinite loopsection. -
You may already have a template main with this structure, and if not, you should create one now.
-
In the one-time inits section, write the code to configure:
-
PA5asOutput, preloaded asLOW(Start at 0). -
PC10asOutput, preloaded asLOW(Start at 0). -
PC13asInput.
-
2️⃣ Part A - Toggle a pin without using the LIbrary
-
In the infinite loop section, toggle
PC10and nothing else. Do this first manipulating the ODR register only, without using your library (Do not useGPIO_Toggle) -
Record the positive width using the oscilloscope and register how much time the execution takes.
-
Knowing the micro-controller runs by default at 16[MHz], can you estimate this time in
cycles?
3️⃣ Part B – Using GPIO_Toggle()
-
Comment out the code in the infinite loop from Part A, and replace it with the function call:
GPIO_Toggle. -
Record the positive width using the oscilloscope and register how much time the execution takes.
-
How much different is this time from the one obtained in Part A? Explain your findings
-
Can you estimate the difference in
cycles?
4️⃣ Part C
-
For this part you can comment out the previous ones or put them inside an #ifdef preprocessor directive.
-
Using the blocking delays implemented, generate a signal on
PC10that isHIGH for 10[ms]andLOW for 15[ms]. In other words, a signal of 25[ms] period and 40% Duty Cycle. -
Toggle the user LED (
LD4) every25[ms]
5️⃣ Part D
-
Using the Blue button (
PC13), change theLD4toggle time from25[ms]to250[ms]when the button is being pressed, and make it go back to25[ms]when released. -
All other funtionality fof
Part C(PC10 singal) should remain unaffected.