FOC algorithm for STM32 Cube IDE

Good morning community!

I want to start a project at university on STM32 Cube IDE platfotm, but my skills at programming aren’t incredibly good, therefore my progress is very slow.

My idea is to first create a program that enables me to control the velocity of the drone propeller (the motor).

Card: STM32G431CBUX
Motor BLDC (brushless)

I would be very thankfull if any of you can help me. :slight_smile:

1 Like

Hello Arthur,

Thank you for the question, this is very interesting.

There are a lot more experienced people here on this board than me, however, could you please provide a little bit more details about this project?

STM32G431CBUX is an MCU, so which board do you intend to use? Have you chosen the board? It may be helpful if you provide the manufacturer / model?

Same for the motor.

Also, the propeller diameter, are there going to be more than one propellers, the power required, etcetera.

Last but not the least, the Cube IDE is a whole suite of tools. Are you using Arduino with the Cube IDE to flash the chip or you intend to use the native Cube IDE exclusively?

The more details you post, the more help you will get here.

Once again, great project.


I wish you the best of luck.
I bought some demo-boards with this MCU myself, only to find out I will never have the required software.
This MCU has some extra’s which make it a better motorcontroller : a DSP coprocessor and an arithmetic unit.
Unfortunately, GCC does not understand coprocessors.
It just generates generic ARM Thumb-2 16-bit instructions.
Keil compilers exceed my budget.

I had a quick look at the B-G431B-ESC1 board some times ago. It is based on the STM32G431CB. I think its main feature is that you don’t need to program it directly:

  • you use ST graphic tools to tune the FOC parameters (to fit your motor),
  • you use another board (for example a Nucleo-64 if you want to stick to ST boards) to command the B-G431B-ESC1 using PWM, CAN or UART.

Hello Valentine,

Thank you for your response. This is the technical info:

  • B-G431B-ESC1 Discovery kit
  • STM32G431CB microcontroller
  • L6387 driver
  • STL180N6F7 power MOSFETs
  • BLDC motor (FMT F15844).

For now, the power required and the propeller diameter are not so important, as I just want to be capable tu make the motor spin at different velocities. One we get that working properly we’ll buy some propellers and we’ll therefore study the power required to make them spin.

We intend to use native Cube IDE exclusively.

Again, thank you for your time and support.


Thank you for sharing your experience with me, Jan. I’ll try my best.

Thank you for your response @quentin.

I’m using the same board (the B-G431B-ESC1 Discovery kit). Could you explain me more about using FOC parameters and PWM. It’s exactly what we have to do.

Thank you again,


@arthur ,

I suggested you to go the ST way because you said you were a beginner and wanted to stick to STM32CubeIDE. Unfortunately, I’m inexperienced in the ST motor control ecosystem, so I can’t help further. According to ST marketing documents, it’s super easy to tune a BLDC motor with the provided automatic GUI tools, without any programming knowledge. If this is true, all you have to do next is to use a Nucleo board to send commands to the B-G431B-ESC1, using UART for example.

To get additional help on this, you might want to try the ST website or the ST community forum. Here, I think people are more knowledgable in going the SimpleFOC way, i.e. running the SimpleFOC library on the B-G431B-ESC1 using Arduino or PlatformIO IDEs. There are already a few post about this (you can try “B-G431B-ESC1” in the search bar).