NUCLEO STM32F302R8 can not run

HI
I have get angle from I2C port width AS5600; but when i add BLDCDriver3PWM driver, code well stop at driver.init() ;

*********************************************************************************************
      #include <SimpleFOC.h>

MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);

void setup() {
  // monitoring port
  Serial.begin(115200);
  // configure i2C
  Wire.begin();
  Wire.setClock(200000);
  // initialise magnetic sensor hardware
  sensor.init();

  // link the motor to the sensor
  motor.linkSensor(&sensor);

  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 12;
 driver.init();
  // link driver
 motor.linkDriver(&driver);

  

  Serial.println("Sensor ready");
  _delay(1000);
}

void loop() {
  // display the angle and the angular velocity to the terminal
  Serial.print(sensor.getAngle());
  Serial.print("\t");
  Serial.println(sensor.getVelocity());
}

HardwareTimer* _initPinPWM(uint32_t PWM_freq, int ulPin)

I find it stop at this code

Hey @happyfly,

Interesting issue. So the only issue I can see could be the setting of the center aligned PWM signal. Maybe that if no something F302RB has implemented yet. I will need to look into it a bit more deeply.

Can you please comment out the lines 39 and 40 in the file /drivers/hardware_specific/stm32_mcu.cpp and please let us know it this worked for you.

Thanks Reply
I did what you said, but the problem still exists。
if i comment out " driver.init();" ; the code can run.

  if (HardwareTimer_Handle[index] == NULL) {
    HardwareTimer_Handle[index]->__this = new HardwareTimer((TIM_TypeDef *)pinmap_peripheral(pin, PinMap_PWM));
  //  HardwareTimer_Handle[index]->handle.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED3;
   // HAL_TIM_Base_Init(&(HardwareTimer_Handle[index]->handle));
  }

Har

With stm32 I find it much easier to use the PinNames instead of numbers as all docs refer to pin names. Looking in your variant.h I determined the pins you have selected are:

BLDCDriver3PWM driver = BLDCDriver3PWM(PC7, PB4, PB10, PA9);

However there are problems with your selection

PC7 uses TIM17
PB14 uses TIM16
PB10 uses TIM2
PA9 uses TIM1

Only TIM1 and TIM2 support center mode.

Looking at TIM1 in the STM32CubeIDE device configuration tool we can find pins that support center mode.

If you wanted to use all 4 channels of TIM1, then the suggested pins would be:
BLDCDriver3PWM driver = BLDCDriver3PWM(PC0, PC2, PC3, PA9);

Or if you wanted to used TIM2:
BLDCDriver3PWM driver = BLDCDriver3PWM(PA0, PA1, PA3, PB10);

FYI: The board has 3 I2C buses. The first (I2C1) is on SDA=PA14, SCL=PA15

HI
I will configure according to your suggestion and tell you if it works, thank you

Hey @happyfly,
That is very interesting!

Can you try to run the stanalone example for the 3pwm dirver?
We did have some issues with driver timers and I2C and SPI clock timers. Can you just try the example from the library examples for stanalone 3PWM driver. To see if it gives you the same behavior.
Also you can try to run the open-loop example code to see if it works.

Next thing that is maybe the problem is that stm32f302rb does not seem to be listed as supported board for stm32duino (stm32f302r8 is supported). I am not sure if that changes something or not. If you are able to run the sensor examples that probably means that the board is supported.

Finally,

What you can do for now is remove stm32 implementation of the pwm handling. If you only need the 3pwm driver code the performance will not be too different using regular arduino analogWrite at least till we figure out what is the problem.
You can remove file stm32_mcu.cpp completely and remove line 11 from generic_mcu.cpp. This should make the code work.

BLDCDriver3PWM driver = BLDCDriver3PWM(PC0, PC2, PC3, PA9);
Only this configuration can make the motor turn。I run pen loop motor control example

sorry, i am use F 302R8 not RB; I misspelled

Well done @Owen_Williams good thinking!

Ok cool, so you got i working?

yes all is OK, I run close loop is OK; I think the problem is PWM IO confgure.

Cool!
I’m happy to hear that.

I’ll make sure to add it to the docs!