Struggling to get motor spinning with ST B-G431B-ESC1 board

Hi All,

Hopefully someone can see what I’m doing wrong here as I’ve been banging my head against the wall for hours with this. I’m just trying to get a motor spinning in the velocity openloop mode, using the example code from the velocity openloop page, with the driver declaration changed to what I think is right for the B-G431B-ESC1 board.

This is my main.cpp:

// Open loop motor control example
#include <SimpleFOC.h>

// BLDC motor & driver instance
// BLDCMotor( pp number , phase resistance)
BLDCMotor motor = BLDCMotor(11 , 12.5, 100); 

// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&, cmd); }
void doLimitCurrent(char* cmd) { command.scalar(&motor.current_limit, cmd); }

void setup() {

  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 12;
  // link the motor and the driver

  // limiting motor current (provided resistance)
  motor.current_limit = 0.5;   // [Amps]
  // open loop control config
  motor.controller = MotionControlType::velocity_openloop;

  // init motor hardware

  // add target command T
  command.add('T', doTarget, "target velocity");
  command.add('C', doLimitCurrent, "current limit");

  Serial.println("Motor ready!");
  Serial.println("Set target velocity [rad/s]");

void loop() {
  // open loop velocity movement
  // using motor.current_limit and motor.velocity_limit

  // user communication;

and this is my platformio.ini


platform = ststm32
board = disco_b_g431b_esc1
framework = arduino

lib_archive = false

build_flags = 

lib_deps = 
	askuric/Simple FOC@ 2.3.2

With everthing as it is, I get nothing at all, no serial comms in the monitor, no activity on the outputs or drivers when measured on the scope. If I comment out motor.initFOC(); then I get serial comms and can send commands, but still no activity on the outputs or drivers regardless of what I set the speed to.

Can anyone see anything I’ve missed? Tried it on two different boards with the same result so I’m assuming it’s a software/config error. I’m using the builtin ST-LINK programmers on them if that makes a difference, running with the USB connected to the programmer and 12V bench PSU on the driver. It’s only pulling ~10mA with the motor connected so it’s certainly not “trying” to energise the motor.

You are mixing up code from closed loop with code from open loop. For open loop take a look at the example here: (you’ll need to keep your motor/driver defs)

Specifically you shouldn’t be calling initFOC or loopFOC
Also it might be worth following the target_velocity seen in the example so that the motor will spin even if the serial isn’t working properly

You might want to start with a voltage_limit even lower than 3v if your motor has low phase resistance