From 0964bd356517187cbcae2869da7d5106bcbe566a Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Sat, 6 Nov 2021 10:12:55 +0800 Subject: [PATCH 01/10] Update README_zh.md --- README_zh.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README_zh.md b/README_zh.md index 128e07044..dfad590f1 100644 --- a/README_zh.md +++ b/README_zh.md @@ -23,6 +23,8 @@ PikaScript是一个完全重写的超轻量级python引擎,零依赖,零配 [PikaScript入门-单片机python编程和环境配置](https://www.bilibili.com/video/BV1mg411L72e) +[Pika派开发板手把手单片机python编程01——模块安装和GPIO类](https://www.bilibili.com/video/BV1kg411K7W2) + ## 中级篇 - 面向驱动开发者 [PikaScript中级 RISC-V部署PikaScript CH32V103R8](https://www.bilibili.com/video/BV1Cq4y1G7Tj) From bd3c53afc32b76096618dd8342a80fb2c7a0ac31 Mon Sep 17 00:00:00 2001 From: pikastech Date: Sat, 6 Nov 2021 17:11:56 +0800 Subject: [PATCH 02/10] add uart init for each example and tested ok --- bsp/stm32g030c8/MDK-ARM/stm32g030c8.uvprojx | 1 + examples/ADC/main.py | 6 ++++++ examples/GPIO/main.py | 6 ++++++ examples/PWM/main.py | 6 ++++++ examples/RGB/main.py | 12 ++++++------ examples/Snake/main.py | 7 +++++++ examples/Time/main.py | 6 ++++++ examples/UART/main.py | 3 ++- port/linux/api-make-linux.sh | 0 port/linux/api-make-win10.sh | 0 port/linux/api-make.sh | 0 port/linux/gtest.sh | 0 port/linux/init.sh | 0 port/linux/make.sh | 0 port/linux/package/pikascript/rust-msc-latest-linux | Bin port/linux/pull-core.sh | 0 port/linux/push-core.sh | 0 port/linux/test-banchmark.sh | 0 port/linux/update-compiler.sh | 0 19 files changed, 40 insertions(+), 7 deletions(-) mode change 100755 => 100644 port/linux/api-make-linux.sh mode change 100755 => 100644 port/linux/api-make-win10.sh mode change 100755 => 100644 port/linux/api-make.sh mode change 100755 => 100644 port/linux/gtest.sh mode change 100755 => 100644 port/linux/init.sh mode change 100755 => 100644 port/linux/make.sh mode change 100755 => 100644 port/linux/package/pikascript/rust-msc-latest-linux mode change 100755 => 100644 port/linux/pull-core.sh mode change 100755 => 100644 port/linux/push-core.sh mode change 100755 => 100644 port/linux/test-banchmark.sh mode change 100755 => 100644 port/linux/update-compiler.sh diff --git a/bsp/stm32g030c8/MDK-ARM/stm32g030c8.uvprojx b/bsp/stm32g030c8/MDK-ARM/stm32g030c8.uvprojx index 7b58d9ff0..4549b2c09 100644 --- a/bsp/stm32g030c8/MDK-ARM/stm32g030c8.uvprojx +++ b/bsp/stm32g030c8/MDK-ARM/stm32g030c8.uvprojx @@ -10,6 +10,7 @@ stm32g030c8 0x4 ARM-ADS + 6160000::V6.16::ARMCLANG 6160000::V6.16::ARMCLANG 1 diff --git a/examples/ADC/main.py b/examples/ADC/main.py index 414a66016..875e3e488 100644 --- a/examples/ADC/main.py +++ b/examples/ADC/main.py @@ -1,6 +1,12 @@ import PikaStdLib import STM32 +uart = STM32.UART() +uart.init() +uart.setId(1) +uart.setBaudRate(115200) +uart.enable() + time = STM32.Time() adc1 = STM32.ADC() diff --git a/examples/GPIO/main.py b/examples/GPIO/main.py index d3ff7b4f0..a42bd1df9 100644 --- a/examples/GPIO/main.py +++ b/examples/GPIO/main.py @@ -1,6 +1,12 @@ import PikaStdLib import STM32 +uart = STM32.UART() +uart.init() +uart.setId(1) +uart.setBaudRate(115200) +uart.enable() + mem = PikaStdLib.MemChecker() io1 = STM32.GPIO() time = STM32.Time() diff --git a/examples/PWM/main.py b/examples/PWM/main.py index 2c8e7c62d..2c4e6ff19 100644 --- a/examples/PWM/main.py +++ b/examples/PWM/main.py @@ -1,6 +1,12 @@ import PikaStdLib import STM32 +uart = STM32.UART() +uart.init() +uart.setId(1) +uart.setBaudRate(115200) +uart.enable() + time = STM32.Time() pwm = STM32.PWM() pwm.setPin('PA8') diff --git a/examples/RGB/main.py b/examples/RGB/main.py index a62a3b26d..7ef74306f 100644 --- a/examples/RGB/main.py +++ b/examples/RGB/main.py @@ -2,8 +2,13 @@ import STM32 import PikaPiZero import PikaStdLib -time = STM32.Time() uart = STM32.UART() +uart.init() +uart.setId(1) +uart.setBaudRate(115200) +uart.enable() + +time = STM32.Time() adc = STM32.ADC() pin = STM32.GPIO() pwm = STM32.PWM() @@ -11,11 +16,6 @@ uart = STM32.UART() rgb = PikaPiZero.RGB() mem = PikaStdLib.MemChecker() -uart.init() -uart.setId(1) -uart.setBaudRate(115200) -uart.enable() - rgb.init() rgb.enable() diff --git a/examples/Snake/main.py b/examples/Snake/main.py index 4efe68ebe..ae64aa415 100644 --- a/examples/Snake/main.py +++ b/examples/Snake/main.py @@ -2,6 +2,13 @@ from PikaObj import * import PikaStdLib import PikaPiZero import STM32 + +uart = STM32.UART() +uart.init() +uart.setId(1) +uart.setBaudRate(115200) +uart.enable() + pin = STM32.GPIO() pin.init() pin.setPin('PA0') diff --git a/examples/Time/main.py b/examples/Time/main.py index f45a823f4..88c399478 100644 --- a/examples/Time/main.py +++ b/examples/Time/main.py @@ -1,6 +1,12 @@ import PikaStdLib import STM32 +uart = STM32.UART() +uart.init() +uart.setId(1) +uart.setBaudRate(115200) +uart.enable() + time = STM32.Time() while True: diff --git a/examples/UART/main.py b/examples/UART/main.py index 067c1ec1d..26c9544d7 100644 --- a/examples/UART/main.py +++ b/examples/UART/main.py @@ -1,13 +1,14 @@ import PikaStdLib import STM32 -time = STM32.Time() uart = STM32.UART() uart.init() uart.setBaudRate(115200) uart.setId(1) uart.enable() +time = STM32.Time() + while True: time.sleep_ms(500) readBuff = uart.read(2) diff --git a/port/linux/api-make-linux.sh b/port/linux/api-make-linux.sh old mode 100755 new mode 100644 diff --git a/port/linux/api-make-win10.sh b/port/linux/api-make-win10.sh old mode 100755 new mode 100644 diff --git a/port/linux/api-make.sh b/port/linux/api-make.sh old mode 100755 new mode 100644 diff --git a/port/linux/gtest.sh b/port/linux/gtest.sh old mode 100755 new mode 100644 diff --git a/port/linux/init.sh b/port/linux/init.sh old mode 100755 new mode 100644 diff --git a/port/linux/make.sh b/port/linux/make.sh old mode 100755 new mode 100644 diff --git a/port/linux/package/pikascript/rust-msc-latest-linux b/port/linux/package/pikascript/rust-msc-latest-linux old mode 100755 new mode 100644 diff --git a/port/linux/pull-core.sh b/port/linux/pull-core.sh old mode 100755 new mode 100644 diff --git a/port/linux/push-core.sh b/port/linux/push-core.sh old mode 100755 new mode 100644 diff --git a/port/linux/test-banchmark.sh b/port/linux/test-banchmark.sh old mode 100755 new mode 100644 diff --git a/port/linux/update-compiler.sh b/port/linux/update-compiler.sh old mode 100755 new mode 100644 From e4aaef7608d5fdcd2de839d07a4d4175e8eae918 Mon Sep 17 00:00:00 2001 From: pikastech Date: Sat, 6 Nov 2021 19:11:25 +0800 Subject: [PATCH 03/10] fit std_device and stm32 package for core v1.2.0 --- .../bootloader/MDK-ARM/bootloader.uvprojx | 2 +- examples/ADC/main.py | 6 -- examples/GPIO/main.py | 6 -- examples/PWM/main.py | 6 -- examples/RGB/main.py | 6 -- examples/Snake/main.py | 7 -- examples/Time/main.py | 6 -- examples/UART/main.py | 5 +- package/PikaStdDevice/PikaStdDeivce_GPIO.c | 9 +- package/PikaStdDevice/PikaStdDevice.py | 24 ++--- package/PikaStdDevice/PikaStdDevice_ADC.c | 11 +-- package/PikaStdDevice/PikaStdDevice_IIC.c | 9 +- package/PikaStdDevice/PikaStdDevice_PWM.c | 17 ++-- package/PikaStdDevice/PikaStdDevice_UART.c | 13 ++- package/STM32/STM32.py | 24 ++--- package/STM32/STM32_ADC.c | 8 +- package/STM32/STM32_GPIO.c | 8 +- package/STM32/STM32_IIC.c | 91 +++++++++++-------- package/STM32/STM32_PWM.c | 13 ++- package/STM32/STM32_UART.c | 85 ++++++++++++----- package/STM32/STM32_common.h | 1 + package/STM32G030Booter/main.c | 47 ++++------ 22 files changed, 205 insertions(+), 199 deletions(-) diff --git a/bsp/PikaPi_Zero/bootloader/MDK-ARM/bootloader.uvprojx b/bsp/PikaPi_Zero/bootloader/MDK-ARM/bootloader.uvprojx index 57eb0eaab..232ba4671 100644 --- a/bsp/PikaPi_Zero/bootloader/MDK-ARM/bootloader.uvprojx +++ b/bsp/PikaPi_Zero/bootloader/MDK-ARM/bootloader.uvprojx @@ -138,7 +138,7 @@ 4101 1 - BIN\UL2V8M.DLL + BIN\UL2CM3.DLL diff --git a/examples/ADC/main.py b/examples/ADC/main.py index 875e3e488..414a66016 100644 --- a/examples/ADC/main.py +++ b/examples/ADC/main.py @@ -1,12 +1,6 @@ import PikaStdLib import STM32 -uart = STM32.UART() -uart.init() -uart.setId(1) -uart.setBaudRate(115200) -uart.enable() - time = STM32.Time() adc1 = STM32.ADC() diff --git a/examples/GPIO/main.py b/examples/GPIO/main.py index a42bd1df9..d3ff7b4f0 100644 --- a/examples/GPIO/main.py +++ b/examples/GPIO/main.py @@ -1,12 +1,6 @@ import PikaStdLib import STM32 -uart = STM32.UART() -uart.init() -uart.setId(1) -uart.setBaudRate(115200) -uart.enable() - mem = PikaStdLib.MemChecker() io1 = STM32.GPIO() time = STM32.Time() diff --git a/examples/PWM/main.py b/examples/PWM/main.py index 2c4e6ff19..2c8e7c62d 100644 --- a/examples/PWM/main.py +++ b/examples/PWM/main.py @@ -1,12 +1,6 @@ import PikaStdLib import STM32 -uart = STM32.UART() -uart.init() -uart.setId(1) -uart.setBaudRate(115200) -uart.enable() - time = STM32.Time() pwm = STM32.PWM() pwm.setPin('PA8') diff --git a/examples/RGB/main.py b/examples/RGB/main.py index 7ef74306f..b086bd986 100644 --- a/examples/RGB/main.py +++ b/examples/RGB/main.py @@ -2,12 +2,6 @@ import STM32 import PikaPiZero import PikaStdLib -uart = STM32.UART() -uart.init() -uart.setId(1) -uart.setBaudRate(115200) -uart.enable() - time = STM32.Time() adc = STM32.ADC() pin = STM32.GPIO() diff --git a/examples/Snake/main.py b/examples/Snake/main.py index ae64aa415..4efe68ebe 100644 --- a/examples/Snake/main.py +++ b/examples/Snake/main.py @@ -2,13 +2,6 @@ from PikaObj import * import PikaStdLib import PikaPiZero import STM32 - -uart = STM32.UART() -uart.init() -uart.setId(1) -uart.setBaudRate(115200) -uart.enable() - pin = STM32.GPIO() pin.init() pin.setPin('PA0') diff --git a/examples/Time/main.py b/examples/Time/main.py index 88c399478..f45a823f4 100644 --- a/examples/Time/main.py +++ b/examples/Time/main.py @@ -1,12 +1,6 @@ import PikaStdLib import STM32 -uart = STM32.UART() -uart.init() -uart.setId(1) -uart.setBaudRate(115200) -uart.enable() - time = STM32.Time() while True: diff --git a/examples/UART/main.py b/examples/UART/main.py index 26c9544d7..f852e6ecb 100644 --- a/examples/UART/main.py +++ b/examples/UART/main.py @@ -1,14 +1,13 @@ import PikaStdLib import STM32 +time = STM32.Time() uart = STM32.UART() uart.init() -uart.setBaudRate(115200) uart.setId(1) +uart.setBaudRate(115200) uart.enable() -time = STM32.Time() - while True: time.sleep_ms(500) readBuff = uart.read(2) diff --git a/package/PikaStdDevice/PikaStdDeivce_GPIO.c b/package/PikaStdDevice/PikaStdDeivce_GPIO.c index 63bc68214..f0fadf1da 100644 --- a/package/PikaStdDevice/PikaStdDeivce_GPIO.c +++ b/package/PikaStdDevice/PikaStdDeivce_GPIO.c @@ -39,7 +39,7 @@ void PikaStdDevice_GPIO_high(PikaObj* self) { } int PikaStdDevice_GPIO_read(PikaObj *self){ - obj_run(self, "readBuff = platformRead()"); + obj_run(self, "platformRead()"); return obj_getInt(self, "readBuff"); } @@ -62,7 +62,7 @@ void PikaStdDevice_GPIO_setPull(PikaObj *self, char * pull){ } } -void PikaStdDevice_GPIO_setPin(PikaObj* self, char* pinName) { +void PikaStdDevice_GPIO_setPin(PikaObj* self, char *pinName) { obj_setStr(self, "pin", pinName); } @@ -85,7 +85,7 @@ void PikaStdDevice_GPIO_platformHigh(PikaObj* self) { obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_GPIO_platformSetMode(PikaObj* self, char* mode) { +void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } @@ -100,8 +100,7 @@ void PikaStdDevice_GPIO_platformOn(PikaObj* self) { obj_setSysOut(self, "[error] platform method need to be override."); } -int PikaStdDevice_GPIO_platformRead(PikaObj *self){ +void PikaStdDevice_GPIO_platformRead(PikaObj *self){ obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); - return -1; } \ No newline at end of file diff --git a/package/PikaStdDevice/PikaStdDevice.py b/package/PikaStdDevice/PikaStdDevice.py index 650dac7e2..20ee044e1 100644 --- a/package/PikaStdDevice/PikaStdDevice.py +++ b/package/PikaStdDevice/PikaStdDevice.py @@ -52,11 +52,11 @@ class GPIO(TinyObj): pass # need override - def platformSetMode(mode: str): + def platformSetMode(): pass # need override - def platformRead()->int: + def platformRead(): pass @@ -84,11 +84,11 @@ class ADC(TinyObj): pass # need override - def platformEnable(pin: str): + def platformEnable(): pass # need override - def platformRead(pin: str) -> float: + def platformRead(): pass @@ -112,15 +112,15 @@ class UART(TinyObj): pass # need override - def platformEnable(id: int, baudRate: int): + def platformEnable(): pass # need override - def platformWrite(id: int, data: str): + def platformWrite(): pass # need override - def platformRead(id: int, length: int) -> str: + def platformRead(): pass @@ -151,11 +151,11 @@ class IIC(TinyObj): pass # need override - def platformWrite(addr: int, data: str): + def platformWrite(): pass # need override - def platformRead(addr: int, length: int) -> str: + def platformRead(): pass @@ -182,13 +182,13 @@ class PWM(TinyObj): pass # need override - def platformEnable(pin: str, freq: int, duty: float): + def platformEnable(): pass # need override - def platformSetFrequency(pin: str, freq: int): + def platformSetFrequency(): pass # need override - def platformSetDuty(pin: str, duty: float): + def platformSetDuty(): pass diff --git a/package/PikaStdDevice/PikaStdDevice_ADC.c b/package/PikaStdDevice/PikaStdDevice_ADC.c index 5b6a80d61..09610eb4b 100644 --- a/package/PikaStdDevice/PikaStdDevice_ADC.c +++ b/package/PikaStdDevice/PikaStdDevice_ADC.c @@ -2,7 +2,7 @@ #include "BaseObj.h" void PikaStdDevice_ADC_enable(PikaObj* self) { - obj_run(self, "platformEnable(pin)"); + obj_run(self, "platformEnable()"); } void PikaStdDevice_ADC_init(PikaObj* self) { @@ -10,21 +10,20 @@ void PikaStdDevice_ADC_init(PikaObj* self) { } float PikaStdDevice_ADC_read(PikaObj* self) { - obj_run(self, "val = platformRead(pin)"); + obj_run(self, "platformRead()"); return obj_getFloat(self, "val"); } -void PikaStdDevice_ADC_setPin(PikaObj* self, char* pin) { +void PikaStdDevice_ADC_setPin(PikaObj* self, char *pin) { obj_setStr(self, "pin", pin); } -void PikaStdDevice_ADC_platformEnable(PikaObj* self, char* pin) { +void PikaStdDevice_ADC_platformEnable(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -float PikaStdDevice_ADC_platformRead(PikaObj* self, char* pin) { +void PikaStdDevice_ADC_platformRead(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); - return -1; } \ No newline at end of file diff --git a/package/PikaStdDevice/PikaStdDevice_IIC.c b/package/PikaStdDevice/PikaStdDevice_IIC.c index 3f02fb589..a33888631 100644 --- a/package/PikaStdDevice/PikaStdDevice_IIC.c +++ b/package/PikaStdDevice/PikaStdDevice_IIC.c @@ -26,17 +26,17 @@ void PikaStdDevice_IIC_setPinSDA(PikaObj *self, char * pin){ void PikaStdDevice_IIC_write(PikaObj *self, int addr, char * data){ obj_setStr(self, "writeData", data); obj_setInt(self, "writeAddr", addr); - obj_run(self, "platformWrite(writeAddr, writeData)"); + obj_run(self, "platformWrite()"); } char * PikaStdDevice_IIC_read(PikaObj *self, int addr, int length){ obj_setInt(self, "length", length); obj_setInt(self, "readAddr", addr); - obj_run(self, "readData = platformRead(readAddr, length)"); + obj_run(self, "platformRead()"); return obj_getStr(self, "readData"); } -void PikaStdDevice_IIC_platformWrite(PikaObj *self, int addr, char * data){ +void PikaStdDevice_IIC_platformWrite(PikaObj *self){ obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } @@ -46,8 +46,7 @@ void PikaStdDevice_IIC_platformEnable(PikaObj *self){ obj_setSysOut(self, "[error] platform method need to be override."); } -char * PikaStdDevice_IIC_platformRead(PikaObj *self, int addr, int length){ +void PikaStdDevice_IIC_platformRead(PikaObj *self){ obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); - return NULL; } diff --git a/package/PikaStdDevice/PikaStdDevice_PWM.c b/package/PikaStdDevice/PikaStdDevice_PWM.c index deb50da70..521628d97 100644 --- a/package/PikaStdDevice/PikaStdDevice_PWM.c +++ b/package/PikaStdDevice/PikaStdDevice_PWM.c @@ -13,16 +13,16 @@ void PikaStdDevice_PWM_setPin(PikaObj* self, char* pin) { void PikaStdDevice_PWM_setFrequency(PikaObj* self, int freq) { obj_setInt(self, "freq", freq); - obj_run(self, "platformSetFrequency(pin, freq)"); + obj_run(self, "platformSetFrequency()"); } void PikaStdDevice_PWM_setDuty(PikaObj* self, float duty) { obj_setFloat(self, "duty", duty); - obj_run(self, "platformSetDuty(pin, duty)"); + obj_run(self, "platformSetDuty()"); } void PikaStdDevice_PWM_enable(PikaObj* self) { - obj_run(self, "platformEnable(pin, freq, duty)"); + obj_run(self, "platformEnable()"); } float PikaStdDevice_PWM_getDuty(PikaObj* self) { @@ -33,20 +33,15 @@ int PikaStdDevice_PWM_getFrequency(PikaObj* self) { return obj_getInt(self, "freq"); } -void PikaStdDevice_PWM_platformEnable(PikaObj* self, - float dute, - int freq, - char* pin) { +void PikaStdDevice_PWM_platformEnable(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_PWM_platformSetDuty(PikaObj* self, float duty, char* pin) { +void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self, - int freq, - char* pin) { +void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } diff --git a/package/PikaStdDevice/PikaStdDevice_UART.c b/package/PikaStdDevice/PikaStdDevice_UART.c index 60b51c0a9..c70cf0a0b 100644 --- a/package/PikaStdDevice/PikaStdDevice_UART.c +++ b/package/PikaStdDevice/PikaStdDevice_UART.c @@ -2,7 +2,7 @@ #include "BaseObj.h" void PikaStdDevice_UART_enable(PikaObj* self) { - obj_run(self, "platformEnable(id, baudRate)"); + obj_run(self, "platformEnable()"); } void PikaStdDevice_UART_init(PikaObj* self) { obj_setInt(self, "baudRate", 115200); @@ -11,7 +11,7 @@ void PikaStdDevice_UART_init(PikaObj* self) { } char* PikaStdDevice_UART_read(PikaObj* self, int length) { obj_setInt(self, "length", length); - obj_run(self, "readData = platformRead(id, length)"); + obj_run(self, "platformRead()"); return obj_getStr(self, "readData"); } void PikaStdDevice_UART_setBaudRate(PikaObj* self, int baudRate) { @@ -22,19 +22,18 @@ void PikaStdDevice_UART_setId(PikaObj* self, int id) { } void PikaStdDevice_UART_write(PikaObj* self, char* data) { obj_setStr(self, "writeData", data); - obj_run(self, "platformWrite(id, writeData)"); + obj_run(self, "platformWrite()"); } -void PikaStdDevice_UART_platformEnable(PikaObj* self, int baudRate, int id) { +void PikaStdDevice_UART_platformEnable(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -char* PikaStdDevice_UART_platformRead(PikaObj* self, int id, int length) { +void PikaStdDevice_UART_platformRead(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); - return NULL; } -void PikaStdDevice_UART_platformWrite(PikaObj* self, char* data, int id) { +void PikaStdDevice_UART_platformWrite(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } \ No newline at end of file diff --git a/package/STM32/STM32.py b/package/STM32/STM32.py index 63eb24527..0fa1c5874 100644 --- a/package/STM32/STM32.py +++ b/package/STM32/STM32.py @@ -20,11 +20,11 @@ class GPIO(PikaStdDevice.GPIO): pass # override - def platformSetMode(mode: str): + def platformSetMode(): pass # override - def platformRead() -> int: + def platformRead(): pass @@ -40,39 +40,39 @@ class Time(PikaStdDevice.Time): class ADC(PikaStdDevice.ADC): # override - def platformEnable(pin: str): + def platformEnable(): pass # override - def platformRead(pin: str) -> float: + def platformRead(): pass class UART(PikaStdDevice.UART): # override - def platformEnable(id: int, baudRate: int): + def platformEnable(): pass # override - def platformWrite(id: int, data: str): + def platformWrite(): pass # override - def platformRead(id: int, length: int) -> str: + def platformRead(): pass class PWM(PikaStdDevice.PWM): # override - def platformEnable(pin: str, freq: int, duty: float): + def platformEnable(): pass # override - def platformSetFrequency(pin: str, freq: int): + def platformSetFrequency(): pass # override - def platformSetDuty(pin: str, duty: float): + def platformSetDuty(): pass @@ -85,11 +85,11 @@ class IIC(PikaStdDevice.IIC): pass # override - def platformWrite(addr: int, data: str): + def platformWrite(): pass # override - def platformRead(addr: int, length: int) -> str: + def platformRead(): pass diff --git a/package/STM32/STM32_ADC.c b/package/STM32/STM32_ADC.c index 2abebb324..3b16cdd23 100644 --- a/package/STM32/STM32_ADC.c +++ b/package/STM32/STM32_ADC.c @@ -22,7 +22,8 @@ uint16_t Get_Adc(ADC_HandleTypeDef* hadc, uint32_t ch) { return (uint16_t)HAL_ADC_GetValue(hadc); } -void STM32_ADC_platformEnable(PikaObj* self, char* pin) { +void STM32_ADC_platformEnable(PikaObj* self) { + char *pin = obj_getStr(self, "pin"); if (!strIsStartWith(pin, "PA")) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] not match adc pin."); @@ -162,6 +163,7 @@ exit: return channel; } -float STM32_ADC_platformRead(PikaObj* self, char* pin) { - return 3.3f * Get_Adc(&pika_hadc1, getChannel(pin)) / 4096.0f; +void STM32_ADC_platformRead(PikaObj* self) { + char *pin = obj_getStr(self, "pin"); + obj_setFloat(self, "val", 3.3f * Get_Adc(&pika_hadc1, getChannel(pin)) / 4096.0f); } diff --git a/package/STM32/STM32_GPIO.c b/package/STM32/STM32_GPIO.c index 16ca74f10..3294ed7f0 100644 --- a/package/STM32/STM32_GPIO.c +++ b/package/STM32/STM32_GPIO.c @@ -105,9 +105,9 @@ void STM32_GPIO_platformHigh(PikaObj* self) { } HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET); } -void STM32_GPIO_platformSetMode(PikaObj* self, char* mode) { +void STM32_GPIO_platformSetMode(PikaObj* self) { char* pin = obj_getStr(self, "pin"); - + char *mode = obj_getStr(self, "mode"); if (0 != enableClk(pin)) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] not match gpio port."); @@ -142,7 +142,7 @@ void STM32_GPIO_platformSetMode(PikaObj* self, char* mode) { HAL_GPIO_Init(gpioPort, &GPIO_InitStruct); } -int STM32_GPIO_platformRead(PikaObj *self){ +void STM32_GPIO_platformRead(PikaObj *self){ char* pin = obj_getStr(self, "pin"); GPIO_TypeDef* gpioPort = getGpioPort(pin); if (NULL == gpioPort) { @@ -154,7 +154,7 @@ int STM32_GPIO_platformRead(PikaObj *self){ obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] not match gpio pin."); } - return HAL_GPIO_ReadPin(gpioPort,gpioPin); + obj_setInt(self, "readBuff", HAL_GPIO_ReadPin(gpioPort,gpioPin)); } int STM32_lowLevel_readPin(PikaObj *self, char * pin){ diff --git a/package/STM32/STM32_IIC.c b/package/STM32/STM32_IIC.c index d8ddaf4df..e03ca4f7f 100644 --- a/package/STM32/STM32_IIC.c +++ b/package/STM32/STM32_IIC.c @@ -1,35 +1,34 @@ #include "STM32_IIC.h" #include #include "BaseObj.h" -#include "STM32_common.h" #include "STM32_GPIO.h" +#include "STM32_common.h" #include "dataStrs.h" -typedef struct pika_IIC_info_t{ - GPIO_TypeDef *SCL_GPIO; - GPIO_TypeDef *SDA_GPIO; +typedef struct pika_IIC_info_t { + GPIO_TypeDef* SCL_GPIO; + GPIO_TypeDef* SDA_GPIO; uint32_t SCL_GPIO_Pin; uint32_t SDA_GPIO_Pin; uint8_t deviceAddr; - - uint8_t readBuff[32]; -}pika_IIC_info; + uint8_t readBuff[32]; +} pika_IIC_info; #define delay_rate 1 -void SDA_OUT(pika_IIC_info *iic){ +void SDA_OUT(pika_IIC_info* iic) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /*Configure GPIO*/ GPIO_InitStruct.Pin = iic->SDA_GPIO_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP ; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(iic->SDA_GPIO, &GPIO_InitStruct); } -void SDA_IN(pika_IIC_info *iic){ +void SDA_IN(pika_IIC_info* iic) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /*Configure GPIO*/ GPIO_InitStruct.Pin = iic->SDA_GPIO_Pin; @@ -39,31 +38,31 @@ void SDA_IN(pika_IIC_info *iic){ HAL_GPIO_Init(iic->SDA_GPIO, &GPIO_InitStruct); } -void IIC_SDA_high(pika_IIC_info *iic){ +void IIC_SDA_high(pika_IIC_info* iic) { HAL_GPIO_WritePin(iic->SDA_GPIO, iic->SDA_GPIO_Pin, GPIO_PIN_SET); } -void IIC_SDA_low(pika_IIC_info *iic){ +void IIC_SDA_low(pika_IIC_info* iic) { HAL_GPIO_WritePin(iic->SDA_GPIO, iic->SDA_GPIO_Pin, GPIO_PIN_RESET); } -void IIC_SCL_high(pika_IIC_info *iic){ +void IIC_SCL_high(pika_IIC_info* iic) { HAL_GPIO_WritePin(iic->SCL_GPIO, iic->SCL_GPIO_Pin, GPIO_PIN_SET); } -void IIC_SCL_low(pika_IIC_info *iic){ +void IIC_SCL_low(pika_IIC_info* iic) { HAL_GPIO_WritePin(iic->SCL_GPIO, iic->SCL_GPIO_Pin, GPIO_PIN_RESET); } -uint8_t READ_SDA(pika_IIC_info *iic){ +uint8_t READ_SDA(pika_IIC_info* iic) { return HAL_GPIO_ReadPin(iic->SDA_GPIO, iic->SDA_GPIO_Pin); } -void WRITE_SDA(pika_IIC_info *iic, uint8_t data){ +void WRITE_SDA(pika_IIC_info* iic, uint8_t data) { HAL_GPIO_WritePin(iic->SDA_GPIO, iic->SDA_GPIO_Pin, data); } -void IIC_Start(pika_IIC_info *iic) { +void IIC_Start(pika_IIC_info* iic) { SDA_OUT(iic); IIC_SDA_high(iic); IIC_SCL_high(iic); @@ -73,7 +72,7 @@ void IIC_Start(pika_IIC_info *iic) { IIC_SCL_low(iic); } -void IIC_Stop(pika_IIC_info *iic) { +void IIC_Stop(pika_IIC_info* iic) { SDA_OUT(iic); IIC_SCL_low(iic); IIC_SDA_low(iic); @@ -83,7 +82,7 @@ void IIC_Stop(pika_IIC_info *iic) { delay_us(delay_rate * 4); } -uint8_t IIC_Wait_Ack(pika_IIC_info *iic) { +uint8_t IIC_Wait_Ack(pika_IIC_info* iic) { uint8_t ucErrTime = 0; SDA_IN(iic); @@ -102,7 +101,7 @@ uint8_t IIC_Wait_Ack(pika_IIC_info *iic) { return 0; } -void IIC_Ack(pika_IIC_info *iic) { +void IIC_Ack(pika_IIC_info* iic) { IIC_SCL_low(iic); SDA_OUT(iic); @@ -113,7 +112,7 @@ void IIC_Ack(pika_IIC_info *iic) { IIC_SCL_low(iic); } -void IIC_NAck(pika_IIC_info *iic) { +void IIC_NAck(pika_IIC_info* iic) { IIC_SCL_low(iic); SDA_OUT(iic); @@ -124,7 +123,7 @@ void IIC_NAck(pika_IIC_info *iic) { IIC_SCL_low(iic); } -void IIC_Send_Byte(pika_IIC_info *iic, uint8_t txd) { +void IIC_Send_Byte(pika_IIC_info* iic, uint8_t txd) { uint8_t t; SDA_OUT(iic); @@ -140,7 +139,7 @@ void IIC_Send_Byte(pika_IIC_info *iic, uint8_t txd) { } } -uint8_t IIC_Read_Byte(pika_IIC_info *iic, unsigned char ack) { +uint8_t IIC_Read_Byte(pika_IIC_info* iic, unsigned char ack) { unsigned char i, receive = 0; SDA_IN(iic); @@ -160,7 +159,11 @@ uint8_t IIC_Read_Byte(pika_IIC_info *iic, unsigned char ack) { return receive; } -uint8_t MPU_Write_Len(pika_IIC_info *iic, uint8_t addr, uint8_t reg, uint8_t len, uint8_t* buf) { +uint8_t MPU_Write_Len(pika_IIC_info* iic, + uint8_t addr, + uint8_t reg, + uint8_t len, + uint8_t* buf) { uint8_t i; IIC_Start(iic); IIC_Send_Byte(iic, (addr << 1) | 0); @@ -181,7 +184,11 @@ uint8_t MPU_Write_Len(pika_IIC_info *iic, uint8_t addr, uint8_t reg, uint8_t len return 0; } -uint8_t MPU_Read_Len(pika_IIC_info *iic, uint8_t addr, uint8_t reg, uint8_t len, uint8_t* buf) { +uint8_t MPU_Read_Len(pika_IIC_info* iic, + uint8_t addr, + uint8_t reg, + uint8_t len, + uint8_t* buf) { IIC_Start(iic); IIC_Send_Byte(iic, (addr << 1) | 0); if (IIC_Wait_Ack(iic)) { @@ -205,7 +212,7 @@ uint8_t MPU_Read_Len(pika_IIC_info *iic, uint8_t addr, uint8_t reg, uint8_t len, return 0; } -void STM32_IIC_platformEnable(PikaObj *self){ +void STM32_IIC_platformEnable(PikaObj* self) { obj_run(self, "SCL.init()"); obj_run(self, "SDA.init()"); obj_run(self, "SCL.setPin(SCLpin)"); @@ -216,13 +223,13 @@ void STM32_IIC_platformEnable(PikaObj *self){ obj_run(self, "SDA.enable()"); obj_run(self, "SCL.low()"); obj_run(self, "SDA.low()"); - char *SCLpin = obj_getStr(self, "SCLpin"); - char *SDApin = obj_getStr(self, "SDApin"); + char* SCLpin = obj_getStr(self, "SCLpin"); + char* SDApin = obj_getStr(self, "SDApin"); uint8_t deviceAddr = obj_getInt(self, "deviceAddr"); - - pika_IIC_info *iic = obj_getPtr(self, "iic"); - if(NULL == iic){ - iic = pikaMalloc(sizeof(pika_IIC_info)); + + pika_IIC_info* iic = obj_getPtr(self, "iic"); + if (NULL == iic) { + iic = pikaMalloc(sizeof(pika_IIC_info)); obj_setPtr(self, "iic", iic); } iic->SDA_GPIO = getGpioPort(SDApin); @@ -233,15 +240,19 @@ void STM32_IIC_platformEnable(PikaObj *self){ SDA_OUT(iic); } -char * STM32_IIC_platformRead(PikaObj *self, int addr, int length){ - pika_IIC_info *iic = obj_getPtr(self, "iic"); - - MPU_Read_Len(iic, iic->deviceAddr, addr, length,(uint8_t *) iic->readBuff); - return (char *)iic->readBuff; +void STM32_IIC_platformRead(PikaObj* self) { + int addr = obj_getInt(self, "addr"); + int length = obj_getInt(self, "length"); + pika_IIC_info* iic = obj_getPtr(self, "iic"); + + MPU_Read_Len(iic, iic->deviceAddr, addr, length, (uint8_t*)iic->readBuff); + obj_setStr(self, "readData", (char*)iic->readBuff); } -void STM32_IIC_platformWrite(PikaObj *self, int addr, char * data){ - pika_IIC_info *iic = obj_getPtr(self, "iic"); +void STM32_IIC_platformWrite(PikaObj* self) { + int addr = obj_getInt(self, "addr"); + char* data = obj_getStr(self, "data"); + pika_IIC_info* iic = obj_getPtr(self, "iic"); - MPU_Write_Len(iic, iic->deviceAddr, addr, strGetSize(data), (uint8_t *)data); + MPU_Write_Len(iic, iic->deviceAddr, addr, strGetSize(data), (uint8_t*)data); } diff --git a/package/STM32/STM32_PWM.c b/package/STM32/STM32_PWM.c index 62532ac14..7f766a4b6 100644 --- a/package/STM32/STM32_PWM.c +++ b/package/STM32/STM32_PWM.c @@ -230,7 +230,10 @@ uint32_t getTimChennel(char* pin) { return 99999; } -void STM32_PWM_platformEnable(PikaObj* self, float duty, int freq, char* pin) { +void STM32_PWM_platformEnable(PikaObj* self) { + float duty = obj_getFloat(self, "duty"); + int freq = obj_getInt(self, "freq"); + char *pin = obj_getStr(self, "pin"); TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; @@ -334,7 +337,9 @@ void STM32_PWM_platformEnable(PikaObj* self, float duty, int freq, char* pin) { HAL_TIM_PWM_Start(pika_tim, getTimChennel(pin)); } -void STM32_PWM_platformSetDuty(PikaObj* self, float duty, char* pin) { +void STM32_PWM_platformSetDuty(PikaObj* self) { + float duty = obj_getFloat(self, "duty"); + char *pin = obj_getStr(self, "pin"); TIM_HandleTypeDef* pika_tim = getTimHandle(pin); if (NULL == pika_tim) { obj_setSysOut(self, "[error]: can not found PWM hardware."); @@ -348,7 +353,9 @@ void STM32_PWM_platformSetDuty(PikaObj* self, float duty, char* pin) { } } -void STM32_PWM_platformSetFrequency(PikaObj* self, int freq, char* pin) { +void STM32_PWM_platformSetFrequency(PikaObj* self) { + int freq = obj_getInt(self, "freq"); + char *pin = obj_getStr(self, "pin"); TIM_HandleTypeDef* pika_tim = getTimHandle(pin); if (NULL == pika_tim) { obj_setSysOut(self, "[error]: can not found PWM hardware."); diff --git a/package/STM32/STM32_UART.c b/package/STM32/STM32_UART.c index 851869566..2e788428b 100644 --- a/package/STM32/STM32_UART.c +++ b/package/STM32/STM32_UART.c @@ -19,6 +19,21 @@ pika_uart_t pika_uart3; pika_uart_t pika_uart4; #endif +UART_HandleTypeDef huart1; + +/* support prinf */ +int fputc(int ch, FILE* f) { + HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, 0xffff); + return ch; +} + +/* support scanf */ +int fgetc(FILE* f) { + uint8_t ch = 0; + HAL_UART_Receive(&huart1, &ch, 1, 0xffff); + return ch; +} + static pika_uart_t* getPikaUart(uint8_t id) { if (1 == id) { return &pika_uart1; @@ -338,11 +353,14 @@ void USART3_4_IRQHandler(void) { #endif #endif -void STM32_UART_platformEnable(PikaObj* self, int baudRate, int id) { -#ifdef Code_ENABLE - STM32_Code_Init(); -#endif +void STM32_UART_platformEnable(PikaObj* self) { + int id = obj_getInt(self, "id"); + int baudRate = obj_getInt(self, "baudRate"); setUartObj(id, self); + /* uart 1 is inited by hardward */ + if (1 == id) { + return; + } UART_HandleTypeDef* huart = getUartHandle(id); huart->Instance = getUartInstance(id); UART_MspInit(huart); @@ -355,7 +373,9 @@ void STM32_UART_platformEnable(PikaObj* self, int baudRate, int id) { HAL_UART_Receive_IT(getUartHandle(id), (uint8_t*)getUartRxBuff(id), 1); } -char* STM32_UART_platformRead(PikaObj* self, int id, int length) { +void STM32_UART_platformRead(PikaObj* self) { + int id = obj_getInt(self, "id"); + int length = obj_getInt(self, "length"); Args* buffs = New_strBuff(); char* readBuff = NULL; pika_uart_t* pika_uart = getPikaUart(id); @@ -379,10 +399,12 @@ char* STM32_UART_platformRead(PikaObj* self, int id, int length) { (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1); exit: args_deinit(buffs); - return readBuff; + obj_setStr(self,"readData", readBuff); } -void STM32_UART_platformWrite(PikaObj* self, char* data, int id) { +void STM32_UART_platformWrite(PikaObj* self) { + char *data = obj_getStr(self, "data"); + int id = obj_getInt(self, "id"); HAL_UART_Transmit(getUartHandle(id), (uint8_t*)data, strGetSize(data), 100); } @@ -418,14 +440,14 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) { pikaShellRxOk = 1; #endif } - /* avoid recive buff overflow */ + /* avoid recive buff overflow */ if (pika_uart->rxBuffOffset + 2 > RX_BUFF_LENGTH) { memmove(pika_uart->rxBuff, pika_uart->rxBuff + 1, RX_BUFF_LENGTH); UART_Start_Receive_IT( - huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1); + huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1); return; } - + /* recive next char */ pika_uart->rxBuffOffset++; pika_uart->rxBuff[pika_uart->rxBuffOffset] = 0; @@ -433,15 +455,36 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) { huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1); } -/* support prinf */ -int fputc(int ch, FILE* f) { - HAL_UART_Transmit(&pika_uart1.huart, (uint8_t*)&ch, 1, 0xffff); - return ch; -} +void HARDWARE_PRINTF_Init(void) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + __HAL_RCC_USART1_CLK_ENABLE(); -/* support scanf */ -int fgetc(FILE* f) { - uint8_t ch = 0; - HAL_UART_Receive(&pika_uart1.huart, &ch, 1, 0xffff); - return ch; -} \ No newline at end of file + __HAL_RCC_GPIOA_CLK_ENABLE(); + GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF1_USART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(USART1_IRQn); + huart1.Instance = USART1; + huart1.Init.BaudRate = 115200; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart1.Init.OverSampling = UART_OVERSAMPLING_16; + huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + HAL_UART_Init(&huart1); + HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8); + HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8); + HAL_UARTEx_DisableFifoMode(&huart1); + pika_uart1.huart = huart1; + pika_uart1.id = 1; + pika_uart1.obj = NULL; + HAL_UART_Receive_IT(getUartHandle(1), (uint8_t*)getUartRxBuff(1), 1); +} diff --git a/package/STM32/STM32_common.h b/package/STM32/STM32_common.h index 5303718d2..2df54209d 100644 --- a/package/STM32/STM32_common.h +++ b/package/STM32/STM32_common.h @@ -87,4 +87,5 @@ void STM32_UART_clearRxBuff(pika_uart_t* pika_uart); uint8_t STM32_Code_reciveHandler(char *data, uint32_t rxSize); void STM32_Code_Init(); void STM32_Code_flashHandler(); +void HARDWARE_PRINTF_Init(); #endif \ No newline at end of file diff --git a/package/STM32G030Booter/main.c b/package/STM32G030Booter/main.c index 6b878545a..6bed6756c 100644 --- a/package/STM32G030Booter/main.c +++ b/package/STM32G030Booter/main.c @@ -24,8 +24,8 @@ /* USER CODE BEGIN Includes */ #include "STM32_common.h" #include "pikaScript.h" -#include "stdbool.h" #include "pikaVM.h" +#include "stdbool.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -61,6 +61,7 @@ void SystemClock_Config(void); PikaObj* pikaMain; extern char pikaShell[RX_BUFF_LENGTH]; extern uint8_t pikaShellRxOk; + /* USER CODE END 0 */ /** @@ -96,61 +97,49 @@ int main(void) { /* set vector table*/ SCB->VTOR = FLASH_BASE | 0x2000; __enable_irq(); + + HARDWARE_PRINTF_Init(); + STM32_Code_Init(); - pikaMain = newRootObj("pikaMain", New_PikaMain); - obj_run(pikaMain, "uart = STM32.UART()"); - obj_run(pikaMain, "uart.init()"); - obj_run(pikaMain, "uart.setId(1)"); - obj_run(pikaMain, "uart.setBaudRate(115200)"); - obj_run(pikaMain, "uart.enable()"); - obj_run(pikaMain, "print('uart init ok')"); - obj_run(pikaMain, "remove('uart')"); - obj_deinit(pikaMain); + printf("stm32 hardware init ok\r\n"); char* code = (char*)FLASH_SCRIPT_START_ADDR; uint16_t codeOffset = 0; if (code[0] != 0xFF) { /* boot from flash */ pikaMain = newRootObj("pikaMain", New_PikaMain); - if(code[0] == 'i'){ + if (code[0] == 'i') { printf("[info]: boot from Script.\r\n"); - Arg *codeBuff = arg_setStr(NULL, "", code); + Arg* codeBuff = arg_setStr(NULL, "", code); obj_run(pikaMain, arg_getStr(codeBuff)); arg_deinit(codeBuff); } - if(code[0] == 'B'){ - printf("[info]: boot from Pika Asm.\r\n"); - printf("%s\n",code); - printf("asm size: %d\n", strGetSize(code)); + if (code[0] == 'B') { + printf("[info]: boot from Pika Asm.\r\n"); + printf("%s\n", code); + printf("asm size: %d\r\n", strGetSize(code)); pikaVM_runAsm(pikaMain, code); } } else { /* boot from firmware */ pikaMain = pikaScriptInit(); } - /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ while (1) { - if(pikaShellRxOk){ - Args * runRes = obj_runDirect(pikaMain, pikaShell); - char* sysOut = args_getSysOut(runRes); - uint8_t errcode = args_getErrorCode(runRes); + if (pikaShellRxOk) { + Parameters* runRes = obj_runDirect(pikaMain, pikaShell); + char* sysOut = args_getSysOut(runRes->attributeList); + uint8_t errcode = args_getErrorCode(runRes->attributeList); __platformPrintf(">>> %s", pikaShell); if (!strEqu("", sysOut)) { __platformPrintf("%s\r\n", sysOut); } if (NULL != runRes) { - args_deinit(runRes); - } + obj_deinit(runRes); + } pikaShellRxOk = 0; } - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ } /** From 1156cb2967ef7720fbfa397d3dc870a5cbe87699 Mon Sep 17 00:00:00 2001 From: pikastech Date: Sat, 6 Nov 2021 19:15:27 +0800 Subject: [PATCH 04/10] update to latest bsp req --- bsp/stm32g030c8/pikascript/requestment.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bsp/stm32g030c8/pikascript/requestment.txt b/bsp/stm32g030c8/pikascript/requestment.txt index feb820fd0..516a0b014 100644 --- a/bsp/stm32g030c8/pikascript/requestment.txt +++ b/bsp/stm32g030c8/pikascript/requestment.txt @@ -1,6 +1,6 @@ -pikascript-core==v1.1.3 +pikascript-core==v1.2.0 PikaStdLib==v1.1.0 -PikaStdDevice==v1.4.1 -STM32==v1.4.1 +PikaStdDevice==latest +STM32==latest PikaPiZero==latest STM32G030Booter==latest \ No newline at end of file From a39894368d85ec19582c4242555ca343bf5ce8c4 Mon Sep 17 00:00:00 2001 From: pikastech Date: Sat, 6 Nov 2021 19:33:13 +0800 Subject: [PATCH 05/10] debug booter and support \r\n asm print --- package/STM32G030Booter/main.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/package/STM32G030Booter/main.c b/package/STM32G030Booter/main.c index 6bed6756c..2b4213a1f 100644 --- a/package/STM32G030Booter/main.c +++ b/package/STM32G030Booter/main.c @@ -97,7 +97,7 @@ int main(void) { /* set vector table*/ SCB->VTOR = FLASH_BASE | 0x2000; __enable_irq(); - + HARDWARE_PRINTF_Init(); STM32_Code_Init(); @@ -113,18 +113,29 @@ int main(void) { Arg* codeBuff = arg_setStr(NULL, "", code); obj_run(pikaMain, arg_getStr(codeBuff)); arg_deinit(codeBuff); + goto main_loop; } if (code[0] == 'B') { - printf("[info]: boot from Pika Asm.\r\n"); - printf("%s\n", code); + printf("==============[Pika ASM]==============\r\n"); + for(int i = 0; i < strGetSize(code); i ++){ + if('\n' == code[i]){ + fputc('\r', (FILE*)!NULL); + } + fputc(code[i], (FILE*)!NULL); + } + printf("==============[Pika ASM]==============\r\n"); printf("asm size: %d\r\n", strGetSize(code)); + printf("[info]: boot from Pika Asm.\r\n"); pikaVM_runAsm(pikaMain, code); + goto main_loop; } } else { /* boot from firmware */ pikaMain = pikaScriptInit(); + goto main_loop; } + main_loop: while (1) { if (pikaShellRxOk) { Parameters* runRes = obj_runDirect(pikaMain, pikaShell); From 2b997c0ca03ba9ef00fd4f09155a9f508db1371b Mon Sep 17 00:00:00 2001 From: pikastech Date: Sat, 6 Nov 2021 19:38:34 +0800 Subject: [PATCH 06/10] lock std device version for bsps --- bsp/ch32v103r8/PikaScript/requestment.txt | 2 +- bsp/stm32f103c8/pikascript/requestment.txt | 4 ++-- bsp/stm32g070cb/pikascript/requestment.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bsp/ch32v103r8/PikaScript/requestment.txt b/bsp/ch32v103r8/PikaScript/requestment.txt index c6ccaf81b..ad5f2f51a 100644 --- a/bsp/ch32v103r8/PikaScript/requestment.txt +++ b/bsp/ch32v103r8/PikaScript/requestment.txt @@ -1,5 +1,5 @@ pikascript-core==v1.1.1 PikaStdLib==v1.1.0 CH32V103R8Booter==v1.0.0 -PikaStdDevice==latest +PikaStdDevice==v1.4.1 CH32V103==latest \ No newline at end of file diff --git a/bsp/stm32f103c8/pikascript/requestment.txt b/bsp/stm32f103c8/pikascript/requestment.txt index ab67ec80e..230bd549d 100644 --- a/bsp/stm32f103c8/pikascript/requestment.txt +++ b/bsp/stm32f103c8/pikascript/requestment.txt @@ -1,6 +1,6 @@ pikascript-core==v0.9.0 -PikaStdLib==latest -PikaStdDevice==latest +PikaStdLib==v1.1.0 +PikaStdDevice==v1.4.1 STM32==v1.1.1 PikaMath==v1.0.0 PikaRunExternControl==v1.0.0 \ No newline at end of file diff --git a/bsp/stm32g070cb/pikascript/requestment.txt b/bsp/stm32g070cb/pikascript/requestment.txt index ab67ec80e..230bd549d 100644 --- a/bsp/stm32g070cb/pikascript/requestment.txt +++ b/bsp/stm32g070cb/pikascript/requestment.txt @@ -1,6 +1,6 @@ pikascript-core==v0.9.0 -PikaStdLib==latest -PikaStdDevice==latest +PikaStdLib==v1.1.0 +PikaStdDevice==v1.4.1 STM32==v1.1.1 PikaMath==v1.0.0 PikaRunExternControl==v1.0.0 \ No newline at end of file From 58338191d62c8fc989d322c007dbbd27ff14db01 Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Sat, 6 Nov 2021 19:44:22 +0800 Subject: [PATCH 07/10] Update CI.yml --- .github/workflows/CI.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9f7adf222..67f60625a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -24,8 +24,10 @@ jobs: - name: PULL_CORE run: cd ${{github.workspace}}/port/linux && bash pull-core.sh - - name: INIT + - name: CHMOD + run: cd ${{github.workspace}}/port/linux/package/pikascript && chmod +x ./rust-msc-latest-linux + - name: INIT run: cd ${{github.workspace}}/port/linux && bash init.sh - name: TEST From e3c0e895987580d10c78f51d6a474824f09d2248 Mon Sep 17 00:00:00 2001 From: pikastech Date: Sun, 7 Nov 2021 11:04:20 +0800 Subject: [PATCH 08/10] chmox +x for sh --- port/linux/api-make-linux.sh | 0 port/linux/api-make-win10.sh | 0 port/linux/api-make.sh | 0 port/linux/gtest.sh | 0 port/linux/init.sh | 0 port/linux/make.sh | 0 port/linux/package/pikascript/rust-msc-latest-linux | Bin port/linux/pull-core.sh | 0 port/linux/push-core.sh | 0 port/linux/test-banchmark.sh | 0 port/linux/update-compiler.sh | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 port/linux/api-make-linux.sh mode change 100644 => 100755 port/linux/api-make-win10.sh mode change 100644 => 100755 port/linux/api-make.sh mode change 100644 => 100755 port/linux/gtest.sh mode change 100644 => 100755 port/linux/init.sh mode change 100644 => 100755 port/linux/make.sh mode change 100644 => 100755 port/linux/package/pikascript/rust-msc-latest-linux mode change 100644 => 100755 port/linux/pull-core.sh mode change 100644 => 100755 port/linux/push-core.sh mode change 100644 => 100755 port/linux/test-banchmark.sh mode change 100644 => 100755 port/linux/update-compiler.sh diff --git a/port/linux/api-make-linux.sh b/port/linux/api-make-linux.sh old mode 100644 new mode 100755 diff --git a/port/linux/api-make-win10.sh b/port/linux/api-make-win10.sh old mode 100644 new mode 100755 diff --git a/port/linux/api-make.sh b/port/linux/api-make.sh old mode 100644 new mode 100755 diff --git a/port/linux/gtest.sh b/port/linux/gtest.sh old mode 100644 new mode 100755 diff --git a/port/linux/init.sh b/port/linux/init.sh old mode 100644 new mode 100755 diff --git a/port/linux/make.sh b/port/linux/make.sh old mode 100644 new mode 100755 diff --git a/port/linux/package/pikascript/rust-msc-latest-linux b/port/linux/package/pikascript/rust-msc-latest-linux old mode 100644 new mode 100755 diff --git a/port/linux/pull-core.sh b/port/linux/pull-core.sh old mode 100644 new mode 100755 diff --git a/port/linux/push-core.sh b/port/linux/push-core.sh old mode 100644 new mode 100755 diff --git a/port/linux/test-banchmark.sh b/port/linux/test-banchmark.sh old mode 100644 new mode 100755 diff --git a/port/linux/update-compiler.sh b/port/linux/update-compiler.sh old mode 100644 new mode 100755 From e0c2f114b3ac6e9303d6ab495917de7c8dd360db Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Tue, 9 Nov 2021 13:32:55 +0800 Subject: [PATCH 09/10] Update README_zh.md --- README_zh.md | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/README_zh.md b/README_zh.md index dfad590f1..c80ff15cf 100644 --- a/README_zh.md +++ b/README_zh.md @@ -17,6 +17,16 @@ PikaScript是一个完全重写的超轻量级python引擎,零依赖,零配 ![image](https://user-images.githubusercontent.com/88232613/138021445-13643518-b0a3-4872-a290-5dec27697837.png) +# 获取PikaScript: + +## 使用Pika包管理器[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe) + +1. 直接运行[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe), 自动下载并更新pikaScript主仓库(文件在当前磁盘的/tmp/pikaScript文件夹) + +2. 将[requestment.txt](/bsp/stm32g030c8/pikascript/requestment.txt)放在[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe)同一文件夹下, 运行[pikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe), 自动在当前目录下安装[内核](../../tree/master/src)、[预编译器](../../tree/master/tools/pikaCompiler)与[模块](../../tree/master/package)。 + +3. 已发布的模块列表:[packages.toml](/packages.toml) + # 视频教程 ## 入门篇 - 面向单片机Python编程用户 @@ -45,15 +55,19 @@ PikaScript是一个完全重写的超轻量级python引擎,零依赖,零配 [PikaScript进阶-数据结构源码精讲](https://www.bilibili.com/video/BV1Ky4y157nW/) -# 获取PikaScript: +# 开发手册 -## 使用Pika包管理器[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe) +[1. PikaScript-三分钟快速上手](document/1.三分钟快速上手.md) -1. 直接运行[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe), 自动下载并更新pikaScript主仓库(文件在当前磁盘的/tmp/pikaScript文件夹) +[2. PikaScript-架构与原理](https://mp.weixin.qq.com/s?__biz=MzU4NzUzMDc1OA==&mid=2247484127&idx=1&sn=f66cff49c488e48c52570c7bb570328f&chksm=fdebd5b6ca9c5ca0707fd221c32f3ad63e94aeb6f917a92774b89ea042381ea261990f5cca3c&token=2045971639&lang=zh_CN#rd) -2. 将[requestment.txt](/bsp/stm32g030c8/pikascript/requestment.txt)放在[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe)同一文件夹下, 运行[pikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe), 自动在当前目录下安装[内核](../../tree/master/src)、[预编译器](../../tree/master/tools/pikaCompiler)与[模块](../../tree/master/package)。 +[3. PikaScript-十分钟快速部署](document/2.十分钟快速部署.md) -3. 已发布的模块列表:[packages.toml](/packages.toml) +[4. PikaScript-标准开发流程](document/3.PikaScript标准开发流程.md) + +[5. PikaScript-Demo展示](document/5.我就要用最便宜的单片机来跑python,还要用Keil开发,怎么地吧.md) + +[6. Arm-2D GUI引擎和pikascript联合仿真](document/6.用Python玩ARM%202D,认真的嘛.md) ## 文件目录 [src](../../tree/master/src) - 内核源码 @@ -141,24 +155,6 @@ PikaScript是一个完全重写的超轻量级python引擎,零依赖,零配 完整的googletest单元测试。 -### (5)stm32例程 - -[pikascript-stm32-demo](../../tree/master/bsp) - -### (6)开发手册 - -[1. PikaScript-三分钟快速上手](document/1.三分钟快速上手.md) - -[2. PikaScript-架构与原理](https://mp.weixin.qq.com/s?__biz=MzU4NzUzMDc1OA==&mid=2247484127&idx=1&sn=f66cff49c488e48c52570c7bb570328f&chksm=fdebd5b6ca9c5ca0707fd221c32f3ad63e94aeb6f917a92774b89ea042381ea261990f5cca3c&token=2045971639&lang=zh_CN#rd) - -[3. PikaScript-十分钟快速部署](document/2.十分钟快速部署.md) - -[4. PikaScript-标准开发流程](document/3.PikaScript标准开发流程.md) - -[5. PikaScript-Demo展示](document/5.我就要用最便宜的单片机来跑python,还要用Keil开发,怎么地吧.md) - -[6. Arm-2D GUI引擎和pikascript联合仿真](document/6.用Python玩ARM%202D,认真的嘛.md) - # 4.交流与技术支持: ## 微信交流群 From 4d2bc09b0bf4a9fea6fe0c7a12aee1ccbf227adf Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Tue, 9 Nov 2021 13:33:37 +0800 Subject: [PATCH 10/10] Update README.md --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d9cf7138e..bae2792ed 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,20 @@ It's very easy to bind C function to python module with the help of Pika Pre-com 3. Released modules:[packages.toml](packages.toml) +# 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) + ## Folders [src](../../tree/master/src) - core code @@ -117,20 +131,6 @@ Readability first, nearly never use macro function and global argument. Complete unit testes based on google test. -### (5)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) - # 4.Both talk and show the code: ## E-mail: liang6516@outlook.com