3.1. Deploy to new platform in ten minutes
3.1.1. How to choose a platform that can run pikascript
PikaScript 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.
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.
3.1.2. Deployment operation process
In this document, we will describe how to deploy PikaScript for new platforms.
PikaScript has almost no global variables and macros, and only depends on the standard library, so it is very easy to deploy PikaScript for new platforms.
Here are the specific steps to deploy PikaScript
184.108.40.206. 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.
220.127.116.11. Get PikaScript 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.
18.104.22.168.1. Scenario 1 Using pika package manager
22.214.171.124.1.1. Download PikaScript Package Manager
PikaScript 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 PikaScript package manager uses gitee source, which can be used smoothly in the mainland, does not require scientific Internet access.
Enter the PikaScript main repository
Download the PikaScript 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.
126.96.36.199.1.2. 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.
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.
import PikaStdLib print('hello PikaScript!')
import PikaStdLib means importing the standard library.
The standard library must be imported, even if it is not used directly, and
print('hello PikaScript!') is used to test whether pikascript is started normally.
188.8.131.52.2. Option 2 Use the project generator on the official website
Enter the official website: http://pikascript.com/
Select the template for the platform, and then click “Start Generation” to get the default reqeustment.txt, main.py, and pikaPackages.exe.
When the project is generated, the source code and tools are automatically packaged.
184.108.40.206. Precompiled 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.
220.127.116.11. 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.
18.104.22.168. 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
22.214.171.124. Start PikaScript
Add the startup code of PikaScript in the initialization code of main.c.
add header files
add in header file
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
126.96.36.199. 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.
188.8.131.52. Contribute BSP
We sincerely appreciate your contribution, by contributing code, you can help PikaScript run on more platforms, and more developers will benefit from you.
Please see the operation method:
184.108.40.206. Add peripheral support
PikaScript manages peripherals through packages. To add peripheral support to the platform, please refer to the following documents: