EVLSPIN32G4-ACT Hardware Support

Hi,

I have a similiar design based on EVLSPIN32G4 it have STSPIN32G4 MCU. My hardware is almost identical with EVLSPIN32G4 board schematic. I just removed CANBUS support on hardware and changed MOSFET’s with some other brand.

I am having trouble to drive motors with my design but i am not sure if its simple foc or hardware related.

My main.cpp code on Platformio is like this:

#include <Arduino.h>

#include "SimpleFOC.h"

#include "SimpleFOCDrivers.h"

#include "drivers/stspin32g4/STSPIN32G4.h"

#include "stm32g4xx_hal.h"

#include "HardwareSerial.h"

STSPIN32G4 driver = STSPIN32G4();

BLDCMotor motor = BLDCMotor(7);

HallSensor sensor = HallSensor(PB6, PB7, PB8, 7); //THESE ARE MY HALL SENSOR PINS

LowsideCurrentSense currentSense = LowsideCurrentSense(0.0020, 10, PA2, PB1, _NC); //THESE ARE MCU INTERNAL OPAMP OUTPUTS, IF I USE PA6 INSTEAD OF PB1 IT GIVES THIS ERROR "STM32-CS: ERR: Analog pins dont belong to the same ADC!"

void doA(){sensor.handleA();}

void doB(){sensor.handleB();}

void doC(){sensor.handleC();}

Commander commander = Commander(Serial1); //"NORMAL "Serial" DOESN'T WORK. "Serial1" WORKS WITH "-DSERIAL_UART_INSTANCE=1" ON PLATFORMIO.INI FILE.PA10 AND PA9 ARE SERIAL CONNECTION PINS

void onMotor(char* cmd){ commander.motor(&motor,cmd); }

void setup() {

Serial1.begin(115200);

motor.useMonitoring(Serial1);

pinMode(PC14, OUTPUT); //PC14 IS ONBOARD LED FOR JUST FOR VISUAL FEEDBACK IF MCU EXECUTES CODE.

digitalWrite(PC14, HIGH);

delay(1000);

sensor.init();

sensor.enableInterrupts(doA, doB, doC);

motor.linkSensor(&sensor);

driver.voltage_power_supply = 12; //I HAVE 12V PSU

driver.pwm_frequency = 32000;

driver.init();

motor.linkDriver(&driver);

motor.voltage_sensor_align = 1;

motor.controller = MotionControlType::velocity;

motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

motor.init();

currentSense.linkDriver(&driver);

currentSense.init();

motor.linkCurrentSense(&currentSense);

Serial1.println(sensor.getVelocity());

motor.initFOC();

commander.add('M',onMotor,"my motor motion");

}

void loop(){

motor.loopFOC();

motor.move(5);

}

My platformio.ini file as follows:

[env:genericSTM32G431CB]
platform = ststm32
board = genericSTM32G431VB
framework = arduino
lib_deps = 
	askuric/Simple FOC@^2.3.4
	simplefoc/SimpleFOCDrivers@^1.0.8
    Wire
	SPI
board_build.ldscript = ./variant/ldscript.ld

monitor_speed = 115200
monitor_eol = LF

build_unflags = -Os
build_flags = 
    -Ofast
	-DSIMPLEFOC_STM32_DEBUG
	-DPIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -DUSBD_USE_CDC
    -DUSBCON
	-DSERIAL_UART_INSTANCE=1
    -DHAL_CORDIC_MODULE_ENABLED
    -DHAL_LPTIM_MODULE_ENABLED
	-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
	-D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF

Serial output of above code:

MOT: Monitor enabled!
TIM1-CH1 TIM1-CH1N TIM1-CH2 TIM1-CH2N TIM1-CH3 TIM1-CH3N score: 1
STM32-DRV: best: TIM1-CH1 TIM1-CH1N TIM1-CH2 TIM1-CH2N TIM1-CH3 TIM1-CH3N score: 1
STM32-DRV: Syncronising timers! Timer no. 1
STM32-DRV: Restarting timer 1
MOT: Init
MOT: Enable driver.
STM32-CS: Using ADC: 1
STM32-DRV: Stopping timer 1
STM32-DRV: Stopping timer 1
STM32-DRV: Stopping timer 1
STM32-DRV: Stopping timer 1
STM32-DRV: Stopping timer 1
STM32-DRV: Stopping timer 1
STM32-DRV: Syncronising timers! Timer no. 1
STM32-DRV: Restarting timer 1
0.00
MOT: Align sensor.
MOT: Failed to notice movement
MOT: Init FOC failed.

