Skip to main content
Visitor II
March 18, 2018
Question

Problem with External intetrupt flag clearing

  • March 18, 2018
  • 3 replies
  • 3664 views
Posted on March 19, 2018 at 00:25

Hello guys.

I've recently downloaded ST standard libraries for stm8s series and working with the functions.

In cube mx version when we called an interrupt the callback function automatically was executed and after that, the flag was cleared in IRQ HANDLER function at the end of the interrupt.

But in the standard library for stm8 I can't find any functions that have the flag clearing in the interrupts.

Would you please explain me how can I manage this?

    This topic has been closed for replies.

    3 replies

    Visitor II
    March 19, 2018
    Posted on March 19, 2018 at 13:21

    Clearing which interrupt flag?

    The one(s) in the CC register? Those are cleared by the iret instruction compilers place at the end of an interrupt routine.

    Some device-specific flag? That would depend on the device.

    Philipp

    Visitor II
    March 19, 2018
    Posted on March 19, 2018 at 18:57

    Clearing external interrupt that I set for port D pin 1.

    The code below was generated by cube mx in the stm32f2 board that I had.

    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);

    }

    }

    But now that im using stm8s i see no function like this in interupt source files.

    Visitor II
    March 19, 2018
    Posted on March 19, 2018 at 20:00

    The code I wrote is working and interrupt is generated every time I push the button.

    But in stm32 MCUs I put a delay before the flag interrupt cleared so the bouncing of the push button wouldn't cause the interrupt occurs again, but now I can't find where the flag is cleared and the interrupt occurs sometimes just one time and sometimes more than one time by pushing the push button.

    Visitor II
    March 19, 2018
    Posted on March 19, 2018 at 20:02

    http://www.st.com/en/embedded-software/stsw-stm8069.html

     

    This is the lib I'm using.

    Visitor II
    March 20, 2018
    Posted on March 20, 2018 at 22:42

    '

    the flag was cleared in IRQ HANDLER function at the end of the interrupt.'

    I find that to be a bad practice - I clear the flag at the beginning of the isr, so that if an event arrives while I'm still in the isr, it can be serviced - the execution will jump right back to the isr upon returning.

    If you clear the flag in the end, any events arriving before the end of the isr would be ignored.

    I wonder why st did it this way.

    Visitor II
    March 21, 2018
    Posted on March 21, 2018 at 07:42

    Hello dhenry,

    There is no such problem in ST library. If we refer to the EXTI handler, we can see such code:

    /**
    * @brief This function handles EXTI line 4 to 15 interrupts.
    */
    void EXTI4_15_IRQHandler(void)
    {
     /* USER CODE BEGIN EXTI4_15_IRQn 0 */
     /* USER CODE END EXTI4_15_IRQn 0 */
     HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
     /* USER CODE BEGIN EXTI4_15_IRQn 1 */
     /* USER CODE END EXTI4_15_IRQn 1 */
    }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    We can enter user code either before HAL_GPIO_EXTI_IRQHandler() function, which clears the flag or after it.

    And if we refer to body of

    HAL_GPIO_EXTI_IRQHandler() function, we see again that flag is cleared before HAL_GPIO_EXTI_Callback(), which can be reimplemented by user for example in main.c.

    /**
     * @brief This function handles EXTI interrupt request.
     * @param GPIO_Pin: Specifies the pins connected to the EXTI line.
     * @retval None
     */
    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);
     }
    }�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    Regards

    Szymon

    Visitor II
    March 21, 2018
    Posted on March 21, 2018 at 13:55

    thanks. sounds like the notion of the SPL clearing the flag at the end of an isr is simply wrong.