mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
support write bytecode to flash
This commit is contained in:
parent
1a1e09c6f5
commit
564d1c80f4
@ -26,6 +26,7 @@
|
|||||||
#include "pikaVM.h"
|
#include "pikaVM.h"
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
#include "pika_config.h"
|
#include "pika_config.h"
|
||||||
|
#include "pikaParser.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@ -98,21 +99,21 @@ int main(void) {
|
|||||||
|
|
||||||
/* boot pikaScript */
|
/* boot pikaScript */
|
||||||
char* code = (char*)FLASH_SCRIPT_START_ADDR;
|
char* code = (char*)FLASH_SCRIPT_START_ADDR;
|
||||||
if (code[0] != 0xFF) {
|
if ((code[0] != 0xFF) && (code[1] != 0xFF)) {
|
||||||
/* boot from flash */
|
/* boot from flash */
|
||||||
pikaMain = newRootObj("pikaMain", New_PikaMain);
|
pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||||
__pikaMain = pikaMain;
|
__pikaMain = pikaMain;
|
||||||
printf("[info]: boot from flash.\r\n");
|
|
||||||
if (code[0] == 'i') {
|
if (code[0] == 'i') {
|
||||||
obj_run(pikaMain, code);
|
printf("[info]: compiling the python script...\r\n");
|
||||||
goto main_loop;
|
main_codeBuff = arg_setStr(NULL, "", code);
|
||||||
}
|
// obj_run(pikaMain, arg_getStr(main_codeBuff));
|
||||||
// if (code[0] == 'B') {
|
Parser_multiLineToFile("", arg_getStr(main_codeBuff));
|
||||||
// printf("[info]: asm size: %d\r\n", strGetSize(code));
|
NVIC_SystemReset();
|
||||||
// printf("[info]: boot from Pika Asm.\r\n");
|
}else{
|
||||||
// pikaVM_runAsm(pikaMain, code);
|
/* found byte code */
|
||||||
// goto main_loop;
|
pikaVM_runByteCode(pikaMain, (uint8_t*) code);
|
||||||
// }
|
goto main_loop;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* boot from firmware */
|
/* boot from firmware */
|
||||||
printf("[info]: boot from firmware.\r\n");
|
printf("[info]: boot from firmware.\r\n");
|
||||||
|
@ -67,14 +67,6 @@ void HARDWARE_PRINTF_Init(void) {
|
|||||||
LL_USART_EnableIT_RXNE(USART1);
|
LL_USART_EnableIT_RXNE(USART1);
|
||||||
LL_USART_EnableIT_PE(USART1);
|
LL_USART_EnableIT_PE(USART1);
|
||||||
}
|
}
|
||||||
//#pragma import(__use_no_semihosting)
|
|
||||||
//void _sys_exit(int x) {
|
|
||||||
// x = x;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//struct __FILE{
|
|
||||||
// int handle;
|
|
||||||
//};
|
|
||||||
|
|
||||||
//FILE __stdout;
|
//FILE __stdout;
|
||||||
int fputc(int ch, FILE* f) {
|
int fputc(int ch, FILE* f) {
|
||||||
@ -105,7 +97,6 @@ void delay_us(uint32_t udelay) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* support pika Asm to flash */
|
/* support pika Asm to flash */
|
||||||
uint32_t globalWriteAddress = 0;
|
uint32_t globalWriteAddress = 0;
|
||||||
uint32_t GetPage(uint32_t Addr) {
|
uint32_t GetPage(uint32_t Addr) {
|
||||||
@ -164,39 +155,28 @@ uint32_t flash_write_char(uint32_t bassAddr,
|
|||||||
return flash_addr;
|
return flash_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//uint8_t __platform_Asm_is_to_flash(char* pyMultiLine) {
|
int32_t __writeToFlash(char* ptr,
|
||||||
//// if (strCountSign(pyMultiLine, '\n') > 10) {
|
uint32_t flashStart,
|
||||||
//// return 1;
|
uint32_t flashEnd,
|
||||||
//// }
|
uint32_t *writeAddress_p,
|
||||||
// return 0;
|
uint32_t size){
|
||||||
//}
|
for (int i = 0; i < size; i++) {
|
||||||
|
(*writeAddress_p) =
|
||||||
|
flash_write_char(flashStart, (*writeAddress_p), ptr[i]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t __saveStrToFlash(char* str,
|
int32_t __saveStrToFlash(char* str,
|
||||||
uint32_t flashStart,
|
uint32_t flashStart,
|
||||||
uint32_t flashEnd,
|
uint32_t flashEnd,
|
||||||
uint32_t* writeAddress_p) {
|
uint32_t* writeAddress_p) {
|
||||||
uint32_t size = strGetSize(str);
|
uint32_t size = strGetSize(str);
|
||||||
for (int i = 0; i < size; i++) {
|
return __writeToFlash(str, flashStart, flashEnd, writeAddress_p, size);
|
||||||
(*writeAddress_p) =
|
|
||||||
flash_write_char(flashStart, (*writeAddress_p), str[i]);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//char* __platform_load_pikaAsm() {
|
int32_t __writeEOFToFlash() {
|
||||||
// return (char*)FLASH_PIKA_ASM_START_ADDR;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//int32_t __platform_save_pikaAsm(char* PikaAsm) {
|
|
||||||
// if (0 == globalWriteAddress) {
|
|
||||||
// __eriseSelecttedFlash(FLASH_PIKA_ASM_START_ADDR,
|
|
||||||
// FLASH_PIKA_ASM_END_ADDR);
|
|
||||||
// }
|
|
||||||
// return __saveStrToFlash(PikaAsm, FLASH_PIKA_ASM_START_ADDR,
|
|
||||||
// FLASH_PIKA_ASM_END_ADDR, &globalWriteAddress);
|
|
||||||
//}
|
|
||||||
|
|
||||||
int32_t __save_pikaAsm_EOF() {
|
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
globalWriteAddress = flash_write_char(FLASH_PIKA_ASM_START_ADDR,
|
globalWriteAddress = flash_write_char(FLASH_PIKA_ASM_START_ADDR,
|
||||||
globalWriteAddress, '\0');
|
globalWriteAddress, '\0');
|
||||||
@ -231,7 +211,7 @@ void STM32_Code_Init(void) {
|
|||||||
codeHeap.wait = 0;
|
codeHeap.wait = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __erise_all(void){
|
void __eriseUserFlash(void){
|
||||||
printf("[info]: erising flash... \r\n");
|
printf("[info]: erising flash... \r\n");
|
||||||
/* init erise state */
|
/* init erise state */
|
||||||
globalWriteAddress = 0;
|
globalWriteAddress = 0;
|
||||||
@ -325,7 +305,7 @@ void STM32_Code_flashHandler(void) {
|
|||||||
/* transmite is finished */
|
/* transmite is finished */
|
||||||
printf("[info]: recieved size: %d\r\n", codeHeap.size);
|
printf("[info]: recieved size: %d\r\n", codeHeap.size);
|
||||||
/* write to flash from buff (heap.content) */
|
/* write to flash from buff (heap.content) */
|
||||||
__erise_all();
|
__eriseUserFlash();
|
||||||
printf("[info]: Writing flash... \r\n");
|
printf("[info]: Writing flash... \r\n");
|
||||||
/* init write state */
|
/* init write state */
|
||||||
__platform_memset(flash_writeBuff, 0, sizeof(flash_writeBuff));
|
__platform_memset(flash_writeBuff, 0, sizeof(flash_writeBuff));
|
||||||
@ -336,7 +316,7 @@ void STM32_Code_flashHandler(void) {
|
|||||||
/* write EOF */
|
/* write EOF */
|
||||||
__saveStrToFlash("\n\n", FLASH_PIKA_ASM_START_ADDR,
|
__saveStrToFlash("\n\n", FLASH_PIKA_ASM_START_ADDR,
|
||||||
FLASH_PIKA_ASM_END_ADDR, &globalWriteAddress);
|
FLASH_PIKA_ASM_END_ADDR, &globalWriteAddress);
|
||||||
__save_pikaAsm_EOF();
|
__writeEOFToFlash();
|
||||||
HAL_FLASH_Lock();
|
HAL_FLASH_Lock();
|
||||||
|
|
||||||
printf("[ OK ]: Write flash ok! \r\n");
|
printf("[ OK ]: Write flash ok! \r\n");
|
||||||
@ -368,3 +348,23 @@ void __platform_wait(void){
|
|||||||
pika_memory_lock ++;
|
pika_memory_lock ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* file API */
|
||||||
|
FILE* __platform_fopen(const char* filename, const char* modes){
|
||||||
|
__eriseUserFlash();
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
|
int __platform_fclose(FILE* stream){
|
||||||
|
__writeEOFToFlash();
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
size_t __platform_fwrite(const void* ptr, size_t size, size_t n, FILE* stream){
|
||||||
|
__writeToFlash( (char *)ptr,
|
||||||
|
FLASH_PIKA_ASM_START_ADDR,
|
||||||
|
FLASH_PIKA_ASM_END_ADDR,
|
||||||
|
&globalWriteAddress,
|
||||||
|
size * n);
|
||||||
|
return size * n;
|
||||||
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user