Porting to cheaper STM32F401 possible?

I have projects ongoing requires lower cost and minimal size. I was thinking if it is possible to port the programe to cheaper F401 just for one motor application.
I could change the PIN configuration by CubeMX, I dont know how much work left under Freertos?
someone give me a hint?

Hi,
I’m in the process of going the other way and migrating to an H series chip. The port to another STM32 chip should have been straight forward. However the firmware libraries have changed just enough to be a bit of a pain if you’re planning on running the latest and greatest. The USB endpoint control is the biggest issue I’ve found so far. The Odrive currently runs FreeRTOS v9, the later firmware libraries include v10. This hasn’t been a major issue, for the most point some tightening up of the input arguments (more consts so warnings of casting to consts of non consts) and slight changes in some of the APIs.
If you want to do it really quickly, try and find the library STM32Cube_FW_F4_V1.21.0, this should keep your code changes to a minimum.

Why an f4? If you’re looking at cost, have you considered an F3? They have the same core and DSP but reduced memory and no ethernet and as a bonus they’ve improved some of the analog hardware.

Cheers
Simon

Hello Simon,
Thank you for all the information.
F3 is of course a great option. Another possibility is G431/474, they are F3(M4) core, just with more integrated analog divices(like 3 amplifiers). I have did some projects with that. Just worry about the compatibility is worse than F4.
If this works, would it be possible using M3 core, like STSPIN32F0 serie, just with all the devices include pre-driver, we dont even need DRV8031. Disadvantage is the clock frequency is just 48 MHZ.

P.S.: how difficlut is that remove DRV8301? Instead I will use a simple pre driver, which doesnt require SPI communication or Fault report and so on.

BR
George

Hi George

I think the M3 core may work but you would need to characterise the threads (max and median execution time, and memory requirements). I think the current ODrive code takes advantage of the floating point unit so you would also take a significant hit if the chip you use does not use an FPU. You can see what sort of hit you’d take by disabling the the FPU for the current software and again characterising it.

The DRV8031 chip has several key features so you would have to make sure you have those covered. In no particular order (and may not be complete):
Differential to single ended and gain stage for the shunt resistors x2
5V power rail
bootstrapping the FETs
deadband timing - can do in the microcontroller though
fault detection - you said you don’t need this so you’ll have to modify the code to not need the fault detection

I think the G series are based on the M0+ Cortex, again no FPU. The other issue is the ADC count, you have the channels but only 1 ADC so your samples will no longer be in sync and would have to be staggered and timing is a big requirement here.

I hope this helps
Simon

Hello Simon,

FOR G4 SERIE
I double checked the datasheets, it’s indeed M4 core and with FPU, and integrated Amplifiers support at least 3 channal ADC. (I made some ESCs with st official MCSDK code, works just fine)

FOR M3 CORE
Yes, the FPU is exactly my concern. For making it work, it would take alot of effort. For me is not worthy at the moment.

FOR DRV8031
Yes, DRV 8031 has great feutures which you listed. However, the size takes volume, and its “all in one” design makes difficults for me while doing the PCB layout (specially the power and the signals cross each other…) . And it uses an extra SPI communication, which takes GPIO resources from the MCU. In some cases i would rather use some seprated solutions…

BR
BR George

Hi George,

Thank you for the clarification,

I was having a ‘moment’ and was looking at the g0/1 datasheet. the G4 does look like quite a suitable chip. It looks like it’s been designed for motor control. The analog looks like it’s overkill which is good and the PWM features make the 8031 almost superfluous, just need to sort out FET drivers, power supply, and your preamp arrangement for the current sensing. How does the price stack up against the f4’s?

Cheers
Simon

Hello Simon,
G4 is F3 upgrated version which designed for motor control, with FPU und Cordic. Since it integrated 3 amplifiiers, I was thingking the DRV8031’s 2 channal OPs are redudant.
The price is 3.x dollars from retailer, would be controlled under 3 dollars with higher quantity. Some what like F405 (right ?).

BR
George

Hi George,

You could certainly use the op amps as a gain stage but you’ll need either measure either side of the shunt resistor meaning you need 2 gain stages per shunt (minimum of 2 shunts) or use an external differential opamp to feed the gain stage.

Have you taken a look at ST’s speed controller eval board?

I’m not sure how easy it would be to port the ODrive code to it, but at least they have a reference board you could play with.

Cheers
Simon

Hello Simon,

I only wanted a single motor solution, so 3 OP AMP are more than enough. Would it improves the behavior of motor, if 3 shunts solution is applied instead 2 shunts, I dont know. I would like to know your opnion if you have did the comparison.

Yes, this board I have it in hand, and more than that is I have simmilar layout PCBs which is designed by myself.
I would do it in my spear time. However, I have very limited exprience of Freertos. So maybe I would consult you about the sturcture of the programe further.

BR
George

Hi George,

I’m sure I’ll be corrected if I’m wrong but I think measuring the current across all 3 phases offers better control resolution (faster response and lower losses) as you can measure the power in each coil rather than estimating the third phase when you only have 2 phase measurements. Unless you’re looking for rapid changes in speed or have a long set of leads to the motor, 2 simultaneous phase measurements are often sufficient.

FreeRTOS is pretty straightforward to use and in this application it’s not doing much other than scheduling the ODrive tasks using a couple of API’s. Changing FreeRTOS versions is normally pretty straightforward. The bigger issue may be changing to a new MCU’s firmware libraries as the interfaces are mostly (but not completely) common as they do have some variation.

Feel free to drop me a message if you want some more advice on FreeRTOS and the like.

Cheers
Simon

@GeorgeBayern, I am also trying to build a single motor solution and for that I considered the STM32F303CCT6 as a replacement for the STM32F405. Just wanted to know if you were able to port the oDrive code to STM32G4.