Arm Mbed OS support forum

Wait function shows incorrect timing on Nucleo board

Hello Community,

I’m in need of some simple pin toggle sequences. Therefore I’ve ordered a Nucleo F103RB board and started “programming” with the MBED online compiler. Here is the code:

`#include “mbed.h”

InterruptIn mybutton(USER_BUTTON);
DigitalOut myled(LED1);
DigitalOut rx(D8);
DigitalOut idle(D9);
DigitalOut tx(D10);

volatile uint32_t counter = 0; //How often did we cylcle through our routine

void pressed()
counter = 0;

int main()
while (1) {
rx = 1;
rx = 0;
idle = 1;
idle = 0;
tx = 1;
tx = 0;
printf(“Sequence No. = %zu\n”, counter); //Print out result

nothing big. Compilation went without errors, so far so good. Unfortunately the timings are completely off. The 150us wait is a total of 34ms. The 1ms is expanded to 65ms between high and low transitions of the port. The 3rd port which should be set and reset after 150µs is also 65ms long. Next I’ve loaded a demo program of the MBED compiler which blinks an LED. It also uses the wait functions and the timings are again totally wrong.

So is it a bug in the compiler? Am I missing some necessary configurations for the Nucleo or might it be a typical case of PEBCAK?

Yours faithfully,

Hi Chris,

That’s weird. F103 should be a well tested target… Could you repost this question here? Then ST will also see the question, will be faster. Unfortunately I don’t have this board at hand, so I can’t verify myself.

Colleague suggested this:

hard to say without debugging, but it seems like timer implementation is missing a prescaler somewhere

ST should be able to verify whether that makes sense.

Hello Janjongboom,

check! Posted the question as suggested in the other forum.
What I have figured out so far:

  1. tried to more F103 boards to rule out a hardware problem. They show the same behavior regarding the timing problems.
  2. switched over to a F411 nucleo. Timings are correct.

To keep the conversation together, I will close this topic here and move over to the new discussion