What IDE platform should I use?

I intend to start using some STM32 processors for motor control with a wide speed range and fast low speed response to load variations. What programming platform should I use?

I started experimenting with and using the Arduino IDE with the Arduino Nano V3 PCB a year ago as a hobby. Before that I had worked with the development of electronics with microprocessors from about 25 to 40 years back using Assembler and Pascal as programming languages. But now I learned to use C++ and this Arduino platform. For the control of a DC motor for a sewing machine, I needed to make software closer to the hardware in the MPU than the general Arduino platform support. It was also hard for me to find software able to handle full four quadrant control of an H-bridge with active current control. I managed to program this MPU to do that without damaging the functions of many of the Arduino procedures like micros(), millis(), digitalWrite, and Serial.print(). I appreciate that specifics like a bootloader are taken care of in an easy way without me knowing much about it. However I still lacks about many aspects in programming, because I still read many technical software terms, that I do not know the exact meaning of.

When I look at the github for the SimpleFOCproject, it also seems connected to the Arduino IDE: https://github.com/simplefoc
Can other IDEs be used as well?

I noticed this video about getting started with PlatformIO and SimpleFOC:
https://www.youtube.com/watch?v=3B88qCny7Kg
I don’t understand everything that is going on here, so I guess I need to study more. Do such a solution make standard Arduino procedures available?

For future projects with a STM32 processor I should like to be able to use the SimpleFOC sofware and control the motor in different ways. I also want to be able to make my own experiments with low-level programming of ADCs and timers for motor control, that includes current sensing.

I got a lot of help from the Arduino Forum to get started, and I hope I have helped others in that forum as well. Recently, I tried to ask the forum about STM32, and I got almost no response, but one guy recommended me to use the STM32 CubeIDE. I have seen some effort to use the STM32 MPUs from Arduino IDE with an open-source initiative called STM32duino. They have got a homepage and a forum, but it seems like the forum there is not that active and new development have stopped. I have now waited five days to get accepted for a login. Six years back a guy called Roger Clark was very active there, but I think he was hired by ST Microsystems, and this effort almost stopped.

Therefore, it seems reasonable to look elsewhere than the Arduino IDE for the use of the STM32 MPUs, even though I do know the Arduino IDE now. Am I right?

As far as I can see, PlatformIO and STM32 CubeIDEs are two other free alternatives. But are other IDE platforms relevant? It seems that the Stlink V3 is a popular programming and debug device to be used as well. Do you agree? Are other methods relevant?

I hope some other platforms have forums with helpful people like I made use of with the Arduino forum.

What do you recommend for me?

Arduino is both a framework and an IDE. SimpleFOC depends on the framework, but not the IDE.

Many people use VSCode with PlatformIO. I’ve used it for compiling the Marlin 3D printer firmware, but I don’t like it. I prefer Arduino IDE for small motor control projects. And CodeBlocks for larger projects, though I’ve never done any large ones using the Arduino framework. But from a quick search it looks like other people have set up CodeBlocks to use it.

STM32Cube is their official IDE, but I don’t think you can use the Arduino framework with it.

You can do low-level programming in Arduino IDE. On my computer, the file with all the hardware register definitions is C:\Arduino\portable\packages\STMicroelectronics\hardware\stm32\2.3.0\system\Drivers\CMSIS\Device\ST\STM32G4xx\Include\stm32g431xx.h

It took some wrestling to get Arduino IDE to put the main program, packages, libraries, and the build folder all in that C:\Arduino folder rather than scattering all over the hard drive. I don’t remember all the steps involved, but know that it can be done :slight_smile:

For STM32G4, look up reference manual rm0440 and programming manual pm0214 on the STM web site. There’s a lot to learn, but if you’ve done low-level programming with hardware registers before, you should be able to understand it pretty easily. ARM processors are really nice.

You can write assembly code in .s files. A general function looks like

.global Return1
.text
.thumb
.align 2
.thumb_func
Return1:
mov r0, #1
bx lr

