STM32 interrupt application

1. Introduction to interruption

The code is mainly distributed in the firmware library stm32f10x_exti.h and stm32f10x_exti.c File.
Here we first STM32 IO Some basic concepts of port interrupt. STM32 Each of IO Can be used as an external interrupt
Interrupt input port, which is also true STM32 The power of. STM32F103 Interrupt controller support for 19 External interrupts /
Event request. Each interrupt is provided with a status bit / Events have independent trigger and mask settings. STM32F103 of
19 External interrupts are:
Line 0~15 : corresponding to external IO The input of the port is interrupted.
Line 16 : connect to PVD Output.
Line 17 : connect to RTC Alarm clock events.
Line 18 : connect to USB Wake Events
2. Introduction to NVIC
NVIC: nested vector interrupt controller, which belongs to kernel peripherals and manages interrupt related functions including kernel and all peripherals on chip.
Two important library files: core_cm3.h and misc.h

 

  misc.h//NVIC setting system interrupt management

 

                                              Sequence of interrupt programming

1 - enable interrupt request

2 - configure interrupt priority grouping
static void EXTI_NVIC_Config()
{
	   NVIC_InitTypeDef NVIC_InitStruct;
		
		NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

		NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;
		NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
		NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
		NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
		NVIC_Init(&NVIC_InitStruct);
}

3 - configure NVIC register and initialize void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct);
          Embedded vector interrupt controller: nested vector interrupt controller (NVIC)

(For the complete STM32 Devices IRQ Channels list, please refer to stm32f10x.h file)

  Want to know STM32   For this list, refer to stm32f10x.h (interrupt source)

4 - write interrupt service function
The name of the interrupt service function should be the same as startup_ stm32f10x_ The name in HD. S must be the same

 

void EXTI0_IRQHandler(void)
{
	if(EXTI_GetITStatus(EXTI_Line0) != RESET )
	{
		LED_G_TOGGLE;
	}
	EXTI_ClearITPendingBit(EXTI_Line0);
}

                                          

                                         EXTI - external interrupt / Event controller
References in this chapter:< STM32F10X- Chinese reference manual interrupt and event section and 8.4 chapter AFIO deposit
Device description
EXTI brief introduction
  EXTI (External interrupt/event controller) - external interrupt / Event controller  , Managed the of the controller 20
Interrupts / Event line. Each interrupt / Each event line corresponds to an edge detector, which can realize the rising edge of the input signal
Detection and falling edge detection. EXTI Each interrupt can be implemented / The event line is configured separately and can be configured as
Interrupt or event, and the properties that trigger the event.

  

 

 

 

                                          EXTI initialization structure

                EXTI_InitTypeDef

typedef struct
{
  uint32_t EXTI_Line;                               / / Used to generate interrupt / event lines
  EXTIMode_TypeDef EXTI_Mode;         / / Exti mode (interrupt / event)

  EXTITrigger_TypeDef EXTI_Trigger;    / / Trigger (up / down / up / down)

  FunctionalState EXTI_LineCmd;          / / To enable or disable
}EXTI_InitTypeDef;

Select the GPIO line as the external interrupt

/**
  * @brief  Selects the GPIO pin used as EXTI Line.
  * @param  GPIO_PortSource: selects the GPIO port to be used as source for EXTI lines.
  *   This parameter can be GPIO_PortSourceGPIOx where x can be (A..G).
  * @param  GPIO_PinSource: specifies the EXTI line to be configured.
  *   This parameter can be GPIO_PinSourcex where x can be (0..15).
  * @retval None
  */
void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
{
  uint32_t tmp = 0x00;
  /* Check the parameters */
  assert_param(IS_GPIO_EXTI_PORT_SOURCE(GPIO_PortSource));
  assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
  
  tmp = ((uint32_t)0x0F) << (0x04 * (GPIO_PinSource & (uint8_t)0x03));
  AFIO->EXTICR[GPIO_PinSource >> 0x02] &= ~tmp;
  AFIO->EXTICR[GPIO_PinSource >> 0x02] |= (((uint32_t)GPIO_PortSource) << (0x04 * (GPIO_PinSource & (uint8_t)0x03)));
}

exit.c:

#include "exti.h"

static void EXTI_NVIC_Config()
{
	   NVIC_InitTypeDef NVIC_InitStruct;
		
		NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

		NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;
		NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
		NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
		NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
		NVIC_Init(&NVIC_InitStruct);
}

void EXTI_Key_Config(void)
{
	   GPIO_InitTypeDef GPIO_InitStruct;
		EXTI_InitTypeDef EXTI_InitStruct;
		//Configure interrupt priority
		EXTI_NVIC_Config();
	   //Initialize GPIO
	   RCC_APB2PeriphClockCmd(KEY_UP_GPIO_CLK, ENABLE);
	   GPIO_InitStruct.GPIO_Pin  =KEY_UP_GPIO_PIN;
		GPIO_InitStruct.GPIO_Mode =GPIO_Mode_IN_FLOATING;
      GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
	   GPIO_Init(KEY_UP_GPIO_PORT, &GPIO_InitStruct);
	   //Initialize EXTI
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
	   GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);	
		EXTI_InitStruct.EXTI_Line = EXTI_Line0;
		EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; 
	   EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;	
	   EXTI_InitStruct.EXTI_LineCmd = ENABLE;
		EXTI_Init(&EXTI_InitStruct);
}

  Just call it in the main function

EXTI_Key_Config(void);

Error summary:

 ..\OBJ\Template.axf: Error: L6200E: Symbol LED_GPIO_Config multiply defined (by dsp_led.o and stm32f10x_it.o).
Not enough information to list image symbols.
Not enough information to list the image map.

It is found that the header file #include "dsp_led.c" is written incorrectly!!!

exti\exti.h(9): warning:  #1295-D: Deprecated declaration EXTI_NVIC_Config - give arg types

Reason: static void   EXTI_NVIC_Config()

Keywords: stm32

Added by yousaf931 on Tue, 21 Sep 2021 00:43:53 +0300