HAL_Delay works and doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-05 9:35 AM
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);
...
- Labels:
-
STM32Cube MCU Packages
-
STM32F0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-05 9:55 AM
HAL_Delay typically depends on the SysTick interrupt, that it fires and is configured correctly. Usually via HAL_Init()
I'd suspect the tool chain or generated code.
Review what else is on the pin.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-05 10:10 AM
If you use HAL_Delay inside an interrupt routine, havok behaviour may be seen. Check your ISRs and callbacks if any outside the shared code extract.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-05 10:11 AM
Thanks Clive. I completely re-created the project in CubeMX in a new directory, with a new name. All I have set is SWD enabled and 2 outputs for the LEDs. And I set the FCLK to 48MHz. Image below shows what I have. That's all. No other timers or peripherals enabled. Same exact behaviour.
I'm going to see if I can download an older version of CubeF0 to see if that makes a difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-05 10:12 AM
I have no interrupts set. See my response below to Clive about my configuration.
Thanks.
