4.1. Deploy to new platform in ten minutes

4.1.1. How to choose a platform that can run pikascript

  • PikaPython can run on all bare metal and operating systems that support libc.

  • The compiler needs to be able to support the C99 standard.

  • Supports 32bit/64bit kernel, does not support 8bit kernel.

  • resource occupancy

    • If it is an arm kernel, considering the resource consumption of the expansion module, it should be equipped with a minimum of 64k flash and 8k ram.

    • If it is a risc-v kernel, you need 128k flash and 8k ram , because of the gcc optimization of the risc-v kernel and the problem of code density, the code size is much larger than that of the arm kernel.

    • If it is other kernel, you can refer to the configuration requirements of risc-v.

  • If it is a PC/server platform, linux/windows can be used.

4.1.2. Deployment operation process

In this document, we will describe how to deploy PikaPython for new platforms.

PikaPython has almost no global variables and macros, and only depends on the standard library, so it is very easy to deploy PikaPython for new platforms.

Here are the specific steps to deploy PikaPython Prepare template project

Your template project just needs to include a serial port initialization that supports printf, and then you can happily use pikascript.

The usual script interpreters rely on the operating system and file system, and pikascript does not need these, if you have deployed other scripting engines, you will find that PikaScrip has real super Lightweight features. Get PikaPython source code and toolset

To get PikaScsript, you can use the pika package manager (option 1), or use the project generator on the official website (option 2).

Option 2 is an automated version of Option 1. It is recommended that newbies use Option 1 when deploying for the first time to familiarize themselves with the package manager. Download PikaPython Package Manager

PikaPython package manager can help you pull all source code and tools needed by pikascript, and provide version selection function, which is convenient for you to switch versions.

And the PikaPython package manager uses gitee source, which can be used smoothly in the mainland, does not require scientific Internet access.

Enter the PikaPython main repository




Download the PikaPython package manager PikaPackage.exe


Then open the project you want to deploy, create a new pikascript folder in the root directory of the project, and copy PikaPackage.exe into it.

_images/142019778-c727336c-9b6a-4a82-b813-1671f4120152.png Pull source code

Next, with the help of PikaPackage.exe, we can easily pull the source code and modules of the specified version.

Pull the source code and modules through a requestment.txt file.

If you are familiar with python’s pip package manager, you will find that the requestment.txt file format of pikascript is the same as that of pip.

Create a new requestment.txt file in the pikascript folder of the project, and write the following content.


The requestment.txt file indicates the installation of the pikascript-core interpreter kernel and the PikaStdLib standard library. The interpreter kernel and the standard library are mandatory, while the other modules can be added optionally, and only the kernel and the standard library should be added during the initial deployment to avoid compatibility issues.

You can copy the requestment.txt kernel and standard library version of stm32g070, which is an officially supported development board The version used by Pika Pie-Zero.

And all optional versions can be viewed in the packages.toml file.

The lts2021 version refers to the long-term support version released at the end of 2021, and the support period is within 2022.

The usual version number is v1.x.x, the lts2021 version is based on v1.3.5 with stability patches.

The pikascript folder now has two files, pikaPackage.exe and requestment.txt. Double-click to run pikaPackage.exe, and the source code and modules specified in requestmemt.txt will be pulled down.


The pulled files are shown in the figure below, pikascript-core is the kernel source code, pikascript-lib is the module library, pikascript-api is the module API, and rust-msc-latest-win10.exe is the dedicated precompiler for pikascript.


After installation, the package manager will automatically lock the version and the requirement.txt will look like this


If you want to upgrade the version, modify the version number in requestment.txt and run pikaPackage.exe again, the original version will be overwritten.

After pulling the source code, the next step is to write the python script that pikascript runs.

We create a new main.py file in the pikascript folder.

Then write:

import PikaStdLib

print('hello PikaPython!')

Among them, import PikaStdLib means importing the standard library.

The standard library must be imported, even if it is not used directly, and print('hello PikaPython!') is used to test whether pikascript is started normally. Precompile modules

Next, run rust-msc-latest-win10.exe to precompile main.py and imported modules into pikascript api files.

The precompiled files are in the pikascript-api folder.


We open the pikascript-api folder and find that there are some .c and .h files in it, which means that the precompile is successful.

The pikascript precompiler can precompile C modules into .c and .h files.

_images/1644385073271-a39b8d40-f722-4a0c-9b50-e7357f0eae48.png Add source code

Create three new groups in Project, it is recommended to name them pikascript-core, pikascript-api and pikascript-lib


Then add all the .c files in the three subfolders of the pikascript folder (including the subfolder in pikascript-lib) to the keil project (the actual number of .c files may not match the screenshot, just add them all.)


Then add include paths for pikascript-core and pikascript-api folders.


_images/130967949-8399c65b-5584-4674-a947-e40103d953ea.png Adjust stack

Open the project’s startup file, in stm32, this is a startup_stm32xxxx.s file, and on other platforms, you have to figure out how to adjust the stack yourself.


It is recommended to allocate 4K stack space and 16K heap space, and at least 1K stack space and 4K heap space need to be allocated

4K stack space corresponds to 0x1000, 16K heap space corresponds to 0x4000, as shown in the following figure

_images/130967178-a985a4f5-730c-47fd-9317-68f33bc00066.png Start PikaPython

Add the startup code of PikaPython in the initialization code of main.c.

  • add header files

add in header file

 #include "pikascript.h"


  • initialize pikaScript and get the pointer to the pikascript main object pikaMain

Add a startup code to the main function

PikaObj* pikaMain = pikaScriptInit();


ended? Yes, it’s over, it’s that simple, isn’t it amazing.

This is because the precompiler does a lot of auxiliary work behind the scenes, including the automatic generation of the pikaScriptInit() function. compile source code

When compiling the source code, you need to check the C99 standard, and the compilation optimization level can be selected arbitrarily, and pikascript supports it.


Then you can compile it directly. Generally speaking, it can be passed directly.

You can use compiler version 5 or compiler version 6. Contribute BSP

We sincerely appreciate your contribution, by contributing code, you can help PikaPython run on more platforms, and more developers will benefit from you.

Please see the operation method: Add peripheral support

PikaPython manages peripherals through packages. To add peripheral support to the platform, please refer to the following documents: