From abf6547e77ba79670db41bfafb9aa76c5292edae Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 6 Sep 2023 00:57:48 +0800 Subject: [PATCH] update --- Core/Inc/stm32f4xx_it.h | 1 + Core/Src/stm32f4xx_it.c | 15 +++++++++++++++ Core/Src/usart.c | 5 +++++ mainboard.ioc | 1 + usrc/main.cpp | 8 ++++++++ 5 files changed, 30 insertions(+) diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index 833ede9..8276532 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -54,6 +54,7 @@ void UsageFault_Handler(void); void DebugMon_Handler(void); void TIM1_UP_TIM10_IRQHandler(void); void TIM1_TRG_COM_TIM11_IRQHandler(void); +void USART1_IRQHandler(void); void TIM6_DAC_IRQHandler(void); void TIM7_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index 1ea9bf0..f945a4f 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -58,6 +58,7 @@ extern TIM_HandleTypeDef htim6; extern TIM_HandleTypeDef htim7; extern TIM_HandleTypeDef htim10; +extern UART_HandleTypeDef huart1; extern TIM_HandleTypeDef htim11; /* USER CODE BEGIN EV */ @@ -191,6 +192,20 @@ void TIM1_TRG_COM_TIM11_IRQHandler(void) } /** + * @brief This function handles USART1 global interrupt. + */ +void USART1_IRQHandler(void) +{ + /* USER CODE BEGIN USART1_IRQn 0 */ + + /* USER CODE END USART1_IRQn 0 */ + HAL_UART_IRQHandler(&huart1); + /* USER CODE BEGIN USART1_IRQn 1 */ + + /* USER CODE END USART1_IRQn 1 */ +} + +/** * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts. */ void TIM6_DAC_IRQHandler(void) diff --git a/Core/Src/usart.c b/Core/Src/usart.c index 255cb74..463780e 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -110,6 +110,9 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) GPIO_InitStruct.Alternate = GPIO_AF7_USART1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* USART1 interrupt Init */ + HAL_NVIC_SetPriority(USART1_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspInit 1 */ /* USER CODE END USART1_MspInit 1 */ @@ -157,6 +160,8 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); + /* USART1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE END USART1_MspDeInit 1 */ diff --git a/mainboard.ioc b/mainboard.ioc index 7221b8a..ba2d893 100644 --- a/mainboard.ioc +++ b/mainboard.ioc @@ -67,6 +67,7 @@ NVIC.TIM6_DAC_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.TIM7_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.TimeBase=TIM1_TRG_COM_TIM11_IRQn NVIC.TimeBaseIP=TIM11 +NVIC.USART1_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false PA10.Mode=Asynchronous PA10.Signal=USART1_RX diff --git a/usrc/main.cpp b/usrc/main.cpp index 7badf5f..3fd88fa 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -5,6 +5,7 @@ // #include "sdk/os/zos.hpp" +#include "sdk\components\cmdscheduler\cmd_scheduler.hpp" #include "sdk\components\step_motor_45\step_motor_45.hpp" #include "sdk\components\step_motor_45\step_motor_45_scheduler.hpp" @@ -131,7 +132,14 @@ void Main::run() { step_motor45_scheduler.start(); + CmdScheduler cmdScheduler; + cmdScheduler.initialize(&DEBUG_UART, 1000); + cmdScheduler.registerCmd("help", // + [this](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { ZLOGI(TAG, "do_help"); }); + while (true) { OSDefaultSchduler::getInstance()->loop(); + cmdScheduler.schedule(); + osDelay(1); } }