Support for the EVSPIN32G4 (STSPIN32G4)

Hi everyone!

First of all thank you to all the developers of SimpleFOC for their work.

I’ve been working on a project with the STSPIN32G4, and custom PCB, based off the EVSPIN32G4. The EV board has a lot of potential, high amperage, wide voltage range and hall sensor input.

Tried the example code from the driver files (Arduino-FOC-drivers/src/drivers/stspin32g4 at master · simplefoc/Arduino-FOC-drivers · GitHub), the motor would knock once after flashing with ST Link, then nothing; maybe because I have no board definition or custom linker.

Also looked through the simplefoc_funqi_example on github (GitHub - runger1101001/simplefoc_funqi_example: Sample firmware for STSPIN32G4 based BLDC driver), nice to see that CORDIC is implemented. Is there a way to enable build flags with the Arduino IDE to use the library?
Tried compiling and got ‘SimpleFOC_CORDIC_Config’ was not declared in this scope. Looked into the lib and there was: To use it, set the build-flag -DHAL_CORDIC_MODULE_ENABLED for the CORDIC to be enabled in the framework.

What else would I have to do to configure SimpleFOC to work with the board?

You can take the board definition and linkerfile from that repo also, you should use that if the board is also based on stsping4.

I think it would not build the firmware if it was lacking the linker and startup scripts? can you post your platformio.ini?

Hi @C481

Firstly, I would strongly recommend using platformio over ArduinoIDE for working with new boards. It will be much easier to configure and change things on the fly than with ArduinoIDE’s system of board files.

You could then use the funqi example as a direct starting point.

Things you’ll have to change:

  • USB setup and serial setup - may be different on your board
  • clock - although it looks like you’re both using 24MHz external clocks, so the funqi clock config may work for you
  • other functions, LEDs, inputs/outputs which will obviously be different on these two boards.

That should get you up and running for open loop and closed loop voltage modes (if you add a sensor).
For the current sensing, this will be more complicated:

  • current sensing - the EV module has a totally different setup, using the op-amps. This will need custom code specific to the STM32G4 and the op-amp configuration used, you won’t be able to use the default SimpleFOC current sensing
  • the board has voltage sensing, which we currently don’t support but you may want to add since you’re writing custom ADC code anyways

Let us know how it goes! If you feel like sharing code it might help others trying to use this board…

1 Like

Thank you for your guidance. I’ll switch to platformIO and begin with the funqi example. @VIPQualityPost - I havent got anything to present myself. I’ve only experimented with the example code in the FOC drivers rep:

#include <Arduino.h>
#include “SimpleFOC.h”
#include “SimpleFOCDrivers.h”
#include “drivers/stspin32g4/STSPIN32G4.h”

STSPIN32G4 driver = STSPIN32G4();
BLDCMotor motor = BLDCMotor(7);

void setup() {
driver.voltage_power_supply = 12.0f;
driver.init();
motor.voltage_limit = driver.voltage_limit / 2.0f;
motor.controller = MotionControlType::velocity_openloop;
motor.linkDriver(&driver);
motor.init();
}

void loop(){
motor.move(5.0f); // 5 rad/s open loop
delayMicroseconds(100); // STM32G4 is very fast, add a delay in open loop if we do nothing else
}

@runger - As soon as I’ve made some progress I’ll revisit this post, thank you for pointing me forward!

1 Like