2021-12-01 18:45:41 +08:00
< p align = "center" >
2021-12-01 18:49:14 +08:00
< img alt = "logo" src = "https://user-images.githubusercontent.com/88232613/144221063-a85b2cb0-0416-493f-9afb-56cff31e977d.jpg" width = "300" >
2021-12-01 18:45:41 +08:00
< / p >
< h1 align = "center" style = "margin: 30px 0 30px; font-weight: bold;" > PikaScript< / h1 >
< h4 align = "center" > Cross platform ultra lightweight embedded Python engine< / h4 >
< p align = "center" >
< a href = "https://gitee.com/lyon1998/pikascript/stargazers" > < img src = "https://gitee.com/lyon1998/pikascript/badge/star.svg?theme=gvp" > < / a >
< a href = "https://gitee.com/lyon1998/pikascript/members" > < img src = "https://gitee.com/lyon1998/pikascript/badge/fork.svg?theme=gvp" > < / a >
< a href = "https://github.com/pikastech/pikascript/stargazers" > < img src = "https://img.shields.io/github/stars/pikastech/pikascript?style=flat-square&logo=GitHub" > < / a >
< a href = "https://github.com/pikastech/pikascript/network/members" > < img src = "https://img.shields.io/github/forks/pikastech/pikascript?style=flat-square&logo=GitHub" > < / a >
< a href = "https://github.com/pikastech/pikascript/watchers" > < img src = "https://img.shields.io/github/watchers/pikastech/pikascript?style=flat-square&logo=GitHub" > < / a >
< a href = "https://github.com/pikastech/pikascript/issues" > < img src = "https://img.shields.io/github/issues/pikastech/pikascript.svg?style=flat-square&logo=GitHub" > < / a >
< a href = "https://github.com/pikastech/pikascript/blob/master/LICENSE" > < img src = "https://img.shields.io/github/license/pikastech/pikascript.svg?style=flat-square" > < / a >
< a href = "https://github.com/pikasTech/pikascript/actions/workflows/CI.yml" > < img src = "https://github.com/pikasTech/pikascript/actions/workflows/CI.yml/badge.svg" > < / a >
< / p >
2021-11-17 17:32:48 +08:00
2021-12-01 18:45:41 +08:00
< p align = "center" >
2021-12-03 09:01:25 +08:00
< a href = "README_zh.md" > 中文页< / a > |
< a href = "https://whycan.com/f_55.html" > Forum< / a > |
2021-12-07 14:10:24 +08:00
< a href = "https://www.yuque.com/liang-mltek/pikascript/nz7dgl?translate=en" > Documents< / a > |
2021-12-03 09:10:21 +08:00
< a href = "https://space.bilibili.com/5365336/channel/detail?cid=202329" > Videos< / a > |
2021-12-14 04:24:41 +00:00
< a href = "../../tree/master/bsp #platform -support" > BSP</ a > |
2021-12-14 04:25:59 +00:00
< a href = "https://www.yuque.com/liang-mltek/pikascript/of8izq?translate=en" > Package Manager< / a > |
2021-12-14 04:24:41 +00:00
< a href = "https://www.yuque.com/liang-mltek/pikascript/wcc36r?translate=en" > rtthread pkg< / a > |
< a href = "https://www.yuque.com/liang-mltek/pikascript/il3an0?translate=en" > Contribute< / a > |
< a href = "https://www.yuque.com/liang-mltek/pikascript/cp1k24?translate=en" > Business< / a >
2021-12-01 18:45:41 +08:00
< / p >
2021-10-21 07:33:12 +08:00
2021-10-20 10:29:40 +08:00
# 1. Abstract
2021-10-20 10:33:13 +08:00
PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run with 4KB of RAM and 32KB of flash (such as STM32G030C8 and STM32F103C8).
2021-10-20 10:35:43 +08:00
< img src = "https://user-images.githubusercontent.com/88232613/138018674-93a7991a-5367-4fbd-92ee-95c7f0f157fc.png" width = "500" / >
2021-10-20 10:29:40 +08:00
2021-10-20 11:22:14 +08:00
It's very easy to bind C function to python module with the help of Pika Pre-compiler.
2021-10-20 11:19:54 +08:00
2021-10-20 11:21:09 +08:00
< img src = "https://user-images.githubusercontent.com/88232613/138021445-13643518-b0a3-4872-a290-5dec27697837.png" width = "700" / >
2021-10-20 11:04:30 +08:00
2021-10-20 11:19:54 +08:00
# [【Video】PikaScript hand by hand](https://www.bilibili.com/video/BV1mg411L72e)
2021-10-19 20:04:41 +08:00
# Get PikaScript:
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
## Use Pika package manager [PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe)
2021-10-19 19:50:14 +08:00
2021-10-21 07:56:30 +08:00
1. Run the [PikaPackage.exe ](../../raw/master/tools/pikaPackageManager/pikaPackage.exe ) directly, then the pikascript repo would be downloaded auto in the /tmp/pikascript folder of your current disc partition.
2021-10-19 20:40:51 +08:00
2021-10-21 07:56:30 +08:00
2. Add [requestment.txt ](/bsp/stm32g030c8/pikascript/requestment.txt ) to the same folder of PikaPackage.exe then run [PikaPackage.exe ](../../raw/master/tools/pikaPackageManager/pikaPackage.exe ). The [run-time core ](../../tree/master/src ), [pre-compiler ](../../tree/master/tools/pikaCompiler ) and [moudles ](../../tree/master/package ) would be installed in the current folder.
2021-10-19 20:40:51 +08:00
2021-10-21 07:57:07 +08:00
3. Released modules: [packages.toml ](packages.toml )
2021-10-19 20:40:51 +08:00
2021-11-11 15:10:11 +08:00
# Quick Start
You can use [simulation project ](document/1.三分钟快速上手.md ) to quick start without hardware, or use the out-of-the-box develop board [Pika-Pi—Zero ](https://item.taobao.com/item.htm?spm=a1z10.3-c.w4023-23991764790.10.16f97c58fsLjVk&id=654947372034 ).
![image ](https://user-images.githubusercontent.com/88232613/141252834-93011ca7-f84b-4192-8e61-0e242796f62c.png )
The board based on STM32G030C8T6 MCU, only 64kB Flash, 8kB RAM can run PikaScript with total peripheral device (GPIO、TIME、IIC、RGB、KEY、LCD、RGB).
CH340 is deployed to support USB to serial with Type-C USB, support download python script py serial, there are 4 RGB on the board and support the [LCD ](https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-23991764791.12.16f97c58fsLjVk&id=660745643102 ).
2021-11-09 13:33:37 +08:00
# Document
[1. PikaScript-Quick start within 3 minutes ](document/1.三分钟快速上手.md )
[2. PikaScript-Architecture and principle ](https://mp.weixin.qq.com/s?__biz=MzU4NzUzMDc1OA==&mid=2247484127&idx=1&sn=f66cff49c488e48c52570c7bb570328f&chksm=fdebd5b6ca9c5ca0707fd221c32f3ad63e94aeb6f917a92774b89ea042381ea261990f5cca3c&token=2045971639&lang=zh_CN#rd )
[3. PikaScript-Deploy within 10 minutes ](document/2.十分钟快速部署.md )
[4. PikaScript-Standard develop workflow ](document/3.PikaScript标准开发流程.md )
[5. PikaScript-Demo show ](document/5.我就要用最便宜的单片机来跑python, 还要用Keil开发, 怎么地吧.md )
[6. Arm-2D simulation ](document/6.用Python玩ARM%202D, 认真的嘛.md )
2021-10-19 20:04:41 +08:00
## Folders
[src ](../../tree/master/src ) - core code
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
[bsp ](../../tree/master/bsp ) - mcu/board support
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
[port ](../../tree/master/port ) - OS support
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
[document ](../../tree/master/document ) - developt document
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
[examples ](../../tree/master/examples ) - example scripts
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
[package ](../../tree/master/package ) - packages and moudles
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
[pikaCompiler ](../../tree/master/tools/pikaCompiler ) - pre-compiler write by Rust, used to bind C function to python moudle.
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
[pikaPackageManager ](../../tree/master/tools/pikaPackageManager ) - pacakge manager
2021-10-19 19:50:14 +08:00
2021-12-02 23:24:24 +08:00
# 2.Platform support
2021-12-14 19:06:49 +08:00
## MCU support
|MCU|bsp|gpio|uart|pwm|adc|i2c|
|---|---|---|---|---|---|---|
|stm32g030c8|√|√|√|√|√|√|
|stm32g070cB|√|√|√|√|√|√|
|stm32f103c8|√|√|√|√|√|√|
|stm32f103rb|√|√|√|√|√|√|
|stm32f103rc|√|√|√|√|√|√|
|ch32v103r8t6|√|√| | | | |
|cm32m101a|√| | | | | |
|w801|√| | | | | | | | |
|apm32f030r8|√| | | | | |
|apm32e103vb|√| | | | | |
|bl-706|√| | | | | |
## Board support
|Board|bsp|gpio|uart|pwm|adc|i2c|rgb|lcd|arm-2d|
|---|---|---|---|---|---|---|---|---|---|
|[Pika-Pi-Zero ](https://item.taobao.com/item.htm?spm=a230r.1.14.1.4f2e27a8R0qWJn&id=654947372034&ns=1&abbucket=15#detail )|√|√|√|√|√|√|√|√|√|
2021-12-21 15:54:47 +00:00
|Board|bsp|gpio|uart|pwm|adc|i2c|
|---|---|---|---|---|---|---|
|Raspberry Pico|√| | | | | |
|ESP32(preview)|√| | | | | |
|Board|bsp|arm-2d|
|---|---|---|
|QEMU-arm2d|√|√|
|Board|bsp|LED|KEY|
|---|---|---|---|
|SmartLoong|√|√|√|√|
2021-12-02 16:01:41 +08:00
2021-12-21 16:16:45 +00:00
## OS support
|OS|port|GPIO|TIME|
|---|---|---|---|
|rt-thread|√|√|√|
2021-12-22 01:00:40 +08:00
|vsf|√|√| |
2021-12-21 16:16:45 +00:00
|OS|port|Google Test|Banch Mark|
|---|---|---|---|
|linux|√|√|√|
2021-10-19 20:04:41 +08:00
# 3.Characteristic
### (1)Run environment
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
Support run in mcu without OS or file system. Can run in everywhere with **RAM ≥ 4kB** and **FLASH ≥ 32kB** , such as stm32g030, stm32f103c8t6, esp8266.
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
### (2)Develop enviroment
Support run and program python scripts by serial.
2021-10-19 19:50:14 +08:00
< img src = "https://user-images.githubusercontent.com/88232613/134841230-85de6734-8467-4245-93a5-d452b5022b42.gif" width = "400" alt = "微信交流群" / > < br / >
2021-10-19 20:04:41 +08:00
Support IDEs like Keil, IAR, rt-thread studio and segger embedded studio to develop C moudle.
2021-10-19 19:50:14 +08:00
2021-10-19 20:04:41 +08:00
Support build tools like CMake, makeFile and Scons.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
Zero dependencies, zero configuration, out-of-the-box, easy to integrated into privious C projcet.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
Eazy to extern customized C moudles.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
Support linux.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
### (3)Syntax
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
Support subaggregate of python 3 standard syntax.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
Support class and method define, encapsulation-inheritance-polymorphism and moudles in compile time - Based on [Pika Pre-compiler ](../../tree/master/tools/pikaCompiler ).
2021-10-19 19:50:14 +08:00
2021-10-22 07:26:24 +08:00
Support method invoke, argument define, new object, free object, control flow(if\while) and operator ( + - * / < == > ). - Based on [Pika Runtime Core ](../../tree/master/src/package/pikascript/pikascript-core ).
2021-10-19 19:50:14 +08:00
2021-10-25 16:07:09 +08:00
|Syntax|Compile-Time|Run-Time|
|---|---|---|
2021-12-14 19:08:46 +08:00
|Class Define |√|-|
|Class Inherit |√|-|
2021-11-02 10:33:02 +08:00
|Method Define |√|√|
|Method Override |√|√|
2021-10-25 16:07:09 +08:00
|Method Invoke |√|√|
|Module Import |√|√|
|Argument Define |√|√|
|Argument Assignment |√|√|
|Object New |√|√|
|Object Free |√|√|
|Object Nest |√|√|
#### Operator
2021-11-28 17:42:56 +08:00
| + | - | * | / | == | > | < | >= | <= | % | * * | // | != | & | >> | << | and | or | not | += | -= | *= | /= |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|√|√|√|√|√|√|√|√|√|√|√|√|√|√|√|√|√|√|√| | | | |
2021-10-25 16:07:09 +08:00
#### Control flow
2021-12-02 11:17:07 +08:00
| if | while | for | else | elif | break | continue |
| --- | --- | --- | --- | --- | --- | --- |
2021-12-14 14:18:36 +00:00
|√|√| |√|√| | |
2021-10-19 20:25:26 +08:00
### (4)Develop standard.
2021-10-19 19:50:14 +08:00
2021-10-21 10:26:35 +08:00
Readability first, nearly never use macro function and global argument.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
Complete unit testes based on google test.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
# 4.Both talk and show the code:
2021-10-19 19:50:14 +08:00
2021-10-21 07:34:26 +08:00
## E-mail: liang6516@outlook.com
2021-10-19 19:50:14 +08:00
## Tencent QQ: 645275593
2021-10-19 20:26:04 +08:00
# 5.Contribute
| Content | Contributer |
2021-10-19 19:50:14 +08:00
| --- | --- |
2021-12-21 16:16:45 +00:00
| PikaVSF OS package | [versaloon ](https://github.com/versaloon ) |
2021-12-19 14:05:49 +00:00
| ESP32 BSP |kirto|
2021-11-02 09:43:53 +08:00
| QEMU simulation with ARM-2D | [liuduanfei ](https://github.com/liuduanfei ) |
2021-10-19 20:25:26 +08:00
| Donate: GD32E103TB muc 2 pic | 信息牛(WeChat) |
| Rt-thread bsp template| [Meco Jianting Man ](https://github.com/mysterywolf ) |
| Donate: EC600S-CN 4G module | 移远模块 |
| Donate: BL706 board|博流智能 [bouffalolab ](https://github.com/bouffalolab )|
| Donate: CM32M101A board| 孟巍(WeChat) |
| Donate: APM32F030R8 board | 极海半导体 陈成 |
| Donate: APM32E103VB board | 极海半导体 陈成 |
| Donate: APEX-Link debugger | 极海半导体 陈成 |
| format code, add gitattribute | [Meco Jianting Man ](https://github.com/mysterywolf ) |
| demo/simulation-keil | 千帆(WeChat) |
2021-10-19 19:50:14 +08:00
| demo/stm32f103zet6/demo01-led-stm32f103zet6 | [甜航 ](https://github.com/easyzoom ) |
| demo/stm32f103zet6/demo02-led-stm32f103zet6_tworoot | [甜航 ](https://github.com/easyzoom ) |
| demo/stm32f407zgt/demo01-led-stm32f407vgt | [甜航 ](https://github.com/easyzoom ) |
2021-10-19 20:25:26 +08:00
# 6.Test and develop Core
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
## Test core in linux(ubuntu20.04 is recommend):
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
step1: Clone the repo
2021-10-19 19:50:14 +08:00
``` shell
git clone https://github.com/pikastech/pikascript
2021-10-19 20:25:26 +08:00
cd pikascript/port/linux
2021-10-19 19:50:14 +08:00
```
2021-10-19 20:25:26 +08:00
step2: Compile the project
2021-10-19 19:50:14 +08:00
```
2021-10-19 20:25:26 +08:00
sh init.sh # Only nedded in the first time.
sh make.sh # Compile the project.
2021-10-19 19:50:14 +08:00
```
2021-10-19 20:25:26 +08:00
step3: Run the unit tests.
2021-10-19 19:50:14 +08:00
``` shell
2021-10-21 07:40:12 +08:00
sh gtest.sh
2021-10-19 19:50:14 +08:00
```
2021-10-19 20:25:26 +08:00
step4: Run the banchmark
2021-10-19 19:50:14 +08:00
``` shell
sh test-banchmark.sh
```
2021-10-19 20:25:26 +08:00
step5: Run the demo
2021-10-19 19:50:14 +08:00
``` shell
./build/src/boot/demo06-pikamain/pikascript_demo06-pikamain
```
2021-10-21 07:36:51 +08:00
# 7.Demo
2021-10-21 07:38:50 +08:00
The scripts in demos are in the [examples ](examples ) folder.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
## Demo 01 GPIO
2021-10-19 19:50:14 +08:00
![mmexport1631351506111 ](https://user-images.githubusercontent.com/88232613/132943903-b3558929-a107-4a99-bdc4-1b3fd3f7172b.png )
![Hnet-image (2) ](https://user-images.githubusercontent.com/88232613/132943428-f2b365ca-140e-42f4-936c-db6a7d9f8dee.gif )
2021-10-19 20:25:26 +08:00
## Demo 02 USART
2021-10-19 19:50:14 +08:00
![mmexport1631351902469 ](https://user-images.githubusercontent.com/88232613/132944132-90898355-de94-4d81-990b-7b85d4a4d08a.png )
![Hnet-image (3) ](https://user-images.githubusercontent.com/88232613/132943365-0f7059b3-4f9d-4989-a5ec-2cce72b0cc96.gif )
2021-10-19 20:25:26 +08:00
## Demo 03 ADC
2021-10-19 19:50:14 +08:00
![mmexport1631351527609 ](https://user-images.githubusercontent.com/88232613/132944180-a805c8f8-40d5-45ff-ae2a-a0fe8f9db1ab.png )
![mmexport1631351523907 ](https://user-images.githubusercontent.com/88232613/132944185-0a01b1ba-8cf7-4f9f-9d73-fe9cbcd52f0b.png )
2021-10-21 08:07:45 +08:00
## Demo 04 PWM output
2021-10-19 19:50:14 +08:00
![image ](https://user-images.githubusercontent.com/88232613/134461673-975498f4-09de-4f3a-866d-53e6fa1307b1.png )
2021-10-19 20:25:26 +08:00
## Demo 05 RGB
2021-10-19 19:50:14 +08:00
![image ](https://user-images.githubusercontent.com/88232613/134461950-2153c738-0661-452f-956a-65a88fb71592.png )
2021-10-21 07:43:25 +08:00
The maximum RAM usage of these demos is only 3.56K, which is 4.56K if the 1K stack is included, and the maximum Flash usage is 30.4K. Refer to the 20K RAM and 64K Flash of STM32F103C8T6, less than 25% RAM and less than 50% Flash are used.
A quick comparison can be made between the microPython chip STM32F405RG and the PikaScript chip STM32G070CB.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
## RAM resource comparison
2021-10-19 19:50:14 +08:00
![image ](https://user-images.githubusercontent.com/88232613/132944731-a55ece1d-061f-4b91-ba87-bd6547be96a7.png )
2021-10-19 20:25:26 +08:00
## Flash Resource Comparison
2021-10-19 19:50:14 +08:00
![image ](https://user-images.githubusercontent.com/88232613/132944745-e9cf598d-e75f-40bb-873e-911819d535b7.png )
2021-10-19 20:25:26 +08:00
## Reference price comparison (take the selling price of 10 pieces in Lichuang Mall on September 11, 2021 as reference)
2021-10-19 19:50:14 +08:00
![image ](https://user-images.githubusercontent.com/88232613/132944757-2b5cfda8-f93f-4456-8d7f-4e4767954056.png )
2021-10-21 07:45:47 +08:00
## About the custom extern module ?
2021-10-19 19:50:14 +08:00
2021-10-21 07:46:58 +08:00
In addition to device drivers, developing custom Python modules for MCU is very easy. The following two demos are extensions of the custom module, which developed python interfaces for the ARM-2D image driver library.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
## Boxes~
2021-10-19 19:50:14 +08:00
![Hnet-image (7) ](https://user-images.githubusercontent.com/88232613/132945282-bfd310df-8063-456d-b90c-6b798a2c8ed5.gif )
2021-10-19 20:25:26 +08:00
## Rotating suns~
2021-10-19 19:50:14 +08:00
![Hnet-image (6) ](https://user-images.githubusercontent.com/88232613/132945107-e473a2cc-9fbc-47f9-aaed-a28d3ad1048c.gif )