From b71014583e104c0b70f6a8d161550717507ec6bb Mon Sep 17 00:00:00 2001 From: ThinkPad-T460P Date: Fri, 5 Feb 2021 18:22:21 +0800 Subject: [PATCH] support restart usb port device by cdc serial port --- .settings/language.settings.xml | 4 +- Core/Inc/navikit.h | 2 +- Core/Src/freertos.c | 29 +++++++++++- NaviKit_EC_stm32 Debug (1).launch | 72 ++++++++++++++++++++++++++++++ NaviKit_EC_stm32 Debug.launch | 73 +++++++++++++++++++++++++++++++ README.md | 4 +- USB_DEVICE/App/usbd_cdc_if.c | 9 +++- USB_DEVICE/App/usbd_cdc_if.h | 2 +- 8 files changed, 186 insertions(+), 9 deletions(-) create mode 100644 NaviKit_EC_stm32 Debug (1).launch create mode 100644 NaviKit_EC_stm32 Debug.launch diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 46e7806..02d7b51 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -6,7 +6,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/Core/Inc/navikit.h b/Core/Inc/navikit.h index 9aa57cb..5ac8a83 100644 --- a/Core/Inc/navikit.h +++ b/Core/Inc/navikit.h @@ -124,7 +124,7 @@ extern NaviKit_t NaviKit; //device on board enum Device_t{USB2_Port1,USB2_Port2,USB2_Port3,USB2_Port4,USB2_Port5,USB2_Port6, //USB2.0 Port - USB3_Port1,USB3_Port2,USB3_Port3,USB3_Port4,USB3_Port5,USB3_Port6, //USB3.0 Port + USB3_Port5,USB3_Port6,USB3_Port1,USB3_Port2,USB3_Port3,USB3_Port4, //USB3.0 Port SOC_USB2_HUB,SOC_USB3_HUB,SOC_USB3_HOST,SOC_USB3_GEC,SOC_GE_SW, //SOC on Board SYS_FAN1,SYS_FAN2,SYS_FAN3, //Fan on Board SYS_RUN_LED,SYS_PWR_LED, //LED on Board diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 873b69b..4263f2a 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -36,6 +36,7 @@ #include "adc.h" #include "i2c.h" #include "log.h" +#include "usbd_cdc_if.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -55,7 +56,8 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN Variables */ - +extern uint8_t port_restart; +extern bool flag_restart; //Timer osTimerId_t PwrBtnLongPressTimerHandle; const osTimerAttr_t PwrBtnLongPressTimer_attributes = { @@ -79,6 +81,14 @@ const osTimerAttr_t IdleStateHoldTimer_attributes = { }; //Thread + +osThreadId_t cdcMonitorTaskHandle; +const osThreadAttr_t cdcMonitorTask_attributes = { + .name = "cdcMonitorTask", + .priority = (osPriority_t) osPriorityNormal, + .stack_size = 128 * 4 +}; + osThreadId_t LogtoUartTaskHandle; const osThreadAttr_t LogtoUartTask_attributes = { .name = "LogtoUartTask", @@ -156,6 +166,7 @@ void IdleStateHoldTimerCallback(void *argument); //task void StartLogtoUartTask(void *argument); +void StartCdcMonitorTask(void *argument); void StartTestTask1(void *argument); void StartTestTask2(void *argument); @@ -296,6 +307,8 @@ void MX_FREERTOS_Init(void) { // TestTask1Handle = osThreadNew(StartTestTask1, NULL, &TestTask1_attributes); // TestTask2Handle = osThreadNew(StartTestTask2, NULL, &TestTask2_attributes); + cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); + /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ @@ -647,6 +660,19 @@ void StartEventDetect(void *argument) /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ +void StartCdcMonitorTask(void *argument){ + for(;;){ + if(flag_restart && port_restart<12){ + flag_restart = false; + uint8_t port_restart_temp = port_restart; + Log(info,sys,"Port%d restart",port_restart_temp); + PWR_Enable(port_restart_temp, false,400); + TaskBeep(50,1); + PWR_Enable(port_restart_temp, true,0); + } + osDelay(200); + } +} void StartLogtoUartTask(void *argument){ // HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,2); @@ -733,7 +759,6 @@ void IdleStateHoldTimerCallback(void *argument){ } } - /* USER CODE END Application */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/NaviKit_EC_stm32 Debug (1).launch b/NaviKit_EC_stm32 Debug (1).launch new file mode 100644 index 0000000..d66821e --- /dev/null +++ b/NaviKit_EC_stm32 Debug (1).launch @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NaviKit_EC_stm32 Debug.launch b/NaviKit_EC_stm32 Debug.launch new file mode 100644 index 0000000..d54b705 --- /dev/null +++ b/NaviKit_EC_stm32 Debug.launch @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index c8074c1..02ec096 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ * @Author: CK.Zh * @Date: 2020-02-20 11:39:38 * @LastEditors: CK.Zh - * @LastEditTime: 2021-01-07 15:23:09 + * @LastEditTime: 2021-02-05 18:22:00 --> # NaviKit_stm32 PM1导航套件中电源控制板源码,STM32F107VCT6,开发环境STM32CubeIDE @@ -14,7 +14,7 @@ ## 3.电源监控功能(多轨电源电压监控) # 串口通信协议 -* TODO +* 在jetson nano系统中,找到串口ACM,发送数值(0-11),即可通过硬件重启12个usb口对应的设备 `STM32作为CDC Device接入到USB2.0-HUB的Downsteam 7端口下` diff --git a/USB_DEVICE/App/usbd_cdc_if.c b/USB_DEVICE/App/usbd_cdc_if.c index 3a1a726..5cf4df0 100644 --- a/USB_DEVICE/App/usbd_cdc_if.c +++ b/USB_DEVICE/App/usbd_cdc_if.c @@ -23,7 +23,7 @@ #include "usbd_cdc_if.h" /* USER CODE BEGIN INCLUDE */ - +#include "log.h" /* USER CODE END INCLUDE */ /* Private typedef -----------------------------------------------------------*/ @@ -100,6 +100,8 @@ uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; /* USER CODE BEGIN PRIVATE_VARIABLES */ +extern uint8_t port_restart = 0; +extern bool flag_restart = false; /* USER CODE END PRIVATE_VARIABLES */ /** @@ -266,6 +268,11 @@ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) /* USER CODE BEGIN 6 */ USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); USBD_CDC_ReceivePacket(&hUsbDeviceFS); + + port_restart = Buf[0]; + flag_restart = true; + + Log(info,sys,"cdc receive %d",port_restart); return (USBD_OK); /* USER CODE END 6 */ } diff --git a/USB_DEVICE/App/usbd_cdc_if.h b/USB_DEVICE/App/usbd_cdc_if.h index c1d5225..5c4f05f 100644 --- a/USB_DEVICE/App/usbd_cdc_if.h +++ b/USB_DEVICE/App/usbd_cdc_if.h @@ -31,7 +31,7 @@ #include "usbd_cdc.h" /* USER CODE BEGIN INCLUDE */ - +#include "stdbool.h" /* USER CODE END INCLUDE */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY