Skip to main content
ferrario
Associate III
October 6, 2016
Question

EXTI11 HAL

  • October 6, 2016
  • 6 replies
  • 1481 views
Posted on October 06, 2016 at 13:48

I am trying to make EXTI11 work using the HAL libraries and run into troubles.

This is my configuration

  /*Configure GPIO pin : EXT11_Pin */

  GPIO_InitStruct.Pin = GPIO_PIN_11;

  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);

 //some time later

  HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);       //EXT11

file stm32f4it.c

void EXTI10_15_IRQHandler(void)

{

  /* Handle PD11 interrupt */

 

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);

}

//file interruptcallbacks.c

void HAL_GPIO_EXTI_Callback (uint16_t GPIO_Pin)

{    

    if (GPIO_Pin==

GPIO_PIN_11

)

    {

          // FALLING

          if (EXTI->FTSR & 0x0400)

          {

              //ENABLE RISING

              EXTI->FTSR &= 0xFBFF;

              EXTI->RTSR |= 0x0400;

          }

          //RISING

          else if ((EXTI->RTSR & 0x0400)!=0)

          {

              //ENABLE FALLING

              EXTI->RTSR &= 0xFBFF;

              EXTI->FTSR |= 0x0400;

              

              }

          }

    }

the issue I am facing, is that, as soon as I toggle the interrupt line, code jumps into Default_Handler.

Disabling the interrupt works as expected.

Thanks

Fabio

 

    This topic has been closed for replies.

    6 replies

    Tesla DeLorean
    Guru
    October 6, 2016
    Posted on October 06, 2016 at 15:00

    Use the right name, it is 15_10 not 10_15, otherwise the Vector Table linkage will fail.

    EXTI10_15_IRQHandler(void) // Bad

    EXTI15_10_IRQHandler(void) // Good

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    ferrario
    ferrarioAuthor
    Associate III
    October 6, 2016
    Posted on October 06, 2016 at 18:21

    Thanks Clive,

    This was a typo in pasting the code.

    I copied the ISR from the startup code.

    I must be doing something else wrong.

    Still no joy.

    Fabio

    Tesla DeLorean
    Guru
    October 6, 2016
    Posted on October 06, 2016 at 18:44

    I must be doing something else wrong.

    0x0400 is 210

    0x0800 is 211

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    ferrario
    ferrarioAuthor
    Associate III
    October 10, 2016
    Posted on October 10, 2016 at 13:26

    Dear Clive,

    thanks for your help. You are right.

    Although this fixes my interrupt callback routine I never have the joy to see it working because I routinely jump into default_handler.

    So my question :

    sure the obvious idea is that I don't have a handler for this event, but the

    EXTI15_10_IRQHandler(void)

    routine is there and is the one the startup code looks for, it should override the weak call to the default hanlder where I indeed land.

    Why doesn´t CUBEMx automatically generate also this ISR?

    I wrote a mini application to test EXT11 and experience the same issue..

    Is there any example application I can use for reference?

    Any help is really appriciated.

    Thanks

    Tesla DeLorean
    Guru
    October 10, 2016
    Posted on October 10, 2016 at 18:39

    I can't be drawn into issues with HAL/CubeMX

    You'd perhaps want to simplify the handler to clear the right pin, and toggle a GPIO or something. That's what I'd start with using the SPL.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    October 10, 2016
    Posted on October 10, 2016 at 21:00

    // STM32 EXTI11 STM32F4 Discovery - sourcer32@gmail.com
    // Loop PC10 to PC11 to demonstrate handler
    #include ''stm32f4_discovery.h''
    /**************************************************************************************/
    void GPIO_Configuration(void)
    {
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* GPIOC clock enable */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_SetBits(GPIOC, GPIO_Pin_10);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    }
    /**************************************************************************************/
    void EXTI_Configuration(void)
    {
    EXTI_InitTypeDef EXTI_InitStructure;
    /* Enable SYSCFG clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
    /* Configure EXTI Line11 */
    EXTI_InitStructure.EXTI_Line = EXTI_Line11;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);
    /* Connect EXTI Line11 to PC11 pin */
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource11); 
    }
    /**************************************************************************************/
    void EXTI15_10_IRQHandler(void)
    {
    if (EXTI_GetITStatus(EXTI_Line11) != RESET)
    {
    EXTI_ClearITPendingBit(EXTI_Line11);
    /* Toggle LED3 : End of Transfer */
    STM_EVAL_LEDToggle(LED3);
    // Add code here to process things
    }
    }
    /**************************************************************************************/
    void NVIC_Configuration(void)
    {
    NVIC_InitTypeDef NVIC_InitStructure;
    /* Enable the EXTI IRQ Channel */
    NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    }
    /**************************************************************************************/
    int main(void)
    {
    GPIO_Configuration();
    NVIC_Configuration();
    EXTI_Configuration();
    STM_EVAL_LEDInit(LED3); /* Configure LEDs to monitor program status */
    STM_EVAL_LEDOn(LED3); /* Turn LED3 on, toggling means it working */
    while(1) // Don't want to exit
    {
    volatile int i;
    for(i=0; i<
    10000000
    ; i++);
    GPIOC->ODR ^= GPIO_Pin_10; /* Connect PC10 to PC11 to make LED3 toggle */
    }
    }
    /**************************************************************************************/
    #ifdef USE_FULL_ASSERT
    /**
    * @brief Reports the name of the source file and the source line number
    * where the assert_param error has occurred.
    * @param file: pointer to the source file name
    * @param line: assert_param error line source number
    * @retval None
    */
    void assert_failed(uint8_t* file, uint32_t line)
    {
    /* User can add his own implementation to report the file name and line number,
    ex: printf(''Wrong parameters value: file %s on line %d
    
    '', file, line) */
    /* Infinite loop */
    while (1)
    {
    }
    }
    #endif
    /**************************************************************************************/

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..