update use old stm32 to stm32f1

This commit is contained in:
pikastech 2021-12-11 20:12:20 +08:00
parent 9aa06359c2
commit bce5c1fb98
7 changed files with 217 additions and 122 deletions

View File

@ -314,7 +314,7 @@
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>5</Optim>
<Optim>2</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>1</OneElfS>
@ -333,7 +333,7 @@
<v6LangP>3</v6LangP>
<vShortEn>1</vShortEn>
<vShortWch>1</vShortWch>
<v6Lto>1</v6Lto>
<v6Lto>0</v6Lto>
<v6WtE>0</v6WtE>
<v6Rtti>0</v6Rtti>
<VariousControls>
@ -669,6 +669,26 @@
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-api\STM32F1-api.c</FilePath>
</File>
<File>
<FileName>STM32F1_ADC-api.c</FileName>
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-api\STM32F1_ADC-api.c</FilePath>
</File>
<File>
<FileName>STM32F1_IIC-api.c</FileName>
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-api\STM32F1_IIC-api.c</FilePath>
</File>
<File>
<FileName>STM32F1_PWM-api.c</FileName>
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-api\STM32F1_PWM-api.c</FilePath>
</File>
<File>
<FileName>STM32F1_UART-api.c</FileName>
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-api\STM32F1_UART-api.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -684,6 +704,26 @@
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-lib\STM32F1\STM32F1_GPIO.c</FilePath>
</File>
<File>
<FileName>STM32F1_IIC.c</FileName>
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-lib\STM32F1\STM32F1_IIC.c</FilePath>
</File>
<File>
<FileName>STM32F1_PWM.c</FileName>
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-lib\STM32F1\STM32F1_PWM.c</FilePath>
</File>
<File>
<FileName>STM32F1_UART.c</FileName>
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-lib\STM32F1\STM32F1_UART.c</FilePath>
</File>
<File>
<FileName>STM32F1_ADC.c</FileName>
<FileType>1</FileType>
<FilePath>..\pikascript\pikascript-lib\STM32F1\STM32F1_ADC.c</FilePath>
</File>
<File>
<FileName>STM32F1_Time.c</FileName>
<FileType>1</FileType>
@ -741,8 +781,8 @@
<RTE>
<apis/>
<components>
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.3.0" condition="ARMv6_7_8-M Device">
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.6.0"/>
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.5.0" condition="ARMv6_7_8-M Device">
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.8.0"/>
<targetInfos>
<targetInfo name="stm32f103c8"/>
</targetInfos>

View File

@ -1,5 +1,5 @@
pikascript-core==v1.2.6
PikaStdLib==v1.2.1
PikaStdDevice==v1.4.3
STM32F1==v1.0.1
STM32F1==latest
STM32F103C8Booter==v1.0.0

View File

@ -38,62 +38,61 @@ class Time(PikaStdDevice.Time):
pass
# class ADC(PikaStdDevice.ADC):
# # override
# def platformEnable():
# pass
class ADC(PikaStdDevice.ADC):
# override
def platformEnable():
pass
# # override
# def platformRead():
# pass
# override
def platformRead():
pass
# class UART(PikaStdDevice.UART):
# # override
# def platformEnable():
# pass
class UART(PikaStdDevice.UART):
# override
def platformEnable():
pass
# # override
# def platformWrite():
# pass
# override
def platformWrite():
pass
# # override
# def platformRead():
# pass
# override
def platformRead():
pass
# class PWM(PikaStdDevice.PWM):
# # override
# def platformEnable():
# pass
class PWM(PikaStdDevice.PWM):
# override
def platformEnable():
pass
# # override
# def platformSetFrequency():
# pass
# override
def platformSetFrequency():
pass
# # override
# def platformSetDuty():
# pass
# override
def platformSetDuty():
pass
# class IIC(PikaStdDevice.IIC):
# SCL = GPIO()
# SDA = GPIO()
# # override
class IIC(PikaStdDevice.IIC):
SCL = GPIO()
SDA = GPIO()
# override
# def platformEnable():
# pass
def platformEnable():
pass
# # override
# def platformWrite():
# pass
# override
def platformWrite():
pass
# # override
# def platformRead():
# pass
# override
def platformRead():
pass
class lowLevel(TinyObj):
def readPin(pin: str) -> int:
pass

View File

