Porting to STM32F0 and F1

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
oddfield
Posts: 3
Joined: Mon Aug 31, 2015 2:48 am

Porting to STM32F0 and F1

Post by oddfield » Mon Aug 31, 2015 3:01 am

I am investigating the possibility of porting MicroPython to STM32F0 and STM32F1. I would like to know whether it is conceptually feasible. I do know this would be very close to (if not over) the lower limit of MicroPython.

The particular processor I am looking at is STM32F060CB, with a M0 48MHz core, 128kB Flash and 16kB SRAM.

Compromises I am happy to make:
- Python scripts would be limited to simple/small/few.
- Remove some of the code emitters. Compressed bytecode alone would be enough, although it would be nice to have native code emitter as well.
- Reduce/remove non-core Python library support

Looking forward to hear your thoughts on this.

Thank you,
Stephen

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Porting to STM32F0 and F1

Post by dhylands » Mon Aug 31, 2015 7:03 am

I think that getting it downto 128K flash will be the challenge, since the current image is about twice that.

If you dropped USB support, that would probably take a big chunk away.

oddfield
Posts: 3
Joined: Mon Aug 31, 2015 2:48 am

Re: Porting to STM32F0 and F1

Post by oddfield » Mon Aug 31, 2015 10:11 pm

Thank you for your inputs.
dhylands wrote:I think that getting it downto 128K flash will be the challenge, since the current image is about twice that.
I read somewhere that the minimum requirement is 128kB flash and 8kB RAM. Is that now obsolete?
dhylands wrote:If you dropped USB support, that would probably take a big chunk away.
By taking USB away, does that implies taking MSC and file system away?
Would you mind sharing a linkmap so I can get a better idea which part of MicroPython takes up the most space?

Also is 16kB memory realistic? How small a stack can we use realistically?

Thank you.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Porting to STM32F0 and F1

Post by dhylands » Tue Sep 01, 2015 8:10 pm

Taking away USB would take away MSC (also known as USB Mass Storage). It wouldn't necessarily take away the flash filesystem.

The current pyboard is 256K + 112K for the flash file system.

If you want to use a flash filesystem, you'll need to reserve as much RAM for the flash file system as the size of the largest block contained in the file system (on the pyboard the 112K is made up of 3x16K flash blocks and 1x64K flash block, so it needs 64K of RAM for that.

You can still use frozen modules to hold your python source code without having to use a file system at all.

I think that 128K is a goal, but until somebody actually does a port that works in that size, it's still theoretical.

The size of your stack will largely depend on the type of python code you run. I'm going to guess that it could be as small as 1-2K. The pyboard allocates 16K.

I copied a firmware.elf https://www.dropbox.com/s/t65ugu8gbff9v ... e.elf?dl=0 and firmware.map https://www.dropbox.com/s/90q5ld609wsi4 ... e.map?dl=0 to my dropbox account. These are for the pyboard.

oddfield
Posts: 3
Joined: Mon Aug 31, 2015 2:48 am

Re: Porting to STM32F0 and F1

Post by oddfield » Tue Sep 08, 2015 10:51 am

Thank you Dave. Most appreciated for the linkmap.

What is the smallest successful port you know of?

I have no problem taking away the MSC and the file system. There is already a very primitive pseudo file system. There would be no need for floating point support, and I am happy to prune away 80% of the python library support, with only the core, string manipulation and basic arithmetic left. However given the current size I would still say it would be a stiff challenge with my proposed compromise.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Porting to STM32F0 and F1

Post by dhylands » Tue Sep 08, 2015 3:38 pm

I compiled the "minimal" port using the ARM compiler and it came in around 78K.

The teensy port (which has USB serial but no UMS) is around 190K.

BrendanSimon
Posts: 33
Joined: Wed Sep 07, 2016 10:46 am

Re: Porting to STM32F0 and F1

Post by BrendanSimon » Wed Sep 07, 2016 12:12 pm

Just saw these posts _after_ posting a question myself re an F1 port (DOH!!)

I have a board with an STM32F103VE MCU (512KB Flash, 64KB RAM). Plenty of resources for MP :)

Dave, do you still have your F1 port ?

If so, are you able to commit that to MP git repo ?

Thanks, Brendan.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Porting to STM32F0 and F1

Post by dhylands » Wed Sep 07, 2016 3:43 pm

I haven't started anything on the f0/f1 front.

Starting with something based on minimal is probably the best way to become familiar. Then throw that away and do it properly inside stmhal.

Post Reply