Really strange timing. What could be causing it?
Colleagues,
Here’s a code snippet which changes the state of two GPIO lines with delays in between.
[My actual firmware has more code, and I’ve reduced it to this condensed example which still has the issue.]
HAL_GPIO_WritePin(LED_DRIVER_ENABLE_GPIO_Port, LED_DRIVER_ENABLE_Pin, GPIO_PIN_SET);
HAL_Delay(1);
HAL_GPIO_WritePin(LED_STATUS_GREEN_GPIO_Port, LED_STATUS_GREEN_Pin, GPIO_PIN_SET);
HAL_Delay(1);
HAL_GPIO_WritePin(LED_DRIVER_ENABLE_GPIO_Port, LED_DRIVER_ENABLE_Pin, GPIO_PIN_RESET);
HAL_Delay(1);
HAL_GPIO_WritePin(LED_STATUS_GREEN_GPIO_Port, LED_STATUS_GREEN_Pin, GPIO_PIN_RESET);
The resulting picture on the oscilloscope looks quite wrong.
oscilloscope screenshot of GPIO outputs
Legend for the oscilloscope plot:
Channel A is LED_DRIVER_ENABLE (PA3)
Channel B is LED_STATUS_GREEN (PB0)
The most troubling part is that the LED_STATUS_GREEN goes up before LED_DIVER_ENABLE on the oscilloscope. In the code LED_DIVER_ENABLE precedes LED_STATUS_GREEN. [It's more visible in my update below.]
In addition, the first call to HAL_Delay(1) produced a 0.1ms delay instead of expected 1ms. The second and third calls to HAL_Delay(1) produced 4ms and 2ms delays.
What could be causing these issues?
Any suggestion, insight or reference is really appreciated!
STM32G474. I ran the code on two copies of the board, and the microcontrollers are from the same reel. I see the same anomaly on both of them.
The compiler is CubeIDE v1.15.1 . The optimization is -O0 (no optimization, which is the default setting). Let me know if I should provide more information.
Sincerely,
- Nick