My bench PSU is set to 12V and 3A limit, when i reset ESC it draws about 390mA for some time and doesn’t rotate motor.It halts on Init FOC failed. :expressionless:

Current sense thing was a bit complex so i tried it also on openloop with below code:

#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
}

In openloop configuration it draws about 138mA on PSU and doesn’t rotate also. Motor can be rotated with hands with soft ressistance, i can feel the pole points.

Another thing that i want to point that if i start a new project on platformio and upload same FOC code above serial output complains about this:

MOT: Monitor enabled!
MOT: Init not possible, driver not initialized
ERR: Low-side cs not supported!
0.00
MOT: Align sensor.
MOT: Failed to notice movement
MOT: Init FOC failed.

ERR: Low-side cs not supported! i searched web and forum but i cannot find anything related with it.

If i clone this repo and use above FOC code this Low-side error thing doesn’t happen. But as i described above it draws about 390mA for some time and doesn’t rotate motor.

I am pretty confused and puzzled about this. In past i used B-G431B-ESC1 with Simple FOC which i expect this board behavior should be similiar.

Could someone point me right direction?

Thanks in advance.

Could you please post your schematics and perhaps some pictures?

Also, do you have an oscilloscope?

Cheers,
Valentine

Thanks for reply. Sure thing!
Here is my schematic.

Here are some board photos:



I have 4 channel Rigol DS1054Z.Here some screenshots of output phases:(This screenshot belongs to velocity openloop)

What should i measure next? Are those waveforms on phases ok?

Many thanks.

Great, let me check the schematics, but they don’t seem OK, they are all on top of each other. Do they pulsate, does the duty change, like, they stretch and shrink, or they are stuck at that?

Can you measure the PWM from the MCU, one phase, low and high (2 signals) and the 3rd the phase from the 1/2 mosfets? Open velocity please.

image

Valentine

I don’t see any obvious problems with the schematics, it appears very competent. Let’s see the waveforms from the three test points above. There might be an issue with the routing and the PCB, but that’s beyond my ability to debug over a text message, that needs hands-on with the gerbers and a microscope. Also, JLC is usually pretty good at what they do so that’s very unlikely that there is an SMD issue.

Cheers,
Valentine

PS next time you make a dev board please expose those as test points. I see test points on the photo but can’t tell what’s what. If you haven’t, make test probes from jumper cables (I mean thin wires not car battery cables :slight_smile: ), shrinktubes and safety pins.
image

Do you have this in platformio.ini?

lib_archive = false

1 Like

Great, let me check the schematics, but they don’t seem OK, they are all on top of each other. Do they pulsate, does the duty change, like, they stretch and shrink, or they are stuck at that?

They don’t pulsate, duty doesn’t change they seem static. We can say they are stuck.

Can you measure the PWM from the MCU, one phase, low and high (2 signals) and the 3rd the phase from the 1/2 mosfets? Open velocity please.

I will do this and report back but this week i will out of city.

I don’t see any obvious problems with the schematics, it appears very competent. Let’s see the waveforms from the three test points above. There might be an issue with the routing and the PCB, but that’s beyond my ability to debug over a text message, that needs hands-on with the gerbers and a microscope. Also, JLC is usually pretty good at what they do so that’s very unlikely that there is an SMD issue.

It all assembled by me (without a stencil) with LCSC parts not from JLC so it may a SMD issue maybe :slightly_smiling_face: but i have unassembled PCB’s and components to make another board just i need free time to assemble them. In a nutshell i can make another board next week and post results.

PS next time you make a dev board please expose those as test points. I see test points on the photo but can’t tell what’s what. If you haven’t, make test probes from jumper cables (I mean thin wires not car battery cables :slight_smile: ), shrinktubes and safety pins.

I have some test points to test misc. stuff such as opamp outputs but not your pointed ones. Whitepawn noted.

Do you have this in platformio.ini?

lib_archive = false

No it wasn’t in platformio.ini but today i tested with “lib_archive = false” but same behavior

Thanks both of you for your replies.

But it’s clearly one of the problems.
Without it, simplefoc will pick the generic driver for pwm and current sense.
That’s why you had that message

So if he doesn’t assert

float _readADCVoltageLowSide(const int pinA, const void* cs_params)

then he will go with the default pwm and that could explain why it doesn’t “spin” ?
I mean this is a flag /side effect that the lib_archive is not really false.
That makes sense in my simplistic thinking. In other words he is not really driving with the dedicated