And from C++ code, forward-declare it with extern "C" int Return1(); and then call it like normal.

I like the knockoff Stlink v2 mini you can buy on ebay. I have an official v3minie, but it’s less convenient because it doesn’t supply 3.3V power. Use STM32CubeProgrammer to operate it.

Thank you for your detailed answer!

Thanks for pointing this out. I did not know the difference up to now, but I see some definitions here:
https://www.quora.com/What-is-the-difference-between-an-IDE-and-a-framework
My interpretation is, that a part of the framework for Arduino is procedures like micros(), millis(), digitalWrite(), and Serial.print().

I am glad, that you think it is possible to work with the Arduino IDE and framework. I like to go forward stepwise in my development, so one big step for me is to change the MCU.

I looked into the possible hardware with STM32G4, and STM actually sell very cheep Nucleo development boards, that includes an on board STlink V2. I noticed these three boards:
https://www.st.com/en/evaluation-tools/nucleo-g431kb.html
https://www.st.com/en/evaluation-tools/nucleo-g431rb.html
https://www.st.com/en/evaluation-tools/nucleo-g474re.html

The board with the G474RE MPU seems very powerful by having six on-chip op-amps and five ADCs. So it seems good for development. I can see, that SimpleFOC do sell (or provide documentation on) power half bridges on shields. Do they fit such a STM development board?

So with the on-board STlink V2, should I use the STM32CubeProgrammer inside the Arduino IDE?

When I look the datasheet for these MPUs there is a lot to read with about 5-10 times the number of pages compared to the Atmega 328P.

That is correct.

Yes, in general most MCUs will be able to interface with most driver boards. Those Nucleo boards will serve you well. A bit expensive if you need a lot of them, but no problem for just getting started.

STM32CubeProgrammer is a separate program. Use it to open the .bin file from the Arduino build folder. STM32Cube IDE can probably upload automatically the way Arduino IDE does for Atmel chips, but I haven’t really looked into getting Arduino IDE or VSCode to do it on STM32. Setting up build environments is my most hated part of programming, so once I find something that works I tend not to investigate any further :slight_smile:

Indeed. The Atmel chips are excellent for beginners because they’re simple enough to learn every detail. Similar to how Gameboy Advance was for me back when I was first exposed to this kind of programming. But they are rather underpowered for motor control, especially using floating point math. The classic drone ESCs perform amazingly well with a 16MHz Atmega8A, but only by extreme optimization. The firmware is open source, but very difficult to understand how it works simonk_tgy3d/tgy.asm at master · c---/simonk_tgy3d · GitHub

SimpleFOC is written with primary focus on education rather than performance, but not ignoring it either. Modern MCUs are plenty fast to run it.

STM32G4 has more peripherals than you’re ever likely to need. It’s good to learn the details of the CPU and overall system architecture, but learn the peripherals as needed or you’ll spend all your time studying instead of producing anything useful :slight_smile: I still haven’t really learned how to use the timers without Arduino/SimpleFOC. They’re ridiculously complicated compared to Atmel, which was already moderately difficult to learn.

The ADCs are quite user-friendly, though. At least if you don’t need to trigger them from the timers for lowside current sense.

Thanks again.

I have been informed, that official Arduino board, Arduino Giga actually have got a STM32H747. Therefore Arduino brand do have a commitment towards STM32 MPUs. I think the IDE should work in some way. I hate this part as well, and I remember some of my frustrations to get things right when I started with the first Arduino Nano and needed to set a special old bootloader for it to work. :slightly_smiling_face:

Yes, I guess the timers needed for creating 6PWM is likely challenging to get initialized the right way.

I prefer to use the Arduino IDE for very small simple low dependency tests. I often then port them into platform io in MScode as I prefer the ide and additional controls.

There is a lot of extra time tied up into this method… I also swap back and forth from windows to Linux during a lot of these projects… Depends which computer I am logged into.

I am sure the Arduino IDE could be utilized totally for what I experiment with… As with most things it probably comes down to preference.