Page 1 of 1

Assistance/guidelines for porting STM32duino to the STM32F3

Posted: Thu Sep 07, 2017 6:28 pm
by pramilo

I read Roger's post here mentioning his availability to give some pointers on how to go about porting the stm32duino libraries to the STM32F3.

I have a good amount of experience in low level ATMEL programming and have also done work on low level libraries for the Teensyduino and written some specific code from scratch for the Teensy 3.2 (Cortex M4) (for example, continuous ADC sampling via interrupts, tweaking the USART libraries to oeprate in one wire half duplex mode, write TSI code from scratch...).

I am beginning a new project where we're designing a board around the STM32F303RET6 to break out of the limitations of the Teensy 3.2.
We intend to port the code we already have compiling with the Teensyduino lib to some other library and the stm32 seems to be the one that might provide the best compatibility.
Having read quite a bit about developing from scratch for these processors, I could either do it from scratch and just implement what I need (CDC USB, UARTs and digitalWrite/analogRead) or I might as well take a swing at porting the stm32duino libraries. (probably the same work or maybe even less and I make a contribution to the community).

Since I am a newly registered user I can't PM Roger, so I am posting here hoping someone can give the right pointers.

Thank you very much,

Re: Assistance/guidelines for porting STM32duino to the STM32F3

Posted: Thu Sep 07, 2017 9:00 pm
by RogerClark
Now that STM have written their own core for the F3, I recommend you use that core.

The F3 in my repo was just put there for historical record, as it had been abandoned by its author.

Alternatively you could also use Koduino, by Avid De, which is a core he developed specificly for the F3
you could make a version using Danieleff's STM32GENERIC core. But I dont know if he has already done a variant for the F3

Re: Assistance/guidelines for porting STM32duino to the STM32F3

Posted: Fri Sep 08, 2017 12:58 am
by victor_pv
The F3 is nearly identical to the F1 except with a Cortex-M4, so if you want to work on updating the F3 core for any function that doesn't work, it should be doable using the F1 as reference as just changing only what's different, that shouldn't be much.

I did a brain transplant in a bluepill from an F1 to an F303CCT6 and tested a basic blinking sketch. I mostly did it for the heck of it, since there are a few threads about that transplant being successful (and even replacing the F1 with an F4). So the F3 core works for the basic.

Still if you are not familir with libmaple, Roger's advice to use STM's own core is likely the best. That core is based on STM's HAL, so anything you learn about the HAL you can still apply later if you decide to just use the HAL and drop Arduino.

There is a couple of forum members that work for STM and are very helpful if you have trouble or questions about that core or the STM32 in general, and I'm sure STM will be happy more people uses their core.

Re: Assistance/guidelines for porting STM32duino to the STM32F3

Posted: Mon Sep 11, 2017 11:42 am
by pramilo
Thank you very much for all your excellent replies.

I'm trying to stay clear of the STM HAL as I've read two not so great things about it: (1) it's incomplete in many cases or the documentation is lacking compared to the actual implemented functionality, (2) adds significant overhead. It's also known for being sometimes buggy.
Also, we're running some time sensitive tasks on the processor and even though the processor is extremely fast, I'd prefer to stay away from the HAL.

I'm more than happy to read through the processor datasheet and look at registers, etc.

For now, I'll try Koduino as I suppose it follows the same Arduino principles. I find this great to get you started as you can use the built functions and then tweak or (re)write the pieces where you need a different or new behavior.
I know Koduino is lacking the USB slave device code (ie to implement a Virtual COMM port). If I do get around to building it, I'll come back to post it.

Once again thank you all for your advice.

Best Regards,

Re: Assistance/guidelines for porting STM32duino to the STM32F3

Posted: Tue Jan 16, 2018 1:49 am
by dannyf
to give some pointers on how to go about porting the stm32duino libraries to the STM32F3.
my 2 cents, having ported the arduino framework to a few mcus, some in the STM32 families. the biggest lesson I learned is to isolate the hardware from the software.

in my initial port, I tried to do that, but took a one-version per device approach (you can see it here: ... x-m-chips/). that approach separates out the hardware from the software, with the device-dependent implementation in armduino_<xxxx>.h/.c files.

It works but due to the various forking / branches, maintenance becomes difficult.

my 2nd attempt (here: ... f-arduino/) completely took the hardware dependent piece out of the implementation. Instead, the same set of xduino.h/.c files, coupled with device-dependent board_<xxxx>.h/.c files gets the job done.

This has two advantages:
1. To add support for new chips, I only need to create the corresponding board_<xxxx>.h/.c files, under a common set of prototyping, as declared in xduino.h;
2. To update, I only need to make changes to xduino.h/.c files and it will permeate down to all devices.

So going back to your question, I would suggest that you take something similar to the 2nd / xduino approach, hiding all hardware specific functionality away from the users. Should you develop support for other variants of STM32F3 chips, you can then add the corresponding files and you are ready to go.

I did implement GPIO/timing functions for STM32F303 so if you wish that could be a starting point for you.

best of luck.