cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L462 delay in a microsecond(us)

AP_040
Senior

HAL Library provide the HAL_Delay() for millisecond delay. I want to use micro second delay in STM32L4 so how I do it? Is it available in HAL library?

12 REPLIES 12
Piranha
Chief II

> You can simply do a nop loop

No, You can't.

https://developer.arm.com/docs/dui0553/a/the-cortex-m4-instruction-set/miscellaneous-instructions/nop

NOP does nothing. NOP is not necessarily a time-consuming NOP. The processor might remove it from the pipeline before it reaches the execution stage.

Use NOP for padding, for example to place the following instruction on a 64-bit boundary.

Also it doesn't account for time in interrupts

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
HDaji.1
Senior

I tried the DWT method in my code. It basically works.

However, I have 2 issues:

  1. The delay time is not so accurate; and does not go linear with input value.
  2. I wonder if it's OK to call DWT_Delay_Init(void) multiple times.