Hi guys, thanks for this library! There’s so much here that’s useful.
I’m trying to get a BLDC motor spinning with this hardware:
STM32L452RE Nucleo-64 development board
STSPIN230 motor driver board
AS5147 magnetic sensor board
I’m using the minimal library, and compiled together code from the stm32_bldc_encoder and esp32_bldc_magnetic_spi example projects.
Oddly, I’ve never been successful programming the STM32 directly from the Arduino IDE, so my workflow has been to generate the binary from Arduino, and actually program the STM32 using STM32CubeProgrammer.
I compiled these tables from the datasheets:
| Connector | Pin | Arduino Label | Morpho Label | Function |
|---|---|---|---|---|
| CN5 | 6 | D13 | PA5 | SPI1_SCK |
| 5 | D12 | PA6 | SPI1_MISO | |
| 4 | D11 | PA7 | TIM17_CH1 or SPI1_MOSI | |
| 3 | D10 | PB6 | TIM16_CH1N or SPI1_CS |
and
| Connector | Pin | Signal | Morpho Label | Arduino Label |
|---|---|---|---|---|
| CN10 | 21 | V_High | PA9 | D8 |
| 23 | U_High | PA8 | D7 | |
| 24 | W_Low | PB1 | - | |
| 28 | V_Low | PB14 | - | |
| 29 | Enable | PB5 | D4 | |
| 30 | U_Low | PB13 | - | |
| 33 | W_High | PA10 | D2 |
From that info, I changed these lines like so:
// SPI magnetic sensor instance
//MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);
MagneticSensorSPI sensor = MagneticSensorSPI(PB6, 14, 0x3FFF);
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
//BLDCDriver6PWM driver = BLDCDriver6PWM(7, 2, 6, 3, 5, 4, 8);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB1, PB5);
When I run the program though, this is the only output I get over serial:
MOT: Monitor enabled!
MOT: Initialise variables.
MOT: Enable driver.
MOT: Align sensor.
The serial interface is unresponsive to commands, and the motor does not move at all. Any idea what I’m doing wrong here? I assume that the program might be waiting for something over SPI, but I don’t know how to debug that if so.
Also, in case it matters, I have no idea how to tell Simple FOC which pins to use for SPI communications. The STM32L452RE has three separate sets of pins ready for SPI, so I picked the set labeled 1 out of 3.





