SPI not initializing with PlatformIO

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

File_000(1)

I created another thread a couple weeks ago about some problems I’m having with my setup. I decided to create this new thread now to address a specific issue: I am unable to get SPI to initialize when I compile and upload a Simple FOC program with PlatformIO. I am not sure if this is a PlatformIO problem, a Simple FOC problem, or something I’m doing wrong.

Some quick facts:

  • Execution always halts at sensor.init();. Or, at least, no serial output is produced after that function is called.
  • I have tried the SPI sensor test example and other examples.
  • I have tried the minimal branch and the master branch of Simple FOC.
  • I have tried fresh installs of VS Code and PlatformIO on two different machines: one running Mac OS Catalina, and other other running current Manjaro Linux.
  • The SPI sensor test example does produce serial output after sensor.init(); when uploaded from the Arduino IDE.

Any ideas what’s going on here? Or further steps I can take to debug this?

I chose what I think is your board in stm32cube ide and it is suggesting not using PA5 (perhaps because it is used for green led.

Have you tried switching clock to PA1 and calling this:

SPI.setMISO(PA6);
SPI.setMOSI(PA7);
SPI.setSCLK(PA1);
sensor.init();

Thanks for the reply! I tried that and unfortunately, it has the same behavior.

Hi @armaanhammer

So to understand you correctly: The SPI sensor does work correctly in arduino IDE and does not work in platform.io?

Did you try to upload and run the full foc code already in arduino IDE?

Hi @Wittecactus, yes that’s correct. The SPI sensor sends data back when the Arduino IDE compiles and writes the code, but I get nothing back over serial after that function call when I compile and write with PlatformIO.

Re: the full FOC code, I’ve actually been having some pinout troubles with my motor setup, so I have not been able to test open loop control yet.

Hi @armaanhammer,

That is strange. Maybe it has something to do with your platformio.ini file, where you can put certain build flags that are also related to serial. Personally I switched back to arduino IDE due to some inconsistencies (also related to serial) I experienced. Maybe this thread can help you further. There are some suggestions there how to fix some of these inconsistencies!. Otherwise maybe a platform.io expert on this forum can help you further!