Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EEE404/591 Real Time DSP

Lab 3: Introduction to On-Chip Peripherals

I.           Objectives

The objective of this lab is to introduce students to the on-chip peripherals and how to access them through memory mapped registers. Upon completion, students will be familiar with

•    accessing and updating memory mapped peripheral registers

•    working with GPIO peripherals such as LEDs and push button

•    setting up timers with specified time intervals and using timer for cycle count

II.          Hardware Setup

Set up the following hardware:

•    STM32F407G-DISC1 kit : When you are ready to upload code to your board, connect USB Type-A end of the cable to your computer’s USB port, connect the Mini-B end of the cable to the board. The PWR red LED will turn on.

III.         Code

Download the following code from Canvas:

•    led_toggle : gpio.h, timer.h, main.c, main_button_poll.c, main_button_interrupt.c, main_timer_interrupt.c

•    timer_count_cycles : main.s, main.c (GRAD STUDENTS ONLY)

IV.        References

The following documents are posted on Canvas.

•    STM32CubeIDE User Guide

•    STM32 Cortex-M4 Microcontroller Reference Manual

•    STM32 Cortex-M4 Microcontroller Programming Manual

•    STM32F407 Discovery Board User Manual

V.         Tasks

1.    Use push button to toggle LED through polling

The code to toggle the green LED is provided to you. Try it out on the board.

Now you need to fill in the parts labelled as FILL_IN_BLANK” in the partially completed script to toggle  the red LED by pushing on the user push button through polling. Use the constants or macros defined in the header file whenever possible. Run, debug and try it out on the board.

2.    Use push button to toggle LED through external interrupt

Fill in the parts labelled as FILL_IN_BLANK” in the partially completed script to toggle the red LED by      pushing on the user push button through external interrupt. Use the constants or macros defined in the header file whenever possible. Run, debug and try it out on the board.

3.    Control LED blink rate using internal timer interrupt

The code to toggle the green LED using timer interrupt is provided to you. Try it out on the board.

Given the clock entering the prescaler is fCK_PSC = 16MHz, fill in the missing parts of the table to achieve different blink periods (sum of on time and off time). It is assumed that the on time = off time. An example is shown in the 1st  row. This is also the setting used in the code provided to you. Note that for the last row, i.e., 6 seconds, there will be more than one correct combinations of PSC and ARR to achieve the desired period. Any of these combinations is acceptable as long as the calculation is shown in the 3rd column.

Prescaler

(PSC)

Auto Reload

Register

(ARR)

Time calculated between LED toggles (i.e.,

on time or off time)

(show calculation)

Period

(sum of on and off

time)

4999

1599

(1+4999)*(1+1599)/16000000 = 0.5 second

1 second

29999

 

 

3 second

 

 

 

6 second

Change the code and try the different settings above and observe the LED blink rate.

4.    Use the timer to measure cycle count

A partially completed main.s file for measuring cycle count of the multiply and accumulate operation using timer is provided to you. Fill in the parts labelled as FILL_IN_BLANK” in the partially completed    script. Run and debug to make sure your code is correct. Is the cycle count you get from using the timer similar to the number you get from Lab 2?

5.    Use the timer to measure cycle count (c implementation): GRAD STUDENTS ONLY

For this task, you need to copy the two header files: gpio.h, timer.h from led_toggle project to the Inc” folder in the timer_count_cycles project.

A partially completed main.c file for measuring cycle count of the multiply and accumulate operation using timer is provided to you. Fill in the parts labelled as FILL_IN_BLANK” in the partially completed      script. Use main_timer_interrupt.c in the led_toggle project as an example. Run and debug to make sure your code is correct. Is the cycle count you get from using the timer similar to the number you get from

Lab 2?

VI.        Deliverables

Start your lab report by including the lab title and your name at the top.

Include in your lab report the followings. Submit your lab report as a single PDF file to Canvas.

1.    Table (1) : the filled-out table from Task 3 above.

2.    Code (3): copy and paste your code below using the following template:

In main_button_poll.c, all 10 lines containing FILL_IN_BLANK” . Make sure to include the code in order.

In main_button_interrupt.c, all 5 lines containing FILL_IN_BLANK”, in the NEW part of interrupt- related code. Make sure to include the code in order.

In main.s, all 5 lines containing FILL_IN_BLANK” . Make sure to include the code in order.

3.    Screenshot (1): show the memory browser, highlight the cycle count (converted to decimal).

GRAD STUDENTS ONLY:

In main.c, include all 8 lines containing FILL_IN_BLANK” . Make sure to include the code in order. Include screenshot showing the value of the cycle_count variable in main.c.