diff --git a/package/STM32G030Booter/gpio.c b/package/STM32G030Booter/gpio.c index e68533ca8..9c6adb01e 100644 --- a/package/STM32G030Booter/gpio.c +++ b/package/STM32G030Booter/gpio.c @@ -42,8 +42,8 @@ void MX_GPIO_Init(void) { /* GPIO Ports Clock Enable */ - LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOF); - LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA); + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); } diff --git a/package/STM32G030Booter/main.c b/package/STM32G030Booter/main.c index ea080d5ec..2b4213a1f 100644 --- a/package/STM32G030Booter/main.c +++ b/package/STM32G030Booter/main.c @@ -22,10 +22,10 @@ #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "STM32_common.h" #include "pikaScript.h" #include "pikaVM.h" #include "stdbool.h" -#include "stm32g030_pika_msp.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -59,8 +59,9 @@ void SystemClock_Config(void); /* supply the main object */ PikaObj* pikaMain; -char Shell_Buff[RX_BUFF_LENGTH] = {0}; -uint8_t Shell_Ready = 0; +extern char pikaShell[RX_BUFF_LENGTH]; +extern uint8_t pikaShellRxOk; + /* USER CODE END 0 */ /** @@ -68,20 +69,40 @@ uint8_t Shell_Ready = 0; * @retval int */ int main(void) { - /* support bootLoader */ + /* USER CODE BEGIN 1 */ + /* USER CODE END 1 */ + + /* MCU + * Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the + * Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + /* USER CODE BEGIN 2 */ __disable_irq(); + /* set vector table*/ SCB->VTOR = FLASH_BASE | 0x2000; __enable_irq(); - - /* system init */ - HAL_Init(); - SystemClock_Config(); - MX_GPIO_Init(); + HARDWARE_PRINTF_Init(); + STM32_Code_Init(); printf("stm32 hardware init ok\r\n"); - /* boot pikaScript */ char* code = (char*)FLASH_SCRIPT_START_ADDR; uint16_t codeOffset = 0; if (code[0] != 0xFF) { @@ -96,8 +117,8 @@ int main(void) { } if (code[0] == 'B') { printf("==============[Pika ASM]==============\r\n"); - for (int i = 0; i < strGetSize(code); i++) { - if ('\n' == code[i]) { + for(int i = 0; i < strGetSize(code); i ++){ + if('\n' == code[i]){ fputc('\r', (FILE*)!NULL); } fputc(code[i], (FILE*)!NULL); @@ -114,14 +135,20 @@ int main(void) { goto main_loop; } - pikaMain = pikaScriptInit(); - goto main_loop; - -main_loop: + main_loop: while (1) { - if(Shell_Ready){ - Shell_Ready = 0; - obj_run(pikaMain, Shell_Buff); + 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) { + obj_deinit(runRes); + } + pikaShellRxOk = 0; } } } @@ -133,7 +160,6 @@ main_loop: void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; /** Configure the main internal regulator output voltage */ @@ -163,13 +189,6 @@ void SystemClock_Config(void) { if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } - /** Initializes the peripherals clocks - */ - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; - PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { - Error_Handler(); - } } /* USER CODE BEGIN 4 */ diff --git a/package/STM32G030Booter/main.h b/package/STM32G030Booter/main.h index 4cffbfdc0..22443aec4 100644 --- a/package/STM32G030Booter/main.h +++ b/package/STM32G030Booter/main.h @@ -1,22 +1,22 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : main.h - * @brief : Header for main.c file. - * This file contains the common defines of the application. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -28,23 +28,8 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include #include "stm32g0xx_hal.h" -#include "stm32g0xx_ll_bus.h" -#include "stm32g0xx_ll_cortex.h" -#include "stm32g0xx_ll_dma.h" -#include "stm32g0xx_ll_exti.h" -#include "stm32g0xx_ll_gpio.h" -#include "stm32g0xx_ll_pwr.h" -#include "stm32g0xx_ll_rcc.h" -#include "stm32g0xx_ll_system.h" -#include "stm32g0xx_ll_usart.h" -#include "stm32g0xx_ll_utils.h" -#if defined(USE_FULL_ASSERT) -#include "stm32_assert.h" -#endif /* USE_FULL_ASSERT */ - /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/package/STM32G030Booter/startup_stm32g030xx.s b/package/STM32G030Booter/startup_stm32g030xx.s index a51347df0..bdd34ee19 100644 --- a/package/STM32G030Booter/startup_stm32g030xx.s +++ b/package/STM32G030Booter/startup_stm32g030xx.s @@ -40,7 +40,7 @@ __initial_sp ; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> ; -Heap_Size EQU 0x1B00 +Heap_Size EQU 0x1700 AREA HEAP, NOINIT, READWRITE, ALIGN=3 __heap_base diff --git a/package/STM32G030Booter/stm32g0xx_it.c b/package/STM32G030Booter/stm32g0xx_it.c index 1fd427be5..740953658 100644 --- a/package/STM32G030Booter/stm32g0xx_it.c +++ b/package/STM32G030Booter/stm32g0xx_it.c @@ -1,55 +1,141 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g0xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ +/* USER CODE END Header */ + /* Includes ------------------------------------------------------------------*/ #include "stm32g0xx_it.h" #include "main.h" -#include "stm32g030_pika_msp.h" -char UART1_RxBuff[RX_BUFF_LENGTH] = {0}; -uint16_t UART1_RXBuff_offset = 0; -extern char Shell_Buff[RX_BUFF_LENGTH]; -extern uint8_t Shell_Ready; +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +#include "STM32_common.h" +/* USER CODE END Includes */ +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* External variables --------------------------------------------------------*/ + +/* USER CODE BEGIN EV */ + +/* USER CODE END EV */ + +/******************************************************************************/ +/* Cortex-M0+ Processor Interruption and Exception Handlers */ +/******************************************************************************/ +/** + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) { } + /* USER CODE END NonMaskableInt_IRQn 1 */ } +/** + * @brief This function handles Hard fault interrupt. + */ void HardFault_Handler(void) { + /* USER CODE BEGIN HardFault_IRQn 0 */ + printf("[error]: Hard fault. Please reset the device.\r\n"); + /* USER CODE END HardFault_IRQn 0 */ while (1) { + /* USER CODE BEGIN W1_HardFault_IRQn 0 */ + /* USER CODE END W1_HardFault_IRQn 0 */ } } -void SVC_Handler(void) {} +/** + * @brief This function handles System service call via SWI instruction. + */ +void SVC_Handler(void) { + /* USER CODE BEGIN SVC_IRQn 0 */ -void PendSV_Handler(void) {} + /* USER CODE END SVC_IRQn 0 */ + /* USER CODE BEGIN SVC_IRQn 1 */ + /* USER CODE END SVC_IRQn 1 */ +} + +/** + * @brief This function handles Pendable request for system service. + */ +void PendSV_Handler(void) { + /* USER CODE BEGIN PendSV_IRQn 0 */ + + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ + + /* USER CODE END PendSV_IRQn 1 */ +} + +/** + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { + /* USER CODE BEGIN SysTick_IRQn 0 */ + + /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ STM32_Code_flashHandler(); + /* USER CODE END SysTick_IRQn 1 */ } -void USART1_IRQHandler(void) { - if (LL_USART_IsActiveFlag_RXNE(USART1)) { - uint8_t inputChar = LL_USART_ReceiveData8(USART1); - /* clear buff when overflow */ - if (UART1_RXBuff_offset >= RX_BUFF_LENGTH) { - UART1_RXBuff_offset = 0; - memset(UART1_RxBuff, 0, sizeof(UART1_RxBuff)); - } - /* recive char */ - UART1_RxBuff[UART1_RXBuff_offset] = inputChar; - UART1_RXBuff_offset++; - if ('\n' == inputChar) { - /* handle python script download */ - if (STM32_Code_reciveHandler(UART1_RxBuff, UART1_RXBuff_offset)) { - goto line_exit; - } - /* handle python shell invoke */ - memcpy(Shell_Buff, UART1_RxBuff, sizeof(Shell_Buff)); - Shell_Ready = 1; - goto line_exit; - line_exit: - UART1_RXBuff_offset = 0; - memset(UART1_RxBuff, 0, sizeof(UART1_RxBuff)); - return; - } - } -} +/******************************************************************************/ +/* STM32G0xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32g0xx.s). */ +/******************************************************************************/ + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/