HAL_Delay works and doesn't work
I'm still very new to STM32 processors, and using CubeMX to generate my basic code structure (for TrueStudio). In the code below, if I uncomment code section A, the yellow LED blinks, but not evenly...
- At low values such HAL_Delay(100), the high time is always 100 or 101ms, but the low time is sometimes 100ms and sometimes 87ms.
- At higher values, such as HAL_Delay(500), the high time is consistently 390ms and low time is less than 1ms.
- Using HAL_Delay(1000) instead gives me the same results as HAL_Delay(500);
What am I missing here?
Now, if I comment out section A, so that section B runs, the red LED comes on, but then the code hangs at the HAL_Delay(1000) so the yellow LED never comes on. If I drop that to HAL_Delay(100), the red LED comes on again, but the yellow LED blinks at approx 2.5Hz. There are no other timers or interrupts running.
I don't know what to check next. If this is somehow expected behaviour, which doc explains how this is supposed to work?
Thanks
/* USER CODE BEGIN 2 */
// HAL_TIM_Base_Start_IT(&htim17);
// Code section A...
while (1)
{
HAL_GPIO_TogglePin(IENC1_GPIO_Port, IENC1_Pin); // Toggle yellow LED
HAL_Delay(500);
}
// Code section B...
HAL_GPIO_WritePin(IENC0_GPIO_Port, IENC0_Pin, GPIO_PIN_SET); // Red LED on
HAL_Delay(1000);
HAL_GPIO_WritePin(IENC1_GPIO_Port, IENC1_Pin, GPIO_PIN_SET); // Yellow LED on
while(1);
...