incorrect micros() value for stm32f411re

Post here first, or if you can't find a relevant section!
ldelana
Posts: 7
Joined: Mon Nov 23, 2020 6:21 pm

Re: incorrect micros() value for stm32f411re

Post by ldelana »

I think that stm32duino sets everything for their need to tune F_CPU 216000000 but may I am wrong...
I not used cubemx btw for stm32f767zi following is the default clock config

Image
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: incorrect micros() value for stm32f411re

Post by mlundin »

If you check the STM32Duino source code for the variant NUCLEO_F767ZI: https://github.com/stm32duino/Arduino_C ... ariant.cpp you can see that it is configured with the HSI clock as source for the PLL. This clock has an accuracy on the order of 0.5 to 1% that can explain your results, that would mean your results are not a problem with the micros() code, but depends on the core clock configuration for the board.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: incorrect micros() value for stm32f411re

Post by fpiSTM »

You could not compare mbed and Arduino. They are really different and does not have the same goal and behaviour. MBED is an OS not the STM32 core. ;)

I guess one of your issue is simply the usage of the Serial.
Serial uses IT with a priority of 1 while EXTI uses a priority of 6 per default. So your isr can be blocked/interrupted by the Serial one.

You can try to change those priorities.
https://github.com/stm32duino/wiki/wiki ... ity-values

Code: Select all

-DEXTI_IRQ_PRIO=2 -DUART_IRQ_PRIO=3
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: incorrect micros() value for stm32f411re

Post by fpiSTM »

Also, your OP is about F411? why talking about F7 ?
For the system core clock config you can redefine your one in the sketch.
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: incorrect micros() value for stm32f411re

Post by mlundin »

Sorry, I dont have a problem, but @ldelana did mention the 767ZI in some earlier posts and I was simply explaning his results. Interference from Serial IRQ so make measured intervals both longer and shorter, depending on whether the first or second time sample is delayed.
ldelana
Posts: 7
Joined: Mon Nov 23, 2020 6:21 pm

Re: incorrect micros() value for stm32f411re

Post by ldelana »

Also, your OP is about F411? why talking about F7 ?
F7 included because then I tried the same code with 3 boards, including F767zi with follow summary results:
- stm32f103 ( correct )
- stm32f446re ( problem )
- stm32f767zi ( problem )
actually I have wires connected to F7.
You could not compare mbed and Arduino. They are really different and does not have the same goal and behaviour. MBED is an OS not the STM32 core.
That's true I was only wondering if they used some different clock setting ( https://github.com/ARMmbed/mbed-os/blob ... l_rcc_ex.h ) but watching at source of read_us() https://github.com/ARMmbed/mbed-os/blob ... api.c#L439 and https://github.com/ARMmbed/mbed-os/blob ... api.c#L145 I'm realizing that the value of `us` retrieved through mbed might not affected by the intrinsic 1% accuracy of 16mhz internal rc oscillator of nucleo-144 stm32f767zi as correctly stated by `mlundin` and also described in `Clocks and startup` datasheet section of mcu, because the read_us() value constantly smooth that error in the time while with stm32duino I read the true actual clock info subjected by the error.

I wondering if using an external 16Mhz clock could fix the issue, I don't know exactly how to do this, I read the user manual of the nucleo-144 in the `Oscillator from external PF0/PH0` and I understand about how to toggle SB8/9/112/148/149 but I don't understand exactly how to connect the two pin crystal to the only pin 29 of CN11... In the past I did used external crystal with atmega that have two pin for that XTAL1, XTAL2.
-DEXTI_IRQ_PRIO=2 -DUART_IRQ_PRIO=3
Thanks `fpiSTM` for suggestion, I tried changing these in boards.txt flags, recompiled checking they used but results still the same.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: incorrect micros() value for stm32f411re

Post by fpiSTM »

You can try to use the HSE by pass on the nucleo F7.
Simply add the new configuration generated thanks CubeMx on top of your sketch:

Code: Select all

extern "C" void SystemClock_Config(void) {
// HSE bypass config
}
dannyf
Posts: 447
Joined: Sat Jul 04, 2020 7:46 pm

Re: incorrect micros() value for stm32f411re

Post by dannyf »

stm32f1
those chips have DWT and you can get timing resolution down to ns -> at 72Mhz, you get 13.9ns
MoDu
Posts: 16
Joined: Mon Jul 20, 2020 10:43 pm

Re: incorrect micros() value for stm32f411re

Post by MoDu »

I've had trouble with DWT timing in the past, because of naughty Arduino libraries blocking the interrupts and skeweing the timer counter. Nowadays I just use the RTC if I want accurate time in periods longer than ~100 ms.
Post Reply

Return to “General discussion”