Custom board specific startup code generation

Hello, I am new to the PlatformIO and trying to grasp the build system. I would like to create a custom board with STM32 MCUs in platformIO. I would like add certain source files to the project whenever user creates a new project with custom board. (Mainly startup sequence, pin-mux configurations and certain board specific hardware interface definitions). I read the documentation and searched for the answers on forum but could not find any definitive straightforward answer on how to achieve this.

I want to do:

  • User creates new project with my custom board and a framework (mostly ststm)
  • Once project is created there needs to be certain .c and .h files in src folder as default starter code

P.S - Arduino generates main.c and espressif framework generates empty.c. I just want to know where can I put my pre-generated source file so that it can be copied to project src folder at the time of initialization.

There is no built-in functionality for this. The PlatformIO core only auto-generates a src/main.cpp or src/main.c file on project creation based on the selected framework (source). There isn’t an option to hook this functionality to copy custom-defined files.

The best you can do is create a library with your functionality and tell users to include it via lib_deps and call its initialization function.

Or, open an issue in Issues · platformio/platformio-core · GitHub.

Ohh…I think this is a very vital functionality particularly for developers who wants to support their products through PlatformIO. But if these functions are handled by core then how espressif generates a empty.c and arduino framework generates main.c even though core is same for both framework?

I will create an issue for this on the github. So just a option to provide init script with board will be sufficient to give infinite flexibility to developers as they can do whatever setup they seem fit from a single init script.

Thank you for clarification!

1 Like

Arduino and ESP-IDF are two different frameworks. The common platform would be platform-espressif32.

ESP-IDF is special case though that is actually not handled in the PlatformIO core code I linked above – it’s handled in the platform: Source. The platform code is exploiting a behavior there that the PlatformIO core runs an intellisense discovery after project discovery, in which a platform’s python scripts are invoked, which are coded in this case to create project files if not present.

But this isn’t something a developer of a new board should do (creating a custom platform that inserts this functionality). Best to open an isuse.

1 Like


I have created an issue here: Board specific init scripts · Issue #4142 · platformio/platformio-core · GitHub
as per your suggestion.

Thank you very much for the support!