dwt_delay
dwt_delay copied to clipboard
DWT _delay(microseconds)
The timer function hangs or stops after a few seconds if placed in a infinite while loop.Please verify.
Yep, it is possible after approx. 30 seconds @72Mhz. There was a typo in the definitions, so signed int was used instead of unsigned. Sorry for that :)
I feel lucky that i didn't hit into such situation with this delay (or reason was not obvious). Anyway, I ran some simple loops after fix: did nothing, blinked LEDs, printed to uart. And it is still running for couple of hours. Pls reopen if it hangs again.
i want to use 0.4 microseconds delay, for ws2812b led, but DWT dont support it, as it is unsigned int32
@sumitsaboo07 There's no nanodelay at the moment. I plan to add it as soon as I have any measurement tools so I can test accuracy of such delays.
You can copy-paste DWT_Delay() with other name and change a line where delayTicks
is calculated, so it looks like delayTicks = ns * (SystemCoreClock / 1e9)
.
This could give you a delay function in nanoseconds.
But consider the fact, that you can't get accurate results with 100ns delays or less: one tick is roughly 14ns @72Mhz, and you always have some ticks as an overhead you can't eliminate.
Therefore, it should suffice your need for 0.4 us = 400 ns delay. Good luck.
is there any fastled library for atollic true studio, for ws2812 as we use in arduino?? as with DWT Delay also i am not able to blink ws2812b led.?
Sorry, i dont know if there's any good fastled lib for Atollic/Eclipse. But you can use this lib directly in arduino (stm32-based, of course), and add nano-delays as i wrote earlier.
stumbled upon this by accident, because i couldn't get the DWT_init working too. i am also working with ws1812 leds, i use this library: https://github.com/hubmartin/WS2812B_STM32F3
Hi. What is exact problem and what are you trying to do? If i got it right, the lib you linked doesn't require any delay library, since it uses TIM2 to drive DMA transfer.
Another guess is that optimization could interfere. What level do you use when compiling? Must admit, I didn't test with -O1
and higher.
You can try changing vars to be volatile in DWT_Delay()
: volatile uint32_t startTick ...
.
There's definitely no need to define any variables as volatile, DWT->CYCCNT register is volatile and it's enough.
FYI, I've successfully used this code with -Os -flto
optimizations.
I have tried this on STM32F407VG. After changing header file name, build succeeded. But code gets trapped into an infinite loop inside the delay. Any idea how to fix it? THanks