Hello everybody! I am developing my own bldc motor controller. Sadly i’ve ran into problems with my microcontroller. I am trying to program an STM32L432kc nucleo32 microcontroller using Arduino IDE. There are 2 major problems.
- The code uploads properly but after the code uploads i get a “Driver init failed” information on serial monitor. There is also no response to any commander commands that i am trying to send.
- When uploading code, Arduino IDE shows wrong numbers of avialiable Flash memory and SRAM on the microcontroller (i am talking max values, not the memory i have avialiable after the upload). Arduino IDE shows i have 65kB of flash memory avialiable, even though i should have 256kB on this particular model. Same situation with SRAM, it shows 41kB avialiable and i should have 64kB.
I cant find any problem with the code. I tested the code with a standard Arduino Nano (with a different pin config ofc) and it was working flawlessly. In the beggining i wanted to use a basic Nano for the whole project but i ran into problems with storage space, when uploading any code more complicated than the open loop velocity control. So i choose to use the stm32 instead.
I dont know if this problem can even be solved, or if a have to get a different microcontroller.
If someone has any idea what might be the problem it would be a life saver.
My code:
// Open loop motor control example
#include <SimpleFOC.h>
// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number, phase resistance (optional) );
BLDCMotor motor = BLDCMotor(15);
// BLDCDriver6PWM( int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en)
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PA7, PA9, PB0, PA10, PB1);
//BLDCDriver6PWM driver = BLDCDriver6PWM(11, 3, 10, 9, 6, 5);
// instantiate the commander
Commander commander = Commander(Serial);
void onTarget(char* cmd) { commander.target(&motor, cmd);}
void onMotor(char* cmd) { commander.motor(&motor,cmd); }
void setup() {
// driver config
// power supply voltage [V]
driver.voltage_power_supply =14;
driver.init();
driver.pwm_frequency = 20000;
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
//motor.phase_resistance = 1.6; // [Ohm]
//motor.current_limit = 4; // [Amps] - if phase resistance defined
motor.voltage_limit = 12; // [V] - if phase resistance not defined
motor.velocity_limit = 50; // [rad/s] cca 50rpm
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
// add target command T
commander.add('T', onTarget, "target velocity");
commander.add('M',onMotor,"full motor config");
Serial.begin(2000000);
Serial.print("Driver init "); // init driver
if (driver.init()) Serial.println("success!");
else{
Serial.println("failed!");
return;}
Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
motor.move();
// user communication
commander.run();
}
And a screenshot of Arduino IDE: