Assignment #3: Delays and GPIO LLibrary

📚 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 RCC module.

  • Create a new compilation unit based on the gpio,h provided and implement the function prototypes provided into your gpio.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 an infinite loop section.

  • 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:

    • PA5 as Output, preloaded as LOW (Start at 0).

    • PC10 as Output, preloaded as LOW (Start at 0).

    • PC13 as Input.

2️⃣ Part A - Toggle a pin without using the LIbrary

  • In the infinite loop section, toggle PC10 and nothing else. Do this first manipulating the ODR register only, without using your library (Do not use GPIO_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 PC10 that isHIGH for 10[ms] and LOW for 15[ms]. In other words, a signal of 25[ms] period and 40% Duty Cycle.

  • Toggle the user LED (LD4) every 25[ms]

5️⃣ Part D

  • Using the Blue button (PC13), change the LD4 toggle time from 25[ms] to 250[ms] when the button is being pressed, and make it go back to 25[ms] when released.

  • All other funtionality fof Part C (PC10 singal) should remain unaffected.