Page 1 of 1

micros() Resolution

Posted: Tue Feb 23, 2021 11:27 am
by Ali
Hello:

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

Re: micros() Resolution

Posted: Tue Mar 02, 2021 6:01 am
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.

Re: micros() Resolution

Posted: Tue Mar 02, 2021 1:28 pm
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.
[...]

Re: micros() Resolution

Posted: Fri Apr 02, 2021 12:27 am
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

Re: micros() Resolution

Posted: Fri Apr 02, 2021 7:22 am
by fpiSTM
STM32 mcu based on cortex-M0 does not have DWT.
Good article:
https://www.carminenoviello.com/2015/09 ... nds-stm32/