2015-05-02 7: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); 
}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);
 }
 
 }
PUBWEAK EXTI4_15_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
EXTI4_15_IRQHandler
B EXTI4_15_IRQHandler2015-05-02 7: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 8: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);
}
}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);
}
}2015-05-05 4: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.
