0% found this document useful (0 votes)
16 views

Lab02 (1)

Tp par fpga

Uploaded by

chamsddin323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Lab02 (1)

Tp par fpga

Uploaded by

chamsddin323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Processors Architecture for Embedded Systems Lab

Lab 02
1 OBJECTIVES
• Configure external interrupt (EXTI) in CubeMX and generate Code
• Add into project Callback function and function which turn on led
• Verify the correct functionality by pressing button which turns on LED

2 ARM CORTEX-M INTERRUPT SPECIFICATIONS


What is an Interrupt?

An interrupt is any process that momentarily stops an ongoing program execution and requires the MCU to
execute specialized code related to the event that initiated the interrupt. This specialized code is known as an
interrupt handler (ISR). In ARM terminology, all interrupts whether they are hardware or software initiated
are called exceptions.

The ARM Cortex-M integrated peripheral contains a hardware device called the nested vector interrupt
controller (NVIC) whose purpose is to manage exceptions (See Figure 1). The NVIC is fully integrated into the
HAL software framework and uses its own C structures to set up a variety of registers.

Figure 1 illustrates two types of peripherals: those that are external to the Cortex-M core but internal to the
STM32 MCU (e.g., timers, UARTs, etc.) and those that are entirely external to the MCU. The External
Interrupt/Event Controller (EXTI) manages the connection between external I/O signals and the Nested
Vectored Interrupt Controller (NVIC)..

Figure 1: NVIC block diagram.

2.1 VECTOR TABLE IN STM32


Hardware exceptions originate from external peripherals and are also referred to as Interrupt Requests (IRQs).
Programmers handle these exceptions using dedicated Interrupt Service Routines (ISRs), which are typically
written in a high-level language such as C. The processor identifies these routines through an indirect table
that stores their memory addresses. This table, known as the vector table, is specific to each STM32
microcontroller model (See Figure 2)..
Figure 2: The vector table of Cortex-M3/4

2.2 EXTERNAL LINES AND NVIC


Up to 81 GPIOs available on the Nucleo STM32F401RE are connected to 16 EXTI lines and only 7 of these lines
have an independent interrupt associated with them (see Figure 3). It can be see that EXTI lines 10 and 15
share the same IRQ inside the NVIC (and hence are serviced by the same ISR).
Figure 3: The relation between GPIO, EXTI lines and corresponding ISR in an STM32F401 MCU

3 EXPERIMENT 01: EXTERNAL INTERRUPT-BASED LED CONTROL


In this experiment, we demonstrate the use of external interrupts on the Nucleo-64 board by using a button
connected to GPIO pin PC13 to change the blinking frequency of an LED connected to GPIO pin PA5. Pressing
the button once makes the LED blink twice per second, while pressing it again slows the blinking to once
every two seconds. The program utilizes the STM32 HAL framework to configure and manage the GPIO
interrupt, with an Interrupt Service Routine (ISR) handling the button press event and adjusting the LED
behavior accordingly.

3.1 PINS CONFIGURATION


1. Open STM32CubeIDE and create a new project by navigating to File → New → STM32
Project.
2. Select the Nucleo-F401RE board and name the project Lab02_Interrupt.
3. In the Pinout & Configuration tab, click on the Pinout menu and select Clear Pinouts to
remove all default configurations.
4. Configure PA5 as a GPIO Output.
5. Configure PC13 as GPIO EXTI.
6. Under Categories, click on System Core, then select RCC. In the Click Mode section,
choose HSE and set BYPASS Clock Source.
7. Under Categories, click on System Core, then select GPIO. Choose PC13, scroll down to
GPIO Mode, and select Falling Edge Trigger Detection.
8. Under Categories, click on System Core, then select NVIC. Enable EXTI line [15:10]
Interrupts.
9. Click on the Clock Configuration tab, select HSE, set HCLK (MHz) to 84 (maximum
frequency), then press Enter.
10. Go to File → Save to save your project.
11. In the Project Explorer, navigate to Core → Src, then open the main.c and stm32f4xx_it.c files.
12. In the stm32f4xx_it.c file, scroll down to the EXTI15_10_IRQHandler function. Right-click on it and
select Open Declaration to view the function's details and understand its execution when the button
is pressed.
13. Add
the following two instructions inside the infinite while(1) loop in main.c:
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(tDelay); HAL_Delay(tDelay) ;

14. Declare the variable tDelay as a global variable:


uint16_t tDelay = 50;
15. Implement the following Interrupt Service Routine (ISR) inside the EXTI15_10_IRQHandler function in
stm32f4xx_it.c:
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
for (int i = 0; i < 65535; i++); // Short delay for debounce
if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13))
{ tDelay = (tDelay == 50) ? 2000 : 50; }
/* USER CODE END EXTI15_10_IRQn 0 */

16. Build the project and execute it in the Proteus simulator.

You might also like