I’m upgrading from an Arduino mega 2560 to a custom designed board, based on an STM32F407VG processor, and would like to remain in an Arduino framework. However, when creating the project I’m requested to choose from the existing boards, which obviously have completely different pinout than what my board has.
Is there a quick way to configure my project to support a new board, without resorting to ST’s cubeMX framework?
Yes, I’m developing a robot, based on a custom designed board which incorporates the STM32 and wanted to customize an Arduino-STM variant to control the required resources
I have actually tried using the black_f407vg, but unfortunately, after uploading a very simple FW toggling a GPIO, the board just did not respond. Using genericSTM32F407VGT6 with the below settings gave better results, however the settings seem much more “tailored” to the original board, than the variant.h you’ve suggested, hence we found it very hard to work out PWMs, serial port etc.
If you want to create a new STM32Duino core variant, this is the general procedure:
Create a custom board JSON file docs. You can basically copy and adapt black_f407vg since it’s the same chip and target framework – however change the variant field to some other name and the -DARDUINO_BLACK_F407VG accordingly to the new variant name. I’ll just demonstrate it with MY_ROBOT as the variant name here. Save this JSON file under some name in the boards/ directory of the project, e.g. boards/my_robot.json.
Setup the platformio.ini to point to your newly created board.
Create a new variant folder in the STM32Duino framework. Go to C:\Users\<users>\.platformio\packages\framework-arduinoststm32\variants. Duplicate the BLACK_F407XX under the name MY_ROBOT. This must match the variant field in the JSON file. You can also duplicate Generic_F4x7Vx if you like and it’s closer to a working state.
Make sure to read the STM32Duino guide for adding a new variant to understand the configuration possibilities. You won’t have to do any really ground-work though since stuff like the PeripheralPins.c are already pre-provided from the copied variant.
Adapt the variant files as needed. In the case of choosing the BLACK_407XX as template, make sure you remove the #if defined(ARDUINO_BLACK_F407VG) stuff in the header file and the colliding #if defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) pin definitions in the variant.cpp and .h file. Adapt the variant.h for default pins for peripherals and the cpp file for clock init (by default it expects an 8MHz crystal for the HSE oscillator – if there’s no crystal, change the code to HSI. STM32Cube auto-generates the startup code.)
You should be able to compile a simple project now to test basic functionality, like if the setup() function is ever reached, whether digital I/O works, serial, SPI, etc.
Once you have finalized your variant files inside the framework-arduinoststm32 folder you can upload the contents of the folder to a repository and point to it using platform_packages, e.g.