2022-09-16 10:51 PM
This happens at randomly. Spent more than a month trying to figure out the issue and never suspected DWT. When I commented out DWT everything works fine now. Can someone educate me on why this is happening and how to avoid it? Thank you for your time.
2022-09-17 02:43 AM
Probably related to how the counter wraps and how you scope your delay loops
2022-09-18 08:58 PM
I start this counter at the beginning of my code and during LCD writes I use the uSec delay for clocking "enable" pulse. I am using systick and timer3 for delays of 1mSec and 10mSec respectively. I have an RS485 bus through which I communicate with 4 devices. Everything works fine and suddenly communication on RS485 line stops and after a few minutes starts as normal (controller does not reset). I found interrupts to be getting executed. Can you please educate me on what happens when this counter wraps? This happens at random times. Sometimes after a few hours.
2022-09-18 09:12 PM
It wraps like any other uint32_t count would.
I would suspect you're doing the uSec delay incorrectly.
You'd want to dereference the count so you can do the comparison, not compute an end point.
2022-09-18 11:09 PM
Hi Tesla DeLorean,
"I would suspect you're doing the uSec delay incorrectly." This could be the reason!!!. Will check. I am using this delay for LCD enable pin control and as you mentioned, there could be an issue here. Just to mention the HAL_Delay provided in the HAL libraries also has an issue. This delay reads the current tick count and adds the asked delay and waits for the tick count to cross this value. What if the added value wraps to a lower count? I think this is what is happening in my case too. Wrap happens much faster in DWT case. Thank you.
2022-09-19 05:28 PM
> This delay reads the current tick count and adds the asked delay and waits for the tick count to cross this value.
That is just not what the HAL_Delay() does:
2022-09-19 11:16 PM
Hello Piranha,
Thanks for the update on HAL_Delay. I will go through the code.