STSPIN32G4 driver = STSPIN32G4();

Cheers,
Valentine

At least it explains the error message with current sense.
I am not sure how the STSPIN32G4 driver works.

I’m back.
Assembled two more boards just to be sure if i made any mistakes during assembly.

Triple checked schematics and parts (measured passive components before soldering) during assembly. I am pretty confident that %95 it is not an hardware issue.

I made measurements regarding 3 boards:

1 ST BOARD
Gates and U Phase Measurement:
High Side Gate From MCU (Measured Before R14)
Low Side Gate From MCU (Measured Before R15)
OUT1 U Phase to Motor (Measured from wire going to motor) (IGNORE 100V/Div it was x1, scope adjusted to x10 so read as 10V/Div)

2 ND BOARD
Gates and U Phase Measurement:
High Side Gate From MCU (Measured Before R14) (Yellow Channel 1)
Low Side Gate From MCU (Measured Before R15) (Cyan Channel 2)
OUT1 U Phase to Motor (Measured from wire going to motor) (Purple Channel 3)


Phase Measurements:
OUT1 U Phase to Motor (Measured from wire going to motor) (Yellow Channel 1)
OUT2 V Phase to Motor (Measured from wire going to motor) (Cyan Channel 2)
OUT3 W Phase to Motor (Measured from wire going to motor) (Purple Channel 3)

Same static behavior as before…

3 RD BOARD
Gates and U Phase Measurement:
High Side Gate From MCU (Measured Before R14) (Yellow Channel 1)
Low Side Gate From MCU (Measured Before R15) (Cyan Channel 2)
OUT1 U Phase to Motor (Measured from wire going to motor) (Purple Channel 3)


Phase Measurements:
OUT1 U Phase to Motor (Measured from wire going to motor) (Yellow Channel 1)
OUT2 V Phase to Motor (Measured from wire going to motor) (Cyan Channel 2)
OUT3 W Phase to Motor (Measured from wire going to motor) (Purple Channel 3)

Same static behavior as above boards.

I used this openloop code (Modified only motor voltage limit, above scope shots belongs to this openloop code) :

#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 = 1.0f; //ONLY THIS CHANGED
    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
}

My platformio.ini file is this:

[env:genericSTM32G431VB]
platform = ststm32
board = genericSTM32G431VB
framework = arduino
board_build.ldscript = ./variant/ldscript.ld
lib_archive = false
monitor_speed = 115200
monitor_eol = LF
build_unflags = -Os
build_flags = 
	-Ofast
	-DSIMPLEFOC_STM32_DEBUG
	-DPIO_FRAMEWORK_ARDUINO_ENABLE_CDC
	-DUSBD_USE_CDC
	-DUSBCON
	-DHAL_CORDIC_MODULE_ENABLED
	-DHAL_LPTIM_MODULE_ENABLED
lib_deps = 
	adafruit/Adafruit NeoPixel@^1.11.0
	askuric/Simple FOC@^2.3.4
	simplefoc/SimpleFOCDrivers@^1.0.8
        SPI
        Wire

As you can see i added lib_archive parameter and some others but result is the same that motor never spins. 3 different esc boards behave exactly same. They also drain about the same current during operation and idle blink program so i don’t think it is a hardware issue.

Any directions?

Thanks.

Could you share the serial output again, now with the lib_archive=false setting?
To verify that your driver is now initialized correctly?

Ok now i managed to partially worked it.
Started from scratch:
Downloaded funqi example and copied simple foc and simple foc driver dev branches to lib folder.

Platformio file is stock except “-DSERIAL_UART_INSTANCE=1” parameter:

[env:genericSTM32G431VB]
platform = ststm32
board = genericSTM32G431VB
framework = arduino
board_build.ldscript = ./variant/ldscript.ld
upload_protocol = stlink

lib_archive = false

monitor_speed = 115200
monitor_eol = LF

build_unflags = -Os
build_flags = 
    -Ofast
	-DSIMPLEFOC_STM32_DEBUG
	-DPIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -DUSBD_USE_CDC
    -DUSBCON
    -DHAL_CORDIC_MODULE_ENABLED
    -DHAL_LPTIM_MODULE_ENABLED
    -DSERIAL_UART_INSTANCE=1

lib_deps =

Here is the code:

#include <Arduino.h>
#include "SimpleFOC.h"
#include "SimpleFOCDrivers.h"
#include "drivers/stspin32g4/STSPIN32G4.h"
#include "utilities/stm32math/STM32G4CORDICTrigFunctions.h"
#include "settings/stm32/STM32FlashSettingsStorage.h"




