3.1. Deploy to new platform in ten minutes

    • 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 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

    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.

    3.1.2.2. 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.

    3.1.2.2.1. Scenario 1 Using pika package manager

    3.1.2.2.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

    https://github.com/pikastech/pikascript

    or:

    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.

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

    3.1.2.2.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 interpreter kernel and the standard library are required options.

    The version numbers of the two can be the same, and the other Modules can be added selectively, on initial deployment, only the kernel and standard libraries should be added to avoid compatibility issues.

    Currently only the == symbol is supported, which means strictly matching the version number. There is also a special version of latest, which means to pull the latest module.

    This latest refers to the latest version of the master branch in the pikascript repository.

    If you are a user of the module rather than a developer, please be careful not to use the latest version. Because the latest version is constantly changing, newer versions of modules may cause compatibility issues.

    You can copy the 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 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.

    https://user-images.githubusercontent.com/88232613/171088378-ea6385fb-56aa-4b87-afae-891d69b2f783.png

    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:

    Among them, means importing the standard library.

    The standard library must be imported, even if it is not used directly, and is used to test whether pikascript is started normally.

    3.1.2.2.2. Option 2 Use the project generator on the official website

    Enter the official website:

    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.

    3.1.2.3. 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.

    https://user-images.githubusercontent.com/88232613/171088576-8bbb420b-c2c5-4f01-b280-f88d45c89f9e.png

    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.

    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 in the pikascript folder to the keil project (the actual number of .c files may be inconsistent with the screenshots, just add them all.)

    _images/130971776-41d8c940-42d0-407d-872e-53525ce299a6.png

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

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

    3.1.2.5. 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

    3.1.2.6. 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

    _images/130969274-ff2fdf6f-2389-466b-b51e-e7bc33472558.png

    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 function.

    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.

    3.1.2.8. 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:

    3.1.2.9. Add peripheral support

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