pikapython/README.md

220 lines
8.6 KiB
Markdown
Raw Normal View History

2021-10-19 19:50:14 +08:00
<img align="left" src="https://emojis.slackmojis.com/emojis/images/1563480763/5999/meow_party.gif" width="60" height="60"/>
[![CI](https://github.com/pikasTech/pikascript/actions/workflows/CI.yml/badge.svg)](https://github.com/pikasTech/pikascript/actions/workflows/CI.yml)
2021-10-21 07:33:12 +08:00
2021-10-21 07:33:28 +08:00
## Star please~
2021-10-21 07:33:12 +08:00
2021-10-21 07:32:42 +08:00
# PikaScript
[中文页](README_zh.md)|
2021-10-19 19:50:14 +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
3. Released modulespackages.toml
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-10-19 20:04:41 +08:00
# 2.Device driver
2021-10-19 19:50:14 +08:00
|MCU/Board|gpio|uart|pwm|adc|rgb|i2c|spi|
|---|---|---|---|---|---|---|---|
|[PikaPi Zero](https://item.taobao.com/item.htm?spm=a230r.1.14.1.4f2e27a8R0qWJn&id=654947372034&ns=1&abbucket=15#detail)|√|√|√|√|√| | |
|stm32g030c8|√|√|√|√|-| | |
|stm32g070cB|√|√|√|√|-| | |
|stm32f103c8|√|√|√|√|-| | |
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, stm32f103c8t6esp8266.
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-19 20:25:26 +08:00
Support method invoke, argument define, new object, free object and control flow(if\while). - Based on [Pika Runtime Core](../../tree/master/src/package/pikascript/pikascript-core).
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
### (4)Develop standard.
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
Readability firstnearly 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
### (5)Document
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
[1. PikaScript-Quick start within 3 minutes](document/1.三分钟快速上手.md)
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
[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)
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
[3. PikaScript-Deploy within 10 minutes](document/2.十分钟快速部署.md)
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
[4. PikaScript-Standard develop workflow](document/3.PikaScript标准开发流程.md)
2021-10-19 19:50:14 +08:00
2021-10-19 20:25:26 +08:00
[5. PikaScript-Demo show](document/5.我就要用最便宜的单片机来跑python还要用Keil开发怎么地吧.md)
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:31:59 +08:00
## QQ group:
2021-10-19 23:55:19 +08:00
<img src="https://user-images.githubusercontent.com/88232613/136304186-e49610e4-ce01-4524-99b6-b56842d56411.png" width="300" alt="微信交流群"/><br/>
2021-10-19 20:31:59 +08:00
2021-10-19 20:26:04 +08:00
# 5.Contribute
| Content | Contributer |
2021-10-19 19:50:14 +08:00
| --- | --- |
2021-10-19 20:25:26 +08:00
| DonateGD32E103TB muc 2 pic | 信息牛(WeChat) |
| Rt-thread bsp template| [Meco Jianting Man](https://github.com/mysterywolf) |
| DonateEC600S-CN 4G module | 移远模块 |
| DonateBL706 board|博流智能 [bouffalolab](https://github.com/bouffalolab)|
| DonateCM32M101A board| 孟巍(WeChat) |
| DonateAPM32F030R8 board | 极海半导体 陈成 |
| DonateAPM32E103VB board | 极海半导体 陈成 |
| DonateAPEX-Link debugger | 极海半导体 陈成 |
| format codeadd 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-19 20:25:26 +08:00
## Demo 04 OWM 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)