2025-12-08 7:20 AM - edited 2025-12-08 7:21 AM
Hello,
I’m working with an STM32F446 and have configured GPIOB pin 12 as an EXTI input. After initialization and before entering the main while loop, I call a function that blocks program execution(what I mean by blocking : I have a test that stands in a blocking while until I receive the first bytes of USART reception) . In this scenario, changing the pin state does not trigger the EXTI interrupt. However, if I comment out this blocking function, the EXTI works as expected. I also observe the same behavior if I insert a while(1) loop before the main loop.
Has anyone experienced similar behavior? If yes, do you know what the solution might be?
Thank you in advance.
Aymen
2025-12-08 7:24 AM
Hello @Mohamed Aymen ,
Better to share your main so we can look at it closely.
2025-12-08 7:29 AM
This is my main
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();
MX_DMA_Init();
MX_I2C3_Init();
MX_SPI3_Init();
MX_TIM1_Init();
MX_TIM2_Init();
MX_USART2_UART_Init();
MX_ADC1_Init();
MX_SPI4_Init();
MX_DAC_Init();
MX_TIM6_Init();
MX_USART1_UART_Init();
MX_TIM5_Init();
MX_IWDG_Init();
/* USER CODE BEGIN 2 */
// Init du TIMER pour la pause de 5�S pour l'init des STPM
HAL_TIM_Base_Start(&htim5) ;
CalibrationEnCours = TFLAG_FALSE ;
// while(1){HAL_IWDG_Refresh(&hiwdg) ;} // If I uncomment this line, the EXTI no longer functions
// Positionner la demande d'envoi de la configuration par la carte UC (sur scrutation)
stm32_rs485_wait_config = VRAI;
// Tester la presence des connecteurs au boot
PresenceConnecteur.flag = TFLAG_TRUE ;
LancerAutotest = 0 ;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// Reinit WATCHDOG
HAL_IWDG_Refresh(&hiwdg) ;
.
.
.
}
2025-12-08 8:02 AM - edited 2025-12-08 8:03 AM
If you use this code, do you fall into the same behavior? (removed all the stuff, keeping the GPIO config + two while loops):
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 */
while(1){} // If I uncomment this line, the EXTI no longer functions
// Tester la presence des connecteurs au boot
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
.
.
.
}
2025-12-10 12:27 AM
2025-12-10 12:34 AM
Hello,
If you play with the optimization? let's say the lowest optimization (depending on your IDE). Do you see the same behavior?
2025-12-10 12:49 AM
I build the project with a Makefile, and I use VScode only for debugging, but I will check the optimization level effect!
2025-12-10 1:26 AM
Changing the optimization level didn’t fix the issue
2025-12-10 1:50 AM
> changing the pin state does not trigger the EXTI interrupt
How do you know? How do you observe the EXTI interrupt being triggered? What's the expected behaviour and how is the observation different from that?
JW