HallSensor sensor = HallSensor(PB6, PB8, PB7, 15);
STSPIN32G4 driver = STSPIN32G4();
BLDCMotor motor = BLDCMotor(15);

// interrupt routine initialization
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}

STM32FlashSettingsStorage settings = STM32FlashSettingsStorage(); // use top page of flash for settings (2kB)
Commander commander = Commander(Serial1);
void onMotor(char* cmd) { commander.motor(&motor, cmd); }
void doSaveSettings(char *cmd) { settings.saveSettings(); }
void doLoadSettings(char *cmd) { settings.loadSettings(); }
void doCalibration(char *cmd) { 
    motor.sensor_direction = Direction::UNKNOWN;
    motor.zero_electric_angle = 0.0f;
    Serial.println("Motor calibration...");
    motor.initFOC();
    Serial.println("Calibration found:");
    Serial.print("   Direction: Direction::");
    Serial.println((motor.sensor_direction==Direction::CW)?"CW":((motor.sensor_direction==Direction::CCW)?"CCW":"UNKNOWN"));
    Serial.print("  Zero Angle: ");
    Serial.println(motor.zero_electric_angle, 6);
 }

void printDriverStatus();

uint32_t ts = 0;

void setup() {
    Serial1.begin(115200);
    SimpleFOCDebug::enable();
    delay(5000);
    Serial1.println("Welcome to FunQi Driver Firmware");

    sensor.init();
    sensor.enableInterrupts(doA, doB, doC);
    //motor.linkSensor(&sensor);

    Serial.println("Initializing CORDIC");
    if (!SimpleFOC_CORDIC_Config())
        Serial1.println("CORDIC init failed");



    Serial1.println("Initializing Driver");
    driver.voltage_power_supply = 12.0f;
    driver.voltage_limit = 10.0f;
    motor.voltage_sensor_align = 1.5; 
    driver.init();
    delay(1);

    Serial1.print("Driver ready: ");
    Serial1.println(driver.isReady()?"true":"false");
    Serial1.print("Driver fault: ");
    Serial1.println(driver.isFault()?"true":"false");    
    printDriverStatus();

    //COMMENTS
    //Serial1.println("Unlocking driver...");
    //driver.unlock();
    //driver.lock();
    //STSPIN32G4PowMng powmng = driver.getPowMngRegister();
    //Serial.print("VCC voltage: ");
    //Serial.println(powmng.vcc_val);
    // Serial.println("Setting VCC to 10V");
    // powmng.vcc_val = 0b01;
    // driver.setPowMngRegister(powmng);
    Serial1.println("Locking driver...");
    driver.lock();
    driver.clearFaults();
    printDriverStatus();
    Serial1.print("Driver ready: ");
    Serial1.println(driver.isReady()?"true":"false");
    Serial1.print("Driver fault: ");
    Serial1.println(driver.isFault()?"true":"false");    

    Serial1.println("Initializing Sensor");
    //sensor.checkcrc = true;

    // options1.uvw_off = 0b1;
    // sensor.setOptions1(options1);
    // sensor.setABZEnabled(true);
    // sensor.setABZResolution(16000-1); // sets 16000 PPR
    Serial1.println("Sensor initialized, start angle: ");
    Serial1.println(sensor.getAngle());

    Serial1.println("Initializing Motor");
    motor.voltage_limit = driver.voltage_limit / 2.0f;
    motor.controller = MotionControlType::torque;
    motor.torque_controller = TorqueControlType::voltage;
    motor.foc_modulation = FOCModulationType::SinePWM;
    motor.motion_downsample = 4;
    motor.linkDriver(&driver);
    motor.linkSensor(&sensor);

    Serial1.println("Initializing Settings");
    settings.addMotor(&motor);
    SimpleFOCRegister regs[] = SIMPLEFOC_SETTINGS_REGISTERS_MINIMAL;
    settings.setRegisters(regs, 2);
    settings.init();
    SettingsStatus loadStatus = settings.loadSettings();

    motor.init();
    Serial1.println("Motor enabled");


    if (loadStatus == SFOC_SETTINGS_SUCCESS) {
        Serial1.println("Calibration loaded:");
        Serial1.print("   Direction: Direction::");
        Serial1.println((motor.sensor_direction==Direction::CW)?"CW":((motor.sensor_direction==Direction::CCW)?"CCW":"UNKNOWN"));
        Serial1.print("  Zero Angle: ");
        Serial1.println(motor.zero_electric_angle, 6);
    }
    else
        Serial1.println("Motor calibration...");
    motor.initFOC();
    if (motor.motor_status == FOCMotorStatus::motor_ready && loadStatus != SFOC_SETTINGS_SUCCESS) {
        Serial1.println("Calibration found:");
        Serial1.print("   Direction: Direction::");
        Serial1.println((motor.sensor_direction==Direction::CW)?"CW":((motor.sensor_direction==Direction::CCW)?"CCW":"UNKNOWN"));
        Serial1.print("  Zero Angle: ");
        Serial1.println(motor.zero_electric_angle, 6);
        Serial1.println("Saving calibration...");
        settings.saveSettings();
        loadStatus = settings.loadSettings();
        if (loadStatus == SFOC_SETTINGS_SUCCESS)
            Serial1.println("Save successful");
        else
            Serial1.println("Save failed");
    }
    if (motor.motor_status == FOCMotorStatus::motor_ready)
        Serial1.println("Motor Ready");
    else
        Serial1.println("Motor NOT Ready");
   

    Serial1.println("Initializing comms");
    commander.add('M', onMotor, "Motor 1");
    commander.add('S', doSaveSettings, "Save settings");
    commander.add('L', doLoadSettings, "Load settings");
    commander.add('C', doCalibration, "Calibrate motor");

    Serial1.println("Setup complete");
    ts = millis();
    motor.target = 0.0f;
}




