From: AceVest Date: Wed, 5 Jun 2019 02:59:33 +0000 (+0800) Subject: F103RE GPIO Input Interrupt X-Git-Url: http://zhaoyanbai.com/repos/man.rndc.html?a=commitdiff_plain;h=e85b9cccc27ef2c1689483b283321057db826ab6;p=acecode.git F103RE GPIO Input Interrupt --- diff --git a/learn/stm32/F103RE/F103RE.ioc b/learn/stm32/F103RE/F103RE.ioc index 81c7f01..55aec6f 100644 --- a/learn/stm32/F103RE/F103RE.ioc +++ b/learn/stm32/F103RE/F103RE.ioc @@ -26,11 +26,12 @@ MxCube.Version=5.2.0 MxDb.Version=DB.5.0.20 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false +NVIC.EXTI0_IRQn=true\:0\:0\:false\:false\:true\:true\:true NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.MemoryManagement_IRQn=true\:0\:0\:true\:false\:true\:false\:false NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 +NVIC.PriorityGroup=NVIC_PRIORITYGROUP_2 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false @@ -60,10 +61,11 @@ PA7.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_PP PA7.GPIO_Speed=GPIO_SPEED_FREQ_HIGH PA7.Locked=true PA7.Signal=GPIO_Output -PC0.GPIOParameters=GPIO_Label +PC0.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI PC0.GPIO_Label=KEY1 +PC0.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING PC0.Locked=true -PC0.Signal=GPIO_Input +PC0.Signal=GPXTI0 PCC.Checker=false PCC.Line=STM32F103 PCC.MCU=STM32F103R(C-D-E)Tx @@ -130,6 +132,8 @@ RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK RCC.TimSysFreq_Value=72000000 RCC.USBFreq_Value=72000000 RCC.VCOOutput2Freq_Value=12000000 +SH.GPXTI0.0=GPIO_EXTI0 +SH.GPXTI0.ConfNb=1 VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick board=custom diff --git a/learn/stm32/F103RE/Inc/main.h b/learn/stm32/F103RE/Inc/main.h index db628f8..c4b327b 100644 --- a/learn/stm32/F103RE/Inc/main.h +++ b/learn/stm32/F103RE/Inc/main.h @@ -60,6 +60,7 @@ void Error_Handler(void); /* Private defines -----------------------------------------------------------*/ #define KEY1_Pin GPIO_PIN_0 #define KEY1_GPIO_Port GPIOC +#define KEY1_EXTI_IRQn EXTI0_IRQn #define LED1_Pin GPIO_PIN_4 #define LED1_GPIO_Port GPIOA #define LED2_Pin GPIO_PIN_5 diff --git a/learn/stm32/F103RE/Inc/stm32f1xx_it.h b/learn/stm32/F103RE/Inc/stm32f1xx_it.h index 9d4af17..f90bf1e 100644 --- a/learn/stm32/F103RE/Inc/stm32f1xx_it.h +++ b/learn/stm32/F103RE/Inc/stm32f1xx_it.h @@ -56,6 +56,7 @@ void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); +void EXTI0_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/learn/stm32/F103RE/Src/gpio.c b/learn/stm32/F103RE/Src/gpio.c index 007b707..27bf981 100644 --- a/learn/stm32/F103RE/Src/gpio.c +++ b/learn/stm32/F103RE/Src/gpio.c @@ -52,7 +52,7 @@ void MX_GPIO_Init(void) /*Configure GPIO pin : PtPin */ GPIO_InitStruct.Pin = KEY1_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(KEY1_GPIO_Port, &GPIO_InitStruct); @@ -63,10 +63,16 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* EXTI interrupt init*/ + HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(EXTI0_IRQn); + } /* USER CODE BEGIN 2 */ - +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { + HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, SET); +} /* USER CODE END 2 */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/learn/stm32/F103RE/Src/main.c b/learn/stm32/F103RE/Src/main.c index 4555c88..413a15d 100644 --- a/learn/stm32/F103RE/Src/main.c +++ b/learn/stm32/F103RE/Src/main.c @@ -96,7 +96,7 @@ int main(void) /* USER CODE BEGIN WHILE */ while (1) { - HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); + HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin); HAL_Delay(100); /* USER CODE END WHILE */ diff --git a/learn/stm32/F103RE/Src/stm32f1xx_hal_msp.c b/learn/stm32/F103RE/Src/stm32f1xx_hal_msp.c index f15a06a..60814ca 100644 --- a/learn/stm32/F103RE/Src/stm32f1xx_hal_msp.c +++ b/learn/stm32/F103RE/Src/stm32f1xx_hal_msp.c @@ -70,6 +70,8 @@ void HAL_MspInit(void) __HAL_RCC_AFIO_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); + HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); + /* System interrupt init*/ /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled diff --git a/learn/stm32/F103RE/Src/stm32f1xx_it.c b/learn/stm32/F103RE/Src/stm32f1xx_it.c index b770208..115e832 100644 --- a/learn/stm32/F103RE/Src/stm32f1xx_it.c +++ b/learn/stm32/F103RE/Src/stm32f1xx_it.c @@ -197,6 +197,20 @@ void SysTick_Handler(void) /* please refer to the startup file (startup_stm32f1xx.s). */ /******************************************************************************/ +/** + * @brief This function handles EXTI line0 interrupt. + */ +void EXTI0_IRQHandler(void) +{ + /* USER CODE BEGIN EXTI0_IRQn 0 */ + + /* USER CODE END EXTI0_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); + /* USER CODE BEGIN EXTI0_IRQn 1 */ + + /* USER CODE END EXTI0_IRQn 1 */ +} + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */