micros() Resolution

All about boards manufactured by ST
Post Reply
Posts: 1
Joined: Tue Feb 23, 2021 11:24 am

micros() Resolution

Post by Ali »


Is there any way to know the resolution of micros() for the Arduino Portenta H7 (which employs STM32H747)? I have checked for other boards e.g. Arduino Nano which is mentioned as 4 uS. However, I couldn't find one for Portenta H7.

Is there any way to measure or look for that
Posts: 6
Joined: Wed Mar 18, 2020 4:46 am

Re: micros() Resolution

Post by Ollie »

I am not aware of the H7 Arduino library implementation. You should get 1 us resolution. If you need 5 nanosecond resolution (with 400 MHz clock) then you can use the following two macros

Code: Select all

#define initCycleCounter() \
    CoreDebug->DEMCR   |= CoreDebug_DEMCR_TRCENA_Msk; \
    DWT->CYCCNT         = 0; \
    DWT->CTRL          |= DWT_CTRL_CYCCNTENA_Msk

#define readCycleCounter()  (DWT->CYCCNT)
These macros do work on all STM32 processors and I have been using them for many years.
Posts: 10
Joined: Fri Jul 10, 2020 10:11 pm

Re: micros() Resolution

Post by Edogaldo »

@Ali I think here is your answer: https://www.arduino.cc/reference/en/lan ... me/micros/
On the boards from the Arduino Portenta family this function has a resolution of one microsecond on all cores.
Posts: 39
Joined: Sat Jul 04, 2020 7:46 pm

Re: micros() Resolution

Post by dannyf »

These macros do work on all STM32 processors
I think some lower end chips don't have dwt.

In those cases you can use a free running timer. Like systick
User avatar
Posts: 975
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 44
Location: Le Mans

Re: micros() Resolution

Post by fpiSTM »

STM32 mcu based on cortex-M0 does not have DWT.
Good article:
https://www.carminenoviello.com/2015/09 ... nds-stm32/
Post Reply

Return to “STM boards (Discovery, Eval, Nucleo, ...)”