3 months, 3 weeks ago.

Control classic Servo Motor with STM32 and Mbed library

I'm using STM32 F401RE board and i'm trying to do a very simple thing. I want to control a servo (0-180). The problem is that it looks like it doesn't respound to my commands.

include the mbed library with this snippet

#include "mbed.h"

PwmOut myServo(D9);

int main() {


The Servo Motor i'm using. At the beginning i though something is wrong with my board pinout or pinout meaning, but it seems like D9 is the same with PC_7. My servo is properly installed and is supplyed by 5V source. I tried many tutorials i've found online but no one worked.

If i generate the same PWM with an oscilloscope it does work.

2 Answers

3 months, 3 weeks ago.

Hi there,

That part of code need to be before the while loop I think.


Check the documentation and examples about PwmOut.

  • Try to check this page about a SERVO.
  • When you use different power supply for the servo then to power the MCU, you need to have connected all GND together I think.
  • PC_7 is standard marking of the seventh pin on Port C of the chip and D9 is marking what according to the arduino header. D9 and PC_7 is one same pin (line 137).

BR, Jan

3 months, 3 weeks ago.


I recommened to use name PC_7 -> PwmOut myServo(PC_7);

Regards, Pekka