@ -2,47 +2,47 @@
#include "BaseObj.h"
#include "STM32F1_common.h"
#include "dataStrs.h"
#include "stm32f1xx_ll_gpio.h"
void STM32F1_GPIO_platformDisable(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
char* mode = obj_getStr(self, "mode");
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = GPIO_get_pin(pin);
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
HAL_GPIO_DeInit(gpioPort,gpioPin);
HAL_GPIO_DeInit(gpioPort, gpioPin);
}
void STM32F1_GPIO_platformEnable(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
char* mode = obj_getStr(self, "mode");
if (0 != GPIO_enable_clock(pin)) {
if (0 != enableClk(pin)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
return;
}
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = GPIO_get_pin(pin);
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
@ -50,18 +50,18 @@ void STM32F1_GPIO_platformEnable(PikaObj* self) {
}
/*Configure GPIO pin Output Level */
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
uint32_t pinMode = getPinMode(mode);
uint32_t gpioPull = GPIO_NOPULL;
char* pull = obj_getStr(self, "pull");
if (strEqu(pull, "up")) {
char *pull = obj_getStr(self, "pull");
if(strEqu(pull, "up")){
gpioPull = GPIO_PULLUP;
} else if (strEqu(pull, "down")) {
}else if(strEqu(pull, "down")){
gpioPull = GPIO_PULLDOWN;
}
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO*/
GPIO_InitStruct.Pin = gpioPin;
@ -72,61 +72,55 @@ void STM32F1_GPIO_platformEnable(PikaObj* self) {
}
void STM32F1_GPIO_platformLow(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = GPIO_get_pin(pin);
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
WRITE_REG(gpioPort->BSRR, (uint32_t)gpioPin << 16U);
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
}
void STM32F1_GPIO_platformHigh(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = GPIO_get_pin(pin);
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
WRITE_REG(gpioPort->BSRR, gpioPin);
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
}
void STM32F1_GPIO_platformSetMode(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
char* mode = obj_getStr(self, "mode");
if (0 != GPIO_enable_clock(pin)) {
char *mode = obj_getStr(self, "mode");
if (0 != enableClk(pin)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
return;
}
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = GPIO_get_pin(pin);
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
@ -134,7 +128,7 @@ void STM32F1_GPIO_platformSetMode(PikaObj* self) {
}
/*Configure GPIO pin Output Level */
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
uint32_t pinMode = getPinMode(mode);
@ -147,31 +141,31 @@ void STM32F1_GPIO_platformSetMode(PikaObj* self) {
HAL_GPIO_Init(gpioPort, &GPIO_InitStruct);
}
void STM32F1_GPIO_platformRead(PikaObj* self) {
void STM32F1_GPIO_platformRead(PikaObj *self){
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = GPIO_get_pin(pin);
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
obj_setInt(self, "readBuff", LL_GPIO_IsInputPinSet(gpioPort, gpioPin));
obj_setInt(self, "readBuff", HAL_GPIO_ReadPin(gpioPort,gpioPin));
}
int STM32F1_lowLevel_readPin(PikaObj* self, char* pin) {
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
int STM32F1_lowLevel_readPin(PikaObj *self, char * pin){
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = GPIO_get_pin(pin);
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
return LL_GPIO_IsInputPinSet(gpioPort, gpioPin);
}
return HAL_GPIO_ReadPin(gpioPort,gpioPin);
}

View File

@ -1,7 +1,7 @@
#include <stdint.h>
#include "BaseObj.h"
#include "STM32F1_common.h"
#include "STM32F1_common.h"
void STM32F1_Time_sleep_ms(PikaObj* self, int ms) {
HAL_Delay(ms);
@ -10,4 +10,4 @@ void STM32F1_Time_sleep_s(PikaObj* self, int s) {
for (int i = 0; i < s; i++) {
HAL_Delay(1000);
}
}
}

View File

@ -1,7 +1,52 @@
#include "STM32F1_common.h"
#include "dataStrs.h"
GPIO_TypeDef* GPIO_get_Group(char* pin) {
void __platformDisableIrqHandle(){
__disable_irq();
}
void __platformEnableIrqHandle(){
__enable_irq();
}
void delay_unit(uint32_t delays) {
/* one unit is 1/64 us */
uint32_t startval, tickn, wait;
startval = SysTick->VAL;
tickn = HAL_GetTick();
if (delays > startval) {
while (HAL_GetTick() == tickn) {
}
wait = 64000 + startval - delays;
while (wait < SysTick->VAL) {
}
} else {
wait = startval - delays;
while (wait < SysTick->VAL && HAL_GetTick() == tickn) {
}
}
}
void delay_us(uint32_t udelay) {
uint32_t startval, tickn, delays, wait;
startval = SysTick->VAL;
tickn = HAL_GetTick();
delays = udelay * 64; // delay 1us when delays = 64
if (delays > startval) {
while (HAL_GetTick() == tickn) {
}
wait = 64000 + startval - delays;
while (wait < SysTick->VAL) {
}
} else {
wait = startval - delays;
while (wait < SysTick->VAL && HAL_GetTick() == tickn) {
}
}
}
GPIO_TypeDef* getGpioPort(char* pin) {
if (strIsStartWith(pin, "PA")) {
return GPIOA;
}
@ -17,7 +62,7 @@ GPIO_TypeDef* GPIO_get_Group(char* pin) {
return NULL;
}
uint16_t GPIO_get_pin(char* pin) {
uint16_t getGpioPin(char* pin) {
Args* buffs = New_strBuff();
uint16_t gpioPin = 0;
@ -102,7 +147,7 @@ uint32_t getPinMode(char* mode) {
return NULL;
}
uint8_t GPIO_enable_clock(char* pin) {
uint8_t enableClk(char* pin) {
if (strIsStartWith(pin, "PA")) {
__HAL_RCC_GPIOA_CLK_ENABLE();
return 0;
@ -120,4 +165,4 @@ uint8_t GPIO_enable_clock(char* pin) {
return 0;
}
return 1;
}
}

View File

@ -1,19 +1,13 @@
#ifndef __STM32F1__COMMON__H
#define __STM32F1__COMMON__H
#ifndef __STM32__COMMON__H
#define __STM32__COMMON__H
#include "PikaObj.h"
#include "main.h"
#include <stdint.h>
#include "stm32f1xx_hal.h"
/* support std lib for stm32 */
#undef u16
#undef u8
#undef u32
#define u16 uint16_t
#define u8 uint8_t
#define u32 uint32_t
#define delay_ms HAL_Delay
typedef uint16_t u16;
typedef uint8_t u8;
typedef uint32_t u32;
#define GPIO_Pin_0 GPIO_PIN_0
#define GPIO_Pin_1 GPIO_PIN_1
@ -32,7 +26,8 @@
#define GPIO_Pin_14 GPIO_PIN_14
#define GPIO_Pin_15 GPIO_PIN_15
#ifdef STM32F103xB
#include "stm32f1xx_hal.h"
#define UART1_EXIST
#define UART2_EXIST
#define UART3_EXIST
@ -41,24 +36,46 @@
#define TIM2_EXIST
#define TIM3_EXIST
#define TIM4_EXIST
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;
GPIO_TypeDef* GPIO_get_Group(char* pin);
uint16_t GPIO_get_pin(char* pin);
uint32_t getPinMode(char* mode);
uint8_t GPIO_enable_clock(char* pin);
#endif
#define RX_BUFF_LENGTH 64
#define FLASH_SCRIPT_START_ADDR (FLASH_BASE + ((FLASH_PAGE_NB - 2) * FLASH_PAGE_SIZE))
#define FLASH_SCRIPT_END_ADDR (FLASH_BASE + FLASH_SIZE - 1)
#define FLASH_PIKA_ASM_START_ADDR FLASH_SCRIPT_START_ADDR
#define FLASH_PIKA_ASM_END_ADDR FLASH_SCRIPT_END_ADDR
uint32_t GetPage(uint32_t Addr);
#define DATA_64 ((uint64_t)0x1234567812345678)
#define DATA_32 ((uint32_t)0x12345678)
typedef struct {
UART_HandleTypeDef huart;
uint8_t id;
char rxBuff[RX_BUFF_LENGTH];
uint16_t rxBuffOffset;
PikaObj* obj;
} pika_uart_t;
typedef struct _CodeHeap{
char *content;
uint32_t size;
uint8_t ena;
uint32_t reciveTime;
uint32_t oldSize;
}CodeHeap;
GPIO_TypeDef* getGpioPort(char* pin);
uint16_t getGpioPin(char* pin);
uint32_t getPinMode(char* mode);
uint8_t enableClk(char* pin);
void delay_us(uint32_t delay);
void delay_unit(uint32_t delay);
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