niekiran / MasteringMCU

Udemy Mastering Microcontroller Course Repository
392 stars 374 forks source link

GPIO driver code jumbled up and unnecessarily invoking trigger #10

Open NavadeepGaneshU opened 2 years ago

NavadeepGaneshU commented 2 years ago

https://github.com/niekiran/MasteringMCU/blob/2742e0297de67851bda72892beed23cd800d1615/Resources/Source_code/Workspace/stm32f4xx_drivers/drivers/src/stm32f407xx_gpio_driver.c#L429

The tutorial shows it correctly, but the committed code has issues. I was confused by this mismatch while comparing the code. This is as shown in the tutorial:

/*********************************************************
 * @fn      - GPIO_IRQHandling
 * @brief       - Interrupt handling
 *
 * @param[in]   -
 * @param[in]   -
 *
 * @return      - 
 *
 * @notes       -
 * /
void GPIO_IRQHandling(uint8_t PinNumber)
{
 //clear the EXTIPR register
    if(EXTI ->PR |= (1 << PinNumber))
    {
        //clear
        EXTI ->PR &= ~(1 << PinNumber);
    }
}
panoskalf commented 2 years ago

This register is actually a special case and it is cleared by writing 1. You can find this mentioned in the register details in the reference manual.

image

https://github.com/niekiran/MasteringMCU/blob/2742e0297de67851bda72892beed23cd800d1615/Resources/Source_code/Workspace/stm32f4xx_drivers/drivers/src/stm32f407xx_gpio_driver.c#L429

The tutorial shows it correctly, but the committed code has issues. I was confused by this mismatch while comparing the code. This is as shown in the tutorial:

/*********************************************************
 * @fn        - GPIO_IRQHandling
 * @brief     - Interrupt handling
 *
 * @param[in] -
 * @param[in] -
 *
 * @return        - 
 *
 * @notes     -
 * /
void GPIO_IRQHandling(uint8_t PinNumber)
{
 //clear the EXTIPR register
  if(EXTI ->PR |= (1 << PinNumber))
  {
      //clear
      EXTI ->PR &= ~(1 << PinNumber);
  }
}