int count = 0;
int crcerrs = 0;

void loop(){
    uint32_t now = millis();
    if (now-ts>1000) {
        Serial1.print("It/s: ");
        Serial1.print(count);
        Serial1.print("  Fault: ");
        Serial1.print(driver.isFault()?"true":"false");
        Serial1.print("  Angle: ");
        Serial1.print(sensor.getAngle());
        Serial1.print("  Status: ");
        //Serial1.print(sensor.getStatus());
        Serial1.print("  CRC Errs: ");
        Serial1.println(crcerrs);
        count = 0;
        crcerrs = 0;
        ts = now;
    }
    count++;
    motor.move();
    motor.loopFOC();
    commander.run();
}




void printDriverStatus() {
    Serial1.println("Driver status: ");
    STSPIN32G4Status status = driver.status();
    Serial1.print("      Lock: ");
    Serial1.println(status.lock?"LOCKED":"UNLOCKED");
    Serial1.print("  VCC UVLO: ");
    Serial1.println(status.vcc_uvlo?"YES":"NO");
    Serial1.print("     VDS P: ");
    Serial1.println(status.vds_p?"YES":"NO");
    Serial1.print("     RESET: ");
    Serial1.println(status.reset?"YES":"NO");
    Serial1.print("      TSHD: ");
    Serial1.println(status.thsd?"YES":"NO");
}

And here is the code serial output:

Welcome to FunQi Driver Firmware
Initializing Driver
Driver ready: true
Driver fault: false
Driver status:
      Lock: LOCKED
  VCC UVLO: NO
     VDS P: NO
     RESET: NO
      TSHD: NO
Locking driver...
Driver status:
      Lock: LOCKED
  VCC UVLO: NO
     VDS P: NO
     RESET: NO
      TSHD: NO
Driver ready: true
Driver fault: false
Initializing Sensor
Sensor initialized, start angle: 
0.00
Initializing Motor
Initializing Settings
Motor enabled
Motor calibration...
Motor NOT Ready
Initializing comms
Setup complete
It/s: 371228  Fault: false  Angle: -0.07  Status:   CRC Errs: 0
It/s: 371040  Fault: false  Angle: -0.07  Status:   CRC Errs: 0
It/s: 371040  Fault: false  Angle: -0.07  Status:   CRC Errs: 0
It/s: 371040  Fault: false  Angle: -0.07  Status:   CRC Errs: 0
It/s: 371040  Fault: false  Angle: -0.07  Status:   CRC Errs: 0

I tested with hoverboard motor and the problem is motor rotates forward and backward but it cannot detect movement of rotor from hall sensors. Here is a video of it.
Because of no movement detection from hall sensors motor cannot be initialized i believe.I checked hall sensors output with osciloscope it seems fine. Openloop still doesn’t work at all.

Any thoughts?

After countless tries with different parameters openloop is now working.
This is the openloop code that i used:

#include <Arduino.h>
#include "SimpleFOC.h"
#include "SimpleFOCDrivers.h"
#include "drivers/stspin32g4/STSPIN32G4.h"
#include "stm32g4xx_hal.h"

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

