2015-05-02 07:37 AM
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
2015-05-02 07:46 AM
i think you need to define the
EXTI4_15_IRQHandler
irq handler, similar (but not exactly the same) as this:void EXTI15_10_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
}
2015-05-02 08:26 AM
I don't really know where I would put that. In the stm32l0xx_hal_gpio.c, it already has:
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
/* EXTI line interrupt detected */
if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
HAL_GPIO_EXTI_Callback(GPIO_Pin);
}
}
/**
* @brief EXTI line detection callbacks.
* @param GPIO_Pin: Specifies the pins connected EXTI line
* @retval None
*/
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
/* NOTE: This function Should not be modified, when the callback is needed,
the HAL_GPIO_EXTI_Callback could be implemented in the user file
*/
}
2015-05-02 12:41 PM
noobee,
I implemented the suggestion you gave, and it works now - thanks. So, now in my main, I have:void EXTI4_15_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == GPIO_PIN_13)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
}
in addition to the IRQ handler in the stm32l0xx_hal_gpio:
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
/* EXTI line interrupt detected */
if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
HAL_GPIO_EXTI_Callback(GPIO_Pin);
}
}
So, I've got the EXTI4_15_IRQHandler declared, which calls HAL_GPIO_EXTI_IRQHandler, which in turn calls HAL_GPIO_EXTI_Callback, which is where the ''do interrupt stuff here'' actually happens. I reached this point through trial and error, which is definitely not how I like writing code. Does it have to be that difficult? I have had limited success finding EWARM examples of simple interrupts.
Joe
2015-05-05 04:17 AM
Did you use STM32CubeMX to configure the interrupt? I thought it generated the ISR and all you needed to do was implement the callback.