C (bare metal) developmment for stm32f0 with PlatformIO

Hi,

After spending some time dealing with PlatformIO, I really would like to get more acquaintance with it. It’s indeed a tool to stick with, if you’re into embedded development.

I have a little experience with old age 8-bit MCUs, but haven’t been into real development of any kind for quite some time now.

So, after I worked my way in using Arduino for a project, I decided I should give all those ARMs a try. I have a STM32F0308-DISCO development board which I’ll use to aid development in another project.

Incredibly enough I was able to compile a blinking led example for this board with PlatformIO (letting it choose everything for me).

But now I’m face with an odd situation: it seems the only framework available for my board is mbed, which is a C++ project. I don’t have any knowledge in C++, and even the blink led example was a bit scary to me.

Trying to ‘retarget’ it to C, I realized PlatformIO does what it promises really well: I’m totally abstracted to the assembly initialization code for my processor, to the MCU configuration, and many other aspects that I was expecting to deal with when trying to compile my “own” code.

How do I deal with all that while still using PlatformIO? How do I debug code (if that’s possible)? How do I set it up for my ‘own board’, while using the manufacturer’s development board as tool in early stages of development?

I’m sorry if all my questions are too obvious our don’t make much sense, but making the switch from oldschool proprietary IDEs to an open source abstracted all-in-one IDE is a bit hard, and the learning curve is already steep with all the other tools of the ‘ecosystem needed’ to get it running.

Thanks in advance,

Andre.

Hi,

If you don’t need any framework, please omit framework = option from platformio.ini. See other examples for ST STM32 platformio-examples/stm32 at db884f2fcfb88926d176ac09cbb4e0a72087d351 · platformio/platformio-examples · GitHub
However, let’s wait for the answer by our engineer ( ping @valeros )

Yes, it should be possible. We are working on hardware debugging for the most boards that are listed in our registry. Do you use PlatformIO IDE or other?

See Custom Embedded Boards — PlatformIO latest documentation

You don’t need to sorry, this is our aim to create unique embedded ecosystem that should be easy for using or switching to it. So, we would be thankful for the feedback and propositions/recommendation how to improve it.

1 Like

Hi @ivankravets,

Thanks very much for your kind answer.

I’m working with PlatformIO IDE. Maybe I could even help a little, since I own some development boards for different kind of processors, so I could I dunno, test the implementations.

I also have been looking forward to learn a bit of python, so I could aid a little in development too, is that’s possible.

Hi @carvalhais!
I think next minimal configuration should be enough for bare metal programming:

[env:disco_f051r8]
platform = ststm32
board = disco_f051r8
build_flags = -Wl,-Tlinker_sript.ld

Where linker_sript.ld is name of your custom ldscipt in root folder of your project.

Hi @valeros,

Thanks for your kind answer regarding to this. I realized my board is not quite disco_f051r8, it is actually a STM32F0308-DISCOVERY, which I believe should translate to disco_f030r8 in PlatformIO ‘lingo’, since it uses a STM32F030R8T6 microcontroller.

I was browsing PlatformIO repositorie to look for the JSON files describing the ‘builtin’ boards, after reading @ivankravets post on how to add your own board, and I believe it is quite straightforward to add those files for the boards I own.

I wonder how would I go about contributing these little two cents with you guys.

Thank you all once again.

I wonder, where do the startup code for the given board goes? Or this assumes I have to provide my own startup code as well?

Yes, since you decided to program your board without any framework you should provide linker script, startup code for correct MCU initialization.