cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable external interrupt.

Sidlauskas.David
Associate II

I'm using CubeMX V 5.0.1 to create a simple project for Nucleo-L031K6 board. I've configured PA12 as an input. Under Pinout & Configuration->System Core->NVIC there is no option to enable "EXTI line 4 to 15 interrupts" . Show only enabled interrupts is not checked.

I have a very similar project created with an earlier version (4.x.x) of CubeMX and the option to enable "EXTI line 4 to 15 interrupts" is shown when the project is opened with V5.0.1

To duplicate, with CubeMX V5.0.1

  1. Create a new project for Nucleo-L013K6
  2. Select PA12 as input.
  3. Go to NVIC configuration as above and see that the "EXTI line 4 to 15 interrupts" selection is not available.

What am I missing???

Thanks,

Dave

3 REPLIES 3
Piranha
Chief II

I'm actually using CubeMX only as a pin selection tool when planning schematics/PCB and have not even tried 5.x versions, but in 4.x that pin would have to be selected not as GPIO_Input, but GPIO_EXTI12.

Sidlauskas.David
Associate II

Thanks Piranha, I must have done that dozens of times with the old version, but completely missed it in this case. You could probably hear me dummy slapping my head where ever you are :-).

S.Ma
Principal

One additional detail about EXTI, it is possible to combine alternate function with EXTI even though activation requires manual coding overrides.

For EXTI only, brute force is post MX Init code to reconfigure the EXTI pin, something like this:

// here SPI SCL slave is combined with EXTI interrupt on STM32L4R
 
 
void SPIP_EnableSCK_EXTI(SPIP_t* pSPIP) {
// PD1 = SCK
  //void HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init)
  // this is a patch to have EXTI on Alternate function...
GPIO_MODE_IT_RISING_FALLING, 0, 0, 0 };
//  HAL_GPIO_Init(GPIOD, &GPIO_Init);
//    SYSCFG->EXTICR[position >> 2] = temp;
  SYSCFG->EXTICR[0] &= ~(0xF<<4);
  SYSCFG->EXTICR[0] |= (3<<4);
  EXTI->IMR1 |= GPIO_PIN_1; // interrupt enable
  EXTI->RTSR1 |= GPIO_PIN_1; // rising sense
  EXTI->FTSR1 |= GPIO_PIN_1; // falling sense
// HAL limitation
  __HAL_GPIO_EXTI_CLEAR_IT(pSPIP->pSCK->Init.Pin);
  __HAL_GPIO_EXTI_CLEAR_FLAG(pSPIP->pSCK->Init.Pin);
  //EXTI->IMR1 |= (1<<1);
  HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI1_IRQn);
}
 
void SPIP_DisableSCK_EXTI(SPIP_t* pSPIP) {
  HAL_NVIC_DisableIRQ(EXTI1_IRQn);  
}
 
void EXTI1_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI0_IRQn 0 */
  /* USER CODE END EXTI0_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
  /* USER CODE BEGIN EXTI0_IRQn 1 */
  /* USER CODE END EXTI0_IRQn 1 */
}

In Cube 4.x when enabling the Stacked pin feature, selecting SPI Alternate followed by EXTI will cause SPI peripheral to be deselected quietly. HAL definitions and functions does not provide straight offering for AF + EXTI. In my case it was for SPI Slave SCK activity start detect (to detect transmission from master has started)