2021-11-12 09:21:18 +08:00
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "stm32g0xx_it.h"
|
|
|
|
#include "main.h"
|
2022-03-30 22:53:55 +08:00
|
|
|
#include "pika_bsp.h"
|
2021-11-12 09:24:00 +08:00
|
|
|
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;
|
2021-11-12 09:21:18 +08:00
|
|
|
|
|
|
|
void NMI_Handler(void) {
|
|
|
|
while (1) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HardFault_Handler(void) {
|
2022-02-17 00:52:19 +08:00
|
|
|
printf("[error]: hard fault, please reset the device.\r\n");
|
2021-11-12 09:21:18 +08:00
|
|
|
while (1) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-12 09:24:00 +08:00
|
|
|
void SVC_Handler(void) {}
|
2021-11-12 09:21:18 +08:00
|
|
|
|
2021-11-12 09:24:00 +08:00
|
|
|
void PendSV_Handler(void) {}
|
2021-11-12 09:21:18 +08:00
|
|
|
|
|
|
|
void SysTick_Handler(void) {
|
|
|
|
HAL_IncTick();
|
|
|
|
STM32_Code_flashHandler();
|
|
|
|
}
|
|
|
|
|
2021-12-28 09:07:46 +00:00
|
|
|
volatile static uint8_t rx_char = 0;
|
|
|
|
|
|
|
|
/* support pikaScript Shell */
|
|
|
|
char __platform_getchar(){
|
|
|
|
char res = 0;
|
|
|
|
while(rx_char == 0){
|
|
|
|
};
|
|
|
|
res = rx_char;
|
|
|
|
rx_char = 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-11-12 20:33:50 +08:00
|
|
|
__attribute__((weak)) void __PIKA_USART1_IRQHandler(char rx_char) {}
|
2021-11-12 16:45:31 +08:00
|
|
|
|
2021-11-12 09:24:00 +08:00
|
|
|
void USART1_IRQHandler(void) {
|
|
|
|
if (LL_USART_IsActiveFlag_RXNE(USART1)) {
|
2021-12-28 09:07:46 +00:00
|
|
|
rx_char = LL_USART_ReceiveData8(USART1);
|
2021-11-12 20:33:50 +08:00
|
|
|
__PIKA_USART1_IRQHandler(rx_char);
|
2021-11-12 09:24:00 +08:00
|
|
|
/* clear buff when overflow */
|
|
|
|
if (UART1_RXBuff_offset >= RX_BUFF_LENGTH) {
|
|
|
|
UART1_RXBuff_offset = 0;
|
|
|
|
memset(UART1_RxBuff, 0, sizeof(UART1_RxBuff));
|
|
|
|
}
|
|
|
|
/* recive char */
|
2021-11-12 20:33:50 +08:00
|
|
|
UART1_RxBuff[UART1_RXBuff_offset] = rx_char;
|
2021-11-12 09:24:00 +08:00
|
|
|
UART1_RXBuff_offset++;
|
2021-11-12 20:33:50 +08:00
|
|
|
if ('\n' == rx_char) {
|
2021-11-12 09:24:00 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|