2024-04-03 06:46 AM
I have this code, in where the interrupt works without issues in debug mode:
void EXTI2_IRQHandler(){
SET_BIT(EXTI->PR1, EXTI_PR1_PIF2); // Clear interrupt flag
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
__HAL_RCC_GPIOD_CLK_ENABLE();
GPIO_InitTypeDef my_GPIO_InitStruct = {0};
// enable nFault (PD2)
my_GPIO_InitStruct.Pin = GPIO_PIN_2;
my_GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
my_GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOD, &my_GPIO_InitStruct);
// Interrupt for nFault (PD2)
SET_BIT(EXTI->IMR1, EXTI_IMR1_IM2); // interrupt for EXTI line 2 (PD2)
SET_BIT(EXTI->FTSR1, EXTI_FTSR1_FT2); // Falling edge for line 2 (PD2)
SET_BIT(SYSCFG->EXTICR[0] ,SYSCFG_EXTICR1_EXTI2_PD); // Interrupt configuration for PD2
NVIC_EnableIRQ(EXTI2_IRQn);
SET_BIT(EXTI->SWIER1, EXTI_SWIER1_SWI2); // trigger interrupt
while(1);
But when put into the main project, it gives me an error, as if the interrupt routine was never defined.
Solved! Go to Solution.
2024-04-03 06:47 AM
Found the solution already:
I have copied the routine in another file. I put the declaration too, but it didnt work.
It workes like this (adding the extern "C"):
#ifdef __cplusplus
extern "C" {
#endif
void EXTI2_IRQHandler(void);
#ifdef __cplusplus
}
#endif
2024-04-03 06:47 AM
Found the solution already:
I have copied the routine in another file. I put the declaration too, but it didnt work.
It workes like this (adding the extern "C"):
#ifdef __cplusplus
extern "C" {
#endif
void EXTI2_IRQHandler(void);
#ifdef __cplusplus
}
#endif