2019-11-16 05:10 AM
Hi every body, how can I create a microsecond delay in STM32f0? ( this MCU has not DWT register)
Thank you
2019-11-16 05:21 AM
Use any other free-running TIM to delta progress of time.
Clock a 1 MHz or faster to improve resolution. Don't interrupt. Remember most TIM here will be limited to 16-bit.
2019-11-16 05:34 AM
Thank you, could you please tell me the details or give me an example?
2019-11-16 06:12 AM
I've posted examples and discussed this before. It really shouldn't be that complex to think through..
Set the TIM up in Timebase mode, set the Period as maximal, ie 0xFFFF
Set the Prescaler as MHz-1, ie 31 if the bus clocks at 32 MHz, the tick time should be 1us
void delay_us(uint16_t us)
{
uint16_t start = TIM2->CNT;
while((TIM2->CNT - start) < us); // rebase, then compare
}
2019-11-16 07:25 AM
Thank You, Please check my CubeMx config, is it correct?
my HCLK = 48Mhz
2019-11-16 11:07 AM
Looks reasonable, not using CubeMX here. Likely some timebase examples under the HAL CubeF0 trees also