STM32CubeIDE configuration into PlatformIO example

For a custom board that uses the STM32G431 I’d like to use STM32CubeIDE to adjust some clock settings, VREF+ settings, and possibly other things. Then I’d like to use the generated code into PlatformIO to combine it with the SimpleFOC Arduino code.

Since I’m new to PlatformIO and STM32CubeIDE I’d appreciate if some of you who have done this before could share your code and perhaps provide some ‘how-to’ info on how to get started with this. Furthermore, I have some doubts about:

  1. For an SPI magnetic encoder: if the SPI library of Arduino works fine, is there any reason to configure SPI in CubeIDE or will this conflict with the SPI library of Arduino?
  2. My 6 PWM channels are all using Timer 1, but every time I run SimpleFOC it automatically searches for the best timer configuration based on score (always resulting in all channels using Timer 1). Should these be configured in CubeIDE or is there a BLDCDriver setting in SimpleFOC that manually configures the timer settings?
  3. For current sense, is it recommended to configure the ADC settings in CubeIDE or leave that to SimpleFOC? I’m currently experiencing some problems with current sensing (error CS: Err align B) and not sure where this is coming from.

Thank you all

I “use” cube IDE, but only the cubeMX part (the GUI peripheral and pin selector). I would recommend you do the same- go in there, enable the peripherals that you want to use, make sure there are no pin conflict, and then generate code if you need the clock configuration. For me mostly it is a configuration tool that I use while planning layout- I don’t use it to create any useful code, other than weird peripherals like op-amp, CORDIC, etc). If you don’t need the clock config, then no reason to generate code. I don’t think you need to use CubeIDE or CubeMX if you are doing pin selection from datasheet or otherwise.

  1. See above, I like using the GUI to select peripherals, but you don’t need any of the code from Cube IDE. Just use the Arduino SPI (it is built on the same STM32 HAL that Cube uses).
  2. Why do you want to skip timer search? It will run it, because it’s trying to figure out what timer to use- if you don’t change the pins you give to the Driver constructor, then it’s deterministic and you don’t need to worry about it accidentally changing what timer is picked.
  3. If you are using internal op amp for current sense, then you need to do a lot of configuration yourself. If you are just using ADC pins then you shouldn’t need to configure anything in Cube.
1 Like