AIO SimpleFOC Board

Hi everyone,

I’m working on a new board which is basically a merge between a stm32 BluePill board and a SimpleFOC shield, extended with 2 accurate in-line current sensor embedded in a 53mm*53 mm 2 layers PCB:

pcb_view_1


I started the design of this board because I need a true torque controller for a PMSM gimbal motor.

I plan to flash SimpleFOC in the onboard STM32 but I have some questions about the library:

  • Can someone who have worked on the development of SimpleFOC can explain what environment he use to modify and improve the library please? (If I modify the library I want to be able to make a push request to the library owner)

  • ST32DUINO is quite limited in my opinion (no use of DMA, no dual ADC support…) how can I add hardware dependent improvement to SimpleFOC without breaking the compatibly of the library with other hardware?

  • Can I add some custom code based on STM HAL library without have to fork the library?

If you have some question about the board don’t hesitate to post your question here, I will try to answer it.

Here is the listing of what I need to add to SimpleFOC for the STM32:

  • DMA ADC sampling ( as I have inline current sensor on board i want start ADC and DMA as background task for sampling motor current)
  • Torque Controller
  • Add an SPI input interface for sending setpoint, loop configuration etc.
  • High speed UART over USB with DMA (Data monitored will be sent without the help of the CPU)

Best regards

1 Like

@Antun_Skuric is by far the main contributor.

I’ve contributed a few pull requests and can tell you how I do things. I use platformio. I can’t quite understand why anyone is still using the Arduino IDE, PlatformIO is so much better (IMHO).
I did a tutorial a month or so back on how I get SimpleFOC working with platformio

If you go that way and have questions, I’d be happy to answer.

I’m also on that journey re. using low level stm32 libs. I’m looking at advance timer features (e.g. complementary pwm channels with dead time). Here is an examples repo that I’m doing some experiments in:

I’m just a hobbyist and have very little experience in any of this, but here is my too cents.

  • most people doing this professionally (and using stm32) would be using STM32CubeIDE and would not be using the arduino platform.
  • if you stick with arduino platform (which you have to if you want to use SimpleFOC) then you’ll probably still want to use STM32CubeIDE for their Device Configuration Tool. It also code generates much of the gpio/timer/dma initialization code which you would then need to find equivalents for/translate into stm32duino.
  • You mentioned DMA twice. I don’t have experience of dma but a quick check of stm32duinos low level api reveals some macros that are available e.g. LL_TIM_CC_SetDMAReqTrigger(), LL_TIM_ConfigDMABurst() etc.

SimpleFOC hides its hardware specific bits in hardware_utils.cpp btw. It mostly has PWM optimisations in there for atmega328p, esp32 and stm32.

1 Like

I’ve discussed this before, but I think this is unnecessary and would add unnecessary code to the library. By using motor.command(String here) you can change setpoint, control parameter, limits, etc. So with a few lines of code on your main code you can use whatever type of communication you want and change everything with just that one line of code. I’ve done this with my ESP32 Brushless controller - Dagor - #20 by happytm with ESP-NOW in just a few lines of code.

What do you guys think?

Thank you Owen for your help, I haven’t work yet with platformIO but it seems to be better than Arduino IDE. I installed it and it’s wonderful !

Your tutorial is a good start and save me a lot of time thank you very much! :slight_smile: Just I can’t install the last version of simplefoc with the library interface of platfomIO, the only version proposed was 1.3 not 1.6.

The stm32f chips have a powerful hardware for FOC. For example : 6 channels synchronized PWM, center aligned PWM (better than left aligned pwm used in the simplefoc default configuration), ADC conversion trigged by PWM … If go with low level lib you will be able to do beautiful stuff without overloading the CPU !

If you need some help about how things work in stm32 I can help you, don’t hesitate to ask question :slight_smile:

DMA stand for: Direct Memory Access. It’s a peripheral in the MCU than can read data form a peripheral and transfer the data somewhere in the memory without the help of the CPU. A DMA can also take data somewhere in the memory and send it to a peripheral register for example. The moment when the DMA start to read and send data can be trigged by a peripheral signal.

For example with an STM32 you can:

  • Setup an ADC trigged by a timer.

  • The ADC will convert an analog input (eg a current sensor) at a frequency fixed by the timer period.

  • When the ADC peripheral send an End of Conversion signal then this will wake up the DMA.

  • Then the DMA can be configured for autonomously take the data contained in the output register of the ADC and send this data somewhere to RAM memory.

  • All of this without the help of the CPU!

« SimpleFOC hides its hardware specific bits in hardware_utils.cpp btw. It mostly has PWM optimisations in there for atmega328p, esp32 and stm32. »

Thank you with the hint, this will be my starting point !

Hi David,

You are completely right on this point! I was not aware that simplefoc have already this interface. Thank you very much!

The only small drawback (in my opinion) is that the command interface and monitoring interface are based on textual commands which is not very optimized. This can be a problem if the user need to send a lot of data, (eg. the full state of the controller: all current, voltage, pwm, position, speed …) but it keep the advantage of the simplicity

Best regards,

I’ve spoken to @Antun_Skuric about this. The repo moved and its confused platformio which still points at old url (it seems platformio library crawler won’t follow redirects). Just raised a PR with platformio here.

In the meantime you can manually change to 1.6 by updating your platformio.ini file (you can see repo has changed from askuric to simplefoc).

# lib_deps = askuric/Simple FOC@^1.3.0
lib_deps = https://github.com/simplefoc/Arduino-FOC
1 Like

2 posts were split to a new topic: STM32 Center-Aligned and 6PWM

Platformio have fixed the issue @robin2906 mentioned above. My workaround is no longer required as the latest library should be available in platformio

2 Likes

@robin2906 Would it be possible to control hoverboard motors with your design ?

Thanks.

Hi,

Unfortunalty this board withstand is only 2A. An hoverboard need way more current than 2 Amps.

I think the command interface is ok. You can always directly change the values of the motor object if you prefer an communication protocol that does not involve strings.
It’s the monitoring interface that I would like to see abstracted in a similar way to the Sensors/Encoders - I use OSC to control SimpleFOC, since it’s easy to make UIs for quick tests. It would be nice to be able to create a OSCMonitoring class.

In terms of SPI and other ways to talk to SimpleFOC, whether this makes sense or not depends on the application, right? If you’re creating an ESC or motion controller, which will be be controlled by a larger PC or another microcontroller, then you want an interface like SPI to control the SimpleFOC firmware on the ESC.
If you’re adding SimpleFOC to an existing firmware, then that firmware can talk directly to the library, and you don’t need an interface.
If you’re trying to control from a PC, things like ASCII Serial and OSC make more sense.

In terms of standard interfaces to ESCs, there is RCPWM, normal PWM based interface used by RC-controllers, also in faster digital variants, and there is something called UAVCAN via CAN-Bus…
There doesn’t seem to be much standardization.

Is OSC this http://opensoundcontrol.org/? Where can I see an example simpleFOC interface by OSC?

I’ll start a new thread…