Do all DigitalOut writes make it to the hardware?

A question about using the DigitalOut abstractions in mbed: does every call to DigitalOut.Write make it to the hardware? Or can toggling too fast result in “dropped” toggles?

so will:


always trigger a short pulse? or can it be that the output simply stays “true”?

Also, can i be sure that the hardware has switched a pin by the time the write call returns? Say i want to use a pin as a chipselect for an SPI communication, do i need to build in some sort of delay between setting the chipselect pin before writing to SPI to guarantee that the CS pin is set by the time the SPI bus starts communication?

//do i need some wait here? or is pin guaranteed to bee in the correct state?


interesting question, but what is the idea based on?

It probably always generate a pulse. I tried to measuring that with oscilloscope on Nucleo-F767ZI and H743ZI2. Toggling without a delay was around 7Mhz (period of 142ns), but signal was not clean and also unstable (maybe because of probe limits, I do not know).
The best stable and accurate seems to be delay of 1us (period of 2us = 500kHz) between every change.

You do not need to care of this, I think.

  • Program will not continue another line of code until the previous one is done. The Code changes value of register, the rest is done by hardware and that is very fast.
  • There are many projects where is the SPI used and I don’t remember there were an issue with timing of CS.
  • Toggle IO is simplest task and according to measurement above we can say it is able to change state in 70ns.

BR, Jan

sorry for my late reply. The question was triggered by the interest in creating a stepper driver. If I cant be sure about banging out the pulses then the stepper will lose its position.

You probably mean lose steps and that will affect the final position.
When you will not overload the motor, then it does not lose steps. So when your stepper motor loses stepps it is probably not caused by MCU or driver, but about design (undersized stepper motors or jam the rest of the hardware).

Just for example (I do not have personal experiences with that but it is based on STM32F103) a feedback via hall sensor and magnet on shaft of stepper motor - MKS SERVO42B: Open Source MKS Closed-loop Stepper Motor Installation Tutorial for Nema17 and Nema23 - YouTube

BR, Jan