From 0b8a55a9e207362fd513c8bb1d33fb8f552cdcdb Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Sat, 8 Mar 2025 14:43:54 +0200 Subject: [PATCH] add button test at the board startup, part 2 --- Core/Inc/stm32f4xx_it.h | 1 + Core/Src/main.c | 7 +++---- Core/Src/stm32f4xx_it.c | 16 +++++++++++++++- test1.ioc | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index fc89766..dd2178f 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -58,6 +58,7 @@ void SysTick_Handler(void); /* USER CODE BEGIN EFP */ void EXTI0_IRQHandler(void); +void EXTI9_5_IRQHandler(void); /* USER CODE END EFP */ diff --git a/Core/Src/main.c b/Core/Src/main.c index 8f469ed..2766bad 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -53,7 +53,7 @@ void ((*executors[])(void)) = { external_temp_show_fahrenheit }; -int current_executor_id = 0; +size_t current_executor_id = 0; /* USER CODE END PV */ @@ -174,14 +174,13 @@ int main(void) HAL_NVIC_EnableIRQ(EXTI0_IRQn); // switch mode for SW5 (alternative advancing method) - GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = GPIO_PIN_8; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - HAL_NVIC_SetPriority(EXTI8_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(EXTI8_IRQn); + HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index 4364047..66992ee 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -41,7 +41,7 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ -extern int current_executor_id; +extern size_t current_executor_id; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -214,4 +214,18 @@ void EXTI0_IRQHandler(void) HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); } +void EXTI9_5_IRQHandler(void) +{ + GPIOD->ODR = 0x1000; + + current_executor_id += 1; + current_executor_id %= 2; + + for (int i = 900000; i > 0; i--) asm("nop"); + + GPIOD->ODR = 0x0000; + + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8); +} + /* USER CODE END 1 */ diff --git a/test1.ioc b/test1.ioc index 2a1afde..b6aa7c3 100644 --- a/test1.ioc +++ b/test1.ioc @@ -157,4 +157,4 @@ SH.ADCx_IN9.ConfNb=1 VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick board=custom -isbadioc=true +isbadioc=false