G431 ESC1 "ERR-MOT:Init not possible, driver not init"

STM32G431 ESC1 driver.init() fails

Hi, I have a G431 ESC1 motor driver. I’ve connected an AS5600 sensor to its I2C pads, connected the motor output pads to a 2804 gimbal motor, and it’s being powered by a 3s lipo.

The issue begins when I write code to spin the motor. I’ve copied the example code directly and modified the sensor code to use the I2C sensor. I’m programming with PlatformIO in Vscode. Whatever I do, the driver.init() always fails (returns 0). I’ve tested the board by only printing the AS5600 reading and it works fine, so the board is probably fine. (it’s also brand new.) I’ve been chatting with Claude for the past 3 hours and couldn’t get it to work…

Here’s main.cpp:


#include <SimpleFOC.h>

// Motor instance
BLDCMotor motor = BLDCMotor(7);  // <-- SET THIS to your motor's actual pole pair count

BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);


// Gain calculation shown at https://community.simplefoc.com/t/b-g431b-esc1-current-control/521/21
//LowsideCurrentSense currentSense = LowsideCurrentSense(0.003f, -64.0f/7.0f, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);

// AS5600 I2C sensor instance
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);


Commander command = Commander(Serial);
void doTarget(char* cmd) { command.motion(&motor, cmd); }

void setup() {


  Serial.begin(115200);
  SimpleFOCDebug::enable(&Serial);
  while(Serial.available() == 0) {
  // Just waiting for key input to start everything
  }


  driver.voltage_power_supply = 10;   
  driver.voltage_limit = 5;           
  Serial.print(F("Initializing driver... "));
  if (driver.init()) {
    Serial.println(F("SUCCESS!"));
  } else {
    Serial.println(F("FAILED! Check main power supply voltage."));
  }


  Wire.begin();
  Wire.setClock(400000);
  sensor.init(&Wire);
  motor.linkSensor(&sensor);
  motor.linkDriver(&driver);


  motor.voltage_sensor_align = 3;
  motor.controller = MotionControlType::angle;
  motor.PID_velocity.P = 0.2;
  motor.PID_velocity.I = 20;
  motor.voltage_limit = 5;
  motor.PID_velocity.output_ramp = 1000;
  motor.LPF_velocity.Tf = 0.01;
  motor.P_angle.P = 20;
  motor.velocity_limit = 4;
  
  

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

  // Add target command T
  command.add('T', doTarget, "target angle");

  Serial.println(F("Motor ready."));
  Serial.println(F("Set the target angle using serial terminal (e.g., T1.5):"));
}

void loop() {
  motor.loopFOC();
  motor.move();
  command.run();
}

I’ve commented out the low side current sensing code because it was giving me problems (ERR: Low-side cs not supported!), even though I’ve added the build flags in the platformio.ini file…

Here’s platformio.ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
monitor_speed = 115200
lib_deps = 
	askuric/Simple FOC @ ^2.4.0
	robtillaart/AS5600@^0.6.7
build_flags = 
	-D PIN_WIRE_SDA=PB7
	-D PIN_WIRE_SCL=PB8
    -D HAL_OPAMP_MODULE_ENABLED
    -D SIMPLEFOC_STM32_6PWM
    -D HAL_ADC_MODULE_ENABLED
extra_scripts = upload_target.py
upload_protocol = custom

Claude told me to explicitly add -D SIMPLEFOC_STM32_6PWM, but it doesn’t work with or without…

Any help would be very very appreciated!! I’ve ran out of ideas…

There are two ways for driver.init() to fail on STM32. - Too many drivers used (not the issue with your code) - stm32_findBestTimerCombination fails. (This is almost certainly your problem.) I would try defining SIMPLEFOC_STM32_DEBUG=1 to see if it will print anything useful about what's happening.

Thanks for the reply! I added the debug code you mentioned, but it doesn't seem to provide any new information. I'll try looking into the timer combination thing though

1 Answer

1

Hi there,

There is a more systematic issue somewhere. If you get the message that the low-side current sensing is not supported that means that the code does not load the stm32g4 hardware specific code of the library.

The only real issue I see in the code is the platformio.ini file which lacks the line:
lib_archive = false
See more here:

Thank you so much! This is the solution! I don't know how I missed it...