Smallest MCU for micropython

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: Smallest MCU for micropython

Post by chrismas9 » Wed Apr 08, 2020 2:12 am

I am developing products using L072, primarily because of its on board EEPROM. I did an exercise first to build a minimum useful STM32 port and got it down to about 150k. Not all features can be disabled in mpconfigboard.h. You need to work through all the config files and disable what you don't need. In my case I only needed a UART comms protocol, GPIO and PWM so I disabled SPI, I2C, ADC, floating point and a bunch of other features.

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: Smallest MCU for micropython

Post by tve » Wed Apr 08, 2020 6:07 am

Ah, interesting! Do you perhaps have a board directory you could share? Did you add a small filesystem or do you load all the code via frozen modules?

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: Smallest MCU for micropython

Post by chrismas9 » Wed Apr 08, 2020 12:54 pm

It's more than a board directory. Some of the changes are in the port files. I will try to put something useful together. I just nuked my laptop and I haven't installed everything yet so I probably won't be able to do anything until next week.

I am not using a filesystem. I debug in RAM using Thonny IDE and then run frozen bytecode.

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: Smallest MCU for micropython

Post by tve » Wed Apr 08, 2020 7:45 pm

If you find the time to upload, that would be cool. I got an L072 version down to under 170KB: https://github.com/tve/micropython/tree ... oards/JNZ5 I'm not looking for a smaller size but for inspiration on other places to cut that don't hurt :lol:

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: Smallest MCU for micropython

Post by chrismas9 » Mon Apr 20, 2020 1:46 am

Thorsten,
Your minimal port is similar to mine. The biggest savings come from disabling FLOAT and SPI. SPI costs about 7k.

The only other big change I made was to disable the compiler. From memory this saves about 24k (my notes are at work and I am working at home).

Code: Select all

#define MICROPY_ENABLE_COMPILER     (0)
You can't use the REPL for debug. I hand wire an F091 module onto prototypes for debug, then freeze the final code.

Some smaller improvements can be made by disabling builtins in mpconfigport.h such as UNICODE, but the gains are relatively small. There are other extended modules that can be disabled such as UASYNCIO, UJSON.
Chris

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: Smallest MCU for micropython

Post by tve » Mon Apr 20, 2020 5:55 am

Thanks for the suggestions! I was toying with the idea of implementing a stack in flash to load .mpy modules instead of trying to cram in a filesystem. Basically write modules one after the other into a block of flash and execute them from there. Then provide "mark" and "pop_to_mark" methods so one can pop modules off to go back to a previous state. This way one can load a set of stable modules and then push/pop more experimental ones easily. It's on my to-do list...

Post Reply