void setup()
{
    Serial1.begin(115200);
    SimpleFOCDebug::enable(&Serial1);
    driver.voltage_power_supply = 12.0f;
    driver.voltage_limit = 1.5f;
    driver.init();
    motor.useMonitoring(Serial1);
    motor.voltage_limit = driver.voltage_limit / 2.0f;
    motor.controller = MotionControlType::velocity_openloop;
    motor.linkDriver(&driver);
    motor.enable();
    motor.init();
}

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

And here is the most important part platformio.ini file:

[env:genericSTM32G431VB]
platform = ststm32
board = genericSTM32G431VB
framework = arduino
board_build.ldscript = ./variant/ldscript.ld
upload_protocol = stlink

lib_archive = false

monitor_speed = 115200

build_flags = 
	-DSIMPLEFOC_STM32_DEBUG
	;-DPIO_FRAMEWORK_ARDUINO_ENABLE_CDC
   ; -DUSBD_USE_CDC
   ; -DUSBCON
    ;-DHAL_CORDIC_MODULE_ENABLED //THIS CAUSES MOTOR NOT TO SPIN BUT LOCK
    ;-DHAL_LPTIM_MODULE_ENABLED
    -DSERIAL_UART_INSTANCE=1
    ;-D ARDUINO_GENERIC_G431VBTX //THIS CAUSES NOT ROTATE MOTORS CAL
    ;-DHAL_EXTI_MODULE_ENABLED
    ;-DHAL_RTC_MODULE_ENABLED
    ;-DHAL_GPIO_MODULE_ENABLED
    -D ARDUINO_GENERIC_G431CBUX //THIS IS THE MOST IMPORTANT BIT.WITH THIS OPENLOOP WORKS
lib_deps =
	;https://github.com/simplefoc/Arduino-FOC.git //I DIRECTLY CLONED GITS AND EXTRACTED FOLDERS TO LIB FOLDER OF VSCODE
	;https://github.com/simplefoc/Arduino-FOC-drivers.git#dev

With -D ARDUINO_GENERIC_G431CBUX parameter on platformio.ini openloop works without issue. So i am relaxed that my hardware design is just fine and works. :slightly_smiling_face: :partying_face:

If i enable cordic module motor behaves exactly described as before. It just locks itself i am not sure why.

The problem is now it cannot read hall sensor values. I tried to print them to serial output and rotate motor with my hand but angle and velocity values are always zero. I tested my hall sensor just to be sure if it works correctly with “B-G431B-ESC1” hall sensors works fine but with “EVLSPIN32G4” it doesn’t work.

Here is my sample code to test just hall sensors:

#include <Arduino.h>
#include "SimpleFOC.h"
#include "SimpleFOCDrivers.h"
#include "drivers/stspin32g4/STSPIN32G4.h"
#include "stm32g4xx_hal.h"


HallSensor sensor = HallSensor(PB6, PB7, PB8, 7); //THIS IS FOR EVLSPIN32G4
//HallSensor sensor = HallSensor(A_HALL1, A_HALL2, A_HALL3, 7); //THIS IS FOR B-G431B-ESC
STSPIN32G4 driver = STSPIN32G4();
BLDCMotor motor = BLDCMotor(7);

// interrupt routine initialization
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}



void printDriverStatus();
uint32_t ts = 0;

void setup() {
    Serial1.begin(115200);
    delay(5000);
    Serial1.println("Welcome to FunQi Driver Firmware");
   
    driver.init();
    motor.linkDriver(&driver);

    sensor.init();
    motor.linkSensor(&sensor);

    sensor.enableInterrupts(doA, doB, doC);

    motor.init();
    motor.initFOC();

    ts = millis();

    
}

int count = 0;
void loop(){
    uint32_t now = millis();
    if (now-ts>1000) {

        sensor.update();
        Serial1.print("  Angle: ");
        Serial1.print(sensor.getAngle());
        Serial1.print("  Velocity: ");
        Serial1.println(sensor.getVelocity());
        count = 0;
        ts = now;
    }
    count++;
}

Right now i don’t have hardware with me but in evening i can provide log outputs of above hall test code.

Do you also include the required initialisation code for the CORDIC in the setup()?

#include "SimpleFOCDrivers.h"
#include "utilities/stm32math/STM32G4CORDICTrigFunctions.h"

void setup() {
    ...

    SimpleFOC_CORDIC_Config();      // initialize the CORDIC

    ...
}
1 Like