PikaScript – A lightweight Python implementation that runs on STM32 and other low-end MCUs

PikaScript is an ultra-lightweight Python engine that can run on microcontrollers with as little as 4KB of RAM and 32KB of Flash, while the more popular MicroPython requires at least 256kB of code space and 16kB of RAM.

PikaScript was initially developed to run on STM32G030C8 and STM32F103C8 MCUs, meaning, for example, it works on the BluePill board, but it has also been ported to other platforms like WCH CH582 RISC-V MCU, WinnerMicro W806 C-Sky microcontroller, as well as other like Raspberry Pi RP2040, ESP32-C3, etc… but those are not quite as well supported with some features missing.

PikaScript also permits the binding C function to a Python module through Pika Pre-compiler. PikaScript can run bare metal on the microcontroller, but also supports real-time operating systems such as RT-Thread and VSF (Versaloon Software Framework), as well as Linux. Just like MicroPython, it’s using a subset of Python 3, but I’d assume with even fewer features due to the smaller footprint.

Pika-Pi-Zero is the official board for the project, but I can only find it on Taobao at this time. It is based on STM32G030C8T6/STM32G070CBT6 MCU. It’s possible to generate a default project for your hardware target and operating system through an online tool.

You’ll also find the source directly on Github together with documentation on some samples (GPIO, USART, ADC, PWM output, RGB display, and Snake game demo).  We’re told the maximum RAM usage of these demos is only 3.56KB or 4.56KB if the 1KB stack is included, while the maximum storage usage is 30.4KB. If we take STM32F103C8T6 microcontroller with 20KB RAM and 64KB flash for reference, that means less than 25% RAM and less than 50% Flash are used by PikaScript firmware and sample code.

If you’d like more details and/or ask questions, Lyon, one of the PikaScript developers, will also give a talk entitled  “PikaScript – An Ultra-lightweight Python Engine Under RT-Thread” at the 2022 RT-Thread IoT OS Global Tech Conference taking place on June 1-3 online.

Share this:

Support CNX Software! Donate via PayPal or cryptocurrencies, become a Patron on Patreon, or buy review samples

7 Replies to “PikaScript – A lightweight Python implementation that runs on STM32 and other low-end MCUs”

  1. Dude. Just improve micropython. This is nearly useless. The world doesn’t need this. We do need better micropython ports and documentation.

    Did you know you have to reset the frequency of the pwm every time you change the duty cycle on a raspberry pic pico? That’s not documented, either. Also you have to reset the duty cycle every time you reset the frequency. That’s clearly just the tip of the iceberg. We don’t need more stuff that doesn’t work. We need stuff that works.

    1. I suppose they do it in their free time…

      Who knows maybe it will become the better micropython some time?

      And the problems you mentioned are they micropython specific or HW specific? Sometimes the silicon manufactorers write those pesky data- and errata sheets as well as programming manuals not just to destroy trees…

      1. If you look on Github, Raspberry Pi Pico is only partially supported.
        The docs may not be up-to-date, but gpio, uart, pwm, adc, and i2c are NOT supported, only the “BSP”.

  2. Since MicroPython and CircuitPython are too resource intensive for ST’s low cost G0s (with built in caps !), this is great news as a development alternative to: STM32Cube IDE/MX, Keil and IAR. Comparing and contrasting tool specific examples is the most effficient way to see what is possible with a given target.

    On the “just improve MicroPython” comment, I would love to see effort put into lesser, lighter weight versions, but the abundance of RP2040 and ESP32 chips has shifted the momentum to make that unlikely as library writers target fatter, lower hanging targets.

    Standing ovation for PikaScript ! 😀

  3. Watching all those execution steps makes me naseous. Just learn C and write some proper code instead of screwing around with shitty scripts on low end hardware.

Leave a Reply

Your email address will not be published.

Advertisement
Advertisement