AnsweredAssumed Answered

Replicating Cube External Interrupt Example

Question asked by snyder.joe on May 2, 2015
Latest reply on May 5, 2015 by Barta.Hank
I'm using the Cube code generator to try and duplicate the Cube example project of generating an interrupt and toggling the user LED on a Nucleo L053R8 board.  The example in the Cube package works fine, but trying to duplicate it from scratch is not working. 

I have cut and pasted everything from the example main.c into my Cube code, and relative snippets are:

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();     //Initialize the user LED (PA5) on the board
  EXTILine4_15_Config();     //Use the same code as the example to initialize the user button (PC13)
  while (1)
  {
    //HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);     //with this un-commented and without pressing the user button, led toggles fine
    //HAL_Delay(250); 
  }

And the interrupt pin initialization is:
static void EXTILine4_15_Config(void)
{
  GPIO_InitTypeDef   GPIO_InitStructure;
 
  /* Enable GPIOC clock */
  __GPIOC_CLK_ENABLE();
   
  /* Configure PC13 pin as input floating */
  GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  GPIO_InitStructure.Pin = GPIO_PIN_13;
    GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
 
  /* Enable and set EXTI4_15 Interrupt to the lowest priority */
  HAL_NVIC_SetPriority(EXTI4_15_IRQn, 3, 0);
  HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if(GPIO_Pin == GPIO_PIN_13)
  {
    /* Toggle LED2 */
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
  }
 
}

It compiles and runs, and I'm able to flash the LED on its own in the while(1) loop, but as soon as I press the button, it gets stuck.  When I pause the debug, it is showing stuck in the startup_stm32l053xx.s file at the last line of this code snippet:

        PUBWEAK EXTI4_15_IRQHandler
        SECTION .text:CODE:NOROOT:REORDER(1)
EXTI4_15_IRQHandler
        B EXTI4_15_IRQHandler
 
As far as I can see, I have done a 1 for 1 swap from the example code.  Any help would be appreciated. 

Joe

Outcomes