Tricky GPIO Input bug in Nucleo STM32F4 bare metal project
Hi,
I at a high level I have designed a program to toggle the user LED on PA5 if a gpio input sees a high signal (shorter than 150ms) on PA0.
The program works well most of the time except in some instances when it will miss an input pulse entirely, seemingly for no reason. I have checked my timer delay function and even switched to a for loop style delay. This allowed me to validate that my timer was not the issue.
The bug only occurs when the output pin is low. (Never when it is high)
Scope Captures of Normal Operation (Input - yellow; Output - blue)

Scope Capture of the Insidious Bug
Here is the main function code and I've attached a copy of the project below also.
#include <Input_Capture.h>
#include <tim.h>
#include "stm32f4xx.h"
int main(void)
{
/* Set GPIO Pin A0 to Input Capture Mode */
gpio_a_init();
IOPA0_Input_cfg();
IOPA5_Output_cfg();
tim3_150ms_init();
while(1)
{
////////// The LED CLAPPER LOGIC ///////////
/* If a high signal is detected on PA0,
* and we aren't already turning the LED on */
if ((GPIOA->IDR & GPIO_IDR_ID0) && !(GPIOA->ODR & GPIO_ODR_OD5))
{
/* Turn on the LED */
GPIOA->BSRR = GPIO_BSRR_BS5;
/* Wait 150ms */
tim3_150ms_delay();
//for(int i = 0; i<1000000; i++){/*Do Nothing */__NOP();}
}
/* If a high signal is detected on PA0,
* for this case, we know the LED will be on */
else if (GPIOA->IDR & GPIO_IDR_ID0)
{
/* Turn off the LED */
GPIOA->BSRR = GPIO_BSRR_BR5;
/* Wait 150ms */
tim3_150ms_delay();
//for(int i = 0; i<1000000; i++){/*Do Nothing */__NOP();}
}
else
{
/* do nothing */
}
}
}
Any help is much appreciated! :)

