One controller driving two motors error

Hello everyone,

I am trying to build a gimbal with the simpleFOC library and need to run two BLDC motors with one controller. The problem is when I upload the code where I have initialised the second driver the stm32 stops when it reaches the line of code where the second driver is initialised. Anyone encountered the same problem?
I am using stm32f103 controller and simpleFOC 2.2 library (the 2.3 version does not compile for the stm32)

Which current sensing? Low side?

No current sensing, I’m using openloop velocity control. It starts the code and when it comes to driver2.init(); it freezes it does nothing. It never executes the rest of the code.

Hey, @Acko, welcome to SimpleFOC!

Which pins are you using, is this 3-PWM or 6-PWM?

You could add the build-flag:


to your build, and enable debug output to serial port:

void setup() {
  delay(3000); // give yourself 3s to connect the serial terminal



Please let us know what you see there…

Simplefoc v2.3 should compile for stm32 boards :smiley:
Maybe this is a memory issue, are you using a bluepill board or something else?
When you upload the sketch you can see how much memory is it using.

v2.3 is a bit larger than v2.2. so Bluepills and Arduino UNOs are a bit limited with the library features they can receive, due to their limited memory. I did not try running two motors with bluepill, this might be a limit.

However if you only use the motors in the open-loop, as its the simplest form of motion control it might still be able to fit in the Bluepill memory. If it uploads that’s a good sign.

So since it uploads, there is a higher chance that you might have chosen your PWM pins that are not compatible. If that’s the case the code proposed by @runger will tell you that, and give even some more info about the timers and channels chosen. If you are not sure what does it mean, paste it here and well have a look.

Thanks for the warm welcome @runger. I am using 3-PWM.
One thing I forgot to mention is that I am using Macbook pro from 2015. I am saying this because I use a windows PC for work and on the windows PC I am able to compile the 2.3 lib version and the code runs normally when I add the second motor and driver. When I say run normally I mean when I upload the code (to the STM32F103T8UX, this is what I have at work for the moment, but home I have STM32f103C8) motors can run. So now I am thinking I could be something in the MacOS compatibility. What do you think? @Antun_Skuric @runger

By the way on the Mac the SimpleFOCDebug::enable(&Serial); does not compile, but on windows it compiles.


I actually use MacOS myself, and don’t normally have problems working with STM32 MCUs. I don’t often use the F103 though.

I normally use PlatformIO, but ArduinoIDE works also.

It’s probably an indication that something is different between your work and home. It could be for example:

  • the framework version used (Board Manager files for STM32 MCUs) - if you’ve been using STM32 for a long time on the Mac, be aware that the Board Manager URL has changed since a few years ago. Check you’re using the up to date URL from stm32duino
  • stm32duino vs maple frameworks - please use official stm32 framework, not maple
  • library version - sounds like maybe on the Mac you’re using an older library version? Also check your libraries folder in the Arduino folder…
  • ArduinoIDE board settings: different settings for USB / Serial support can make a big difference - you may need to use SerialUSB vs Serial for example. Also check memory settings and libc settings.

These are the things I can think of offhand. But for SimpleFOC in general it should work on Mac as well as Windows or Linux…

1 Like

Thanks @runger,
I’ll check all the things. It could be that the framework is the old one since I have for a few years at least. I am using the Arduino IDE and stm32duino framework.
I’ll let you know what happens!

The C8 is quite small… 64k flash. Are you sure the error is that it can’t compile and instead is not that there is not enough space? This would also explain why the new library can’t build…

If you are using platformIO, you can specify the STM32 arduino core to a lower version, the newer versions are about 4k bigger and for me this caused issues with fitting the code in. I did this with:
platform = ststm32@~15.6.0
in the platformio.ini file. Then you can use the current version of library. I don’t know how to do the equivalent of that build flag in Arduino IDE but you can probably find something online about it. You also might be using 2 different versions of the STM32 Arduino library on your two different computers, possibly- worth a check. (I am using macos with 2.3 and it is working for me)

1 Like

I changed the stm32 URL for the new one and updated the library to the 2.3 version. Now everything is working as it should. Thanks @runger for the help!
The bad news is that somehow one of the ground pins from the driver board got loose from the stm32 and as I moved it around it attached itself to the 5V pin on the stm32 effectively killing both driver boards. The stm32 and the Serial com survived. I checked the drivers with other controller and they just jitter around. I’ll order the new ones and continue testing.
Again thanks everyone for the help!

1 Like