2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE BEGIN Header */
|
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* File Name : freertos.c
|
|
|
|
* Description : Code for freertos applications
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
|
|
|
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
|
|
|
* All rights reserved.</center></h2>
|
|
|
|
*
|
|
|
|
* This software component is licensed by ST under Ultimate Liberty license
|
|
|
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at:
|
|
|
|
* www.st.com/SLA0044
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
/* USER CODE END Header */
|
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN Includes */
|
2020-04-10 19:05:38 +08:00
|
|
|
#include "iwdg.h"
|
|
|
|
#include "gpio.h"
|
|
|
|
#include "usart.h"
|
|
|
|
#include "stdio.h"
|
2020-04-17 15:55:14 +08:00
|
|
|
#include "navikit.h"
|
2020-04-27 18:19:02 +08:00
|
|
|
#include "coulomb.h"
|
2020-04-17 15:55:14 +08:00
|
|
|
#include "stdbool.h"
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Includes */
|
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PTD */
|
|
|
|
|
|
|
|
/* USER CODE END PTD */
|
|
|
|
|
|
|
|
/* 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 Variables */
|
|
|
|
|
|
|
|
/* USER CODE END Variables */
|
2020-04-06 21:16:18 +08:00
|
|
|
/* Definitions for defaultTask */
|
|
|
|
osThreadId_t defaultTaskHandle;
|
|
|
|
const osThreadAttr_t defaultTask_attributes = {
|
|
|
|
.name = "defaultTask",
|
|
|
|
.priority = (osPriority_t) osPriorityNormal,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-04-14 17:27:52 +08:00
|
|
|
/* Definitions for LedBlinkTask */
|
|
|
|
osThreadId_t LedBlinkTaskHandle;
|
|
|
|
const osThreadAttr_t LedBlinkTask_attributes = {
|
|
|
|
.name = "LedBlinkTask",
|
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
2020-04-10 19:05:38 +08:00
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
|
|
|
/* Definitions for IWDGRefreshTask */
|
|
|
|
osThreadId_t IWDGRefreshTaskHandle;
|
|
|
|
const osThreadAttr_t IWDGRefreshTask_attributes = {
|
|
|
|
.name = "IWDGRefreshTask",
|
2020-04-14 17:27:52 +08:00
|
|
|
.priority = (osPriority_t) osPriorityHigh,
|
2020-04-10 19:05:38 +08:00
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-08-05 19:22:37 +08:00
|
|
|
/* Definitions for EventDetect */
|
|
|
|
osThreadId_t EventDetectHandle;
|
|
|
|
const osThreadAttr_t EventDetect_attributes = {
|
|
|
|
.name = "EventDetect",
|
2020-04-17 15:55:14 +08:00
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-04-27 18:19:02 +08:00
|
|
|
/* Definitions for CoulombRead */
|
|
|
|
osThreadId_t CoulombReadHandle;
|
|
|
|
const osThreadAttr_t CoulombRead_attributes = {
|
|
|
|
.name = "CoulombRead",
|
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-07-15 18:26:22 +08:00
|
|
|
/* Definitions for StateSwitchTask */
|
|
|
|
osThreadId_t StateSwitchTaskHandle;
|
|
|
|
const osThreadAttr_t StateSwitchTask_attributes = {
|
|
|
|
.name = "StateSwitchTask",
|
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
|
|
|
/* Definitions for SOMPowerManageTask */
|
|
|
|
osThreadId_t SOMPowerManageTaskHandle;
|
|
|
|
const osThreadAttr_t SOMPowerManageTask_attributes = {
|
|
|
|
.name = "SOMPowerManageTask",
|
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN FunctionPrototypes */
|
|
|
|
/* USER CODE END FunctionPrototypes */
|
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
void StartDefaultTask(void *argument);
|
|
|
|
void StartLedBlinkTask(void *argument);
|
|
|
|
void StartIWDGRefreshTask(void *argument);
|
2020-08-05 19:22:37 +08:00
|
|
|
void StartEventDetect(void *argument);
|
2020-04-27 18:19:02 +08:00
|
|
|
void StartCoulombRead(void *argument);
|
2020-07-15 18:26:22 +08:00
|
|
|
void StartStateSwitchTask(void *argument);
|
|
|
|
void StartSOMPowerManageTask(void *argument);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
extern void MX_USB_DEVICE_Init(void);
|
|
|
|
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief FreeRTOS initialization
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
void MX_FREERTOS_Init(void) {
|
|
|
|
/* USER CODE BEGIN Init */
|
|
|
|
|
|
|
|
/* USER CODE END Init */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_MUTEX */
|
|
|
|
/* add mutexes, ... */
|
|
|
|
/* USER CODE END RTOS_MUTEX */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
|
|
/* add semaphores, ... */
|
|
|
|
/* USER CODE END RTOS_SEMAPHORES */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_TIMERS */
|
|
|
|
/* start timers, add new ones, ... */
|
|
|
|
/* USER CODE END RTOS_TIMERS */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_QUEUES */
|
|
|
|
/* add queues, ... */
|
|
|
|
/* USER CODE END RTOS_QUEUES */
|
|
|
|
|
|
|
|
/* Create the thread(s) */
|
2020-04-06 21:16:18 +08:00
|
|
|
/* creation of defaultTask */
|
2020-04-14 17:27:52 +08:00
|
|
|
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
/* creation of LedBlinkTask */
|
|
|
|
LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
|
2020-04-10 19:05:38 +08:00
|
|
|
|
|
|
|
/* creation of IWDGRefreshTask */
|
2020-04-14 17:27:52 +08:00
|
|
|
IWDGRefreshTaskHandle = osThreadNew(StartIWDGRefreshTask, NULL, &IWDGRefreshTask_attributes);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
2020-08-05 19:22:37 +08:00
|
|
|
/* creation of EventDetect */
|
|
|
|
EventDetectHandle = osThreadNew(StartEventDetect, NULL, &EventDetect_attributes);
|
2020-04-17 15:55:14 +08:00
|
|
|
|
2020-04-27 18:19:02 +08:00
|
|
|
/* creation of CoulombRead */
|
|
|
|
CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
|
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
/* creation of StateSwitchTask */
|
|
|
|
StateSwitchTaskHandle = osThreadNew(StartStateSwitchTask, NULL, &StateSwitchTask_attributes);
|
|
|
|
|
|
|
|
/* creation of SOMPowerManageTask */
|
|
|
|
SOMPowerManageTaskHandle = osThreadNew(StartSOMPowerManageTask, NULL, &SOMPowerManageTask_attributes);
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE BEGIN RTOS_THREADS */
|
|
|
|
/* add threads, ... */
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END RTOS_THREADS */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
2020-04-02 22:18:11 +08:00
|
|
|
/**
|
|
|
|
* @brief Function implementing the defaultTask thread.
|
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END Header_StartDefaultTask */
|
|
|
|
void StartDefaultTask(void *argument)
|
2020-04-02 22:18:11 +08:00
|
|
|
{
|
|
|
|
/* init code for USB_DEVICE */
|
|
|
|
MX_USB_DEVICE_Init();
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN StartDefaultTask */
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port,USB2_FS_ENUM_CTL_Pin, GPIO_PIN_SET);
|
2020-08-21 17:44:46 +08:00
|
|
|
Beep(50);
|
2020-04-10 19:05:38 +08:00
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
2020-04-14 17:27:52 +08:00
|
|
|
osDelay(1000);
|
2020-04-14 18:48:32 +08:00
|
|
|
printf("[%f]\n",(float)(osKernelGetTickCount()/1000.0));
|
2020-04-10 19:05:38 +08:00
|
|
|
}
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END StartDefaultTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN Header_StartLedBlinkTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
/**
|
2020-04-14 17:27:52 +08:00
|
|
|
* @brief Function implementing the LedBlinkTask thread.
|
2020-04-10 19:05:38 +08:00
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END Header_StartLedBlinkTask */
|
|
|
|
void StartLedBlinkTask(void *argument)
|
2020-04-10 19:05:38 +08:00
|
|
|
{
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN StartLedBlinkTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
2020-08-21 17:44:46 +08:00
|
|
|
switch(NaviKit.sys.sta){
|
|
|
|
case runing:
|
2020-07-15 18:26:22 +08:00
|
|
|
{
|
|
|
|
if(HAL_GPIO_ReadPin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin))
|
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_RESET);//turn on power led
|
|
|
|
|
|
|
|
if(HAL_GPIO_ReadPin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin) == GPIO_PIN_SET)//sys run led is off
|
|
|
|
{
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);//turn on sys run led
|
|
|
|
osDelay(50);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);//turn off sys run led
|
|
|
|
osDelay(300);
|
|
|
|
}
|
2020-08-21 17:44:46 +08:00
|
|
|
}break;
|
|
|
|
case shutdown:
|
2020-07-15 18:26:22 +08:00
|
|
|
{
|
|
|
|
if(!HAL_GPIO_ReadPin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin))
|
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_SET);//turn off power led
|
|
|
|
|
|
|
|
if(HAL_GPIO_ReadPin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin) == GPIO_PIN_SET)//sys run led is off
|
|
|
|
{
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);//turn on sys run led
|
|
|
|
osDelay(20);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);//turn off sys run led
|
|
|
|
osDelay(2000);
|
|
|
|
}
|
2020-08-21 17:44:46 +08:00
|
|
|
}break;
|
|
|
|
case sleep:
|
2020-08-05 19:22:37 +08:00
|
|
|
{//sleep mode
|
2020-07-23 17:43:36 +08:00
|
|
|
for(uint16_t i=0;i<25;i++)
|
2020-07-15 18:26:22 +08:00
|
|
|
{//20 light level
|
2020-07-23 17:43:36 +08:00
|
|
|
for(uint16_t j=0;j<3;j++)
|
2020-07-15 18:26:22 +08:00
|
|
|
{//the time length of every light level
|
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_SET);
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);
|
|
|
|
osDelay(i);
|
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_RESET);
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);
|
2020-07-23 17:43:36 +08:00
|
|
|
osDelay(25-i);
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
|
|
|
}
|
2020-07-23 17:43:36 +08:00
|
|
|
for(uint16_t i=0;i<25;i++)
|
2020-07-15 18:26:22 +08:00
|
|
|
{
|
2020-07-23 17:43:36 +08:00
|
|
|
for(uint16_t j=0;j<3;j++)
|
2020-07-15 18:26:22 +08:00
|
|
|
{
|
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_SET);
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);
|
2020-07-23 17:43:36 +08:00
|
|
|
osDelay(25-i);
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_RESET);
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);
|
|
|
|
osDelay(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 17:44:46 +08:00
|
|
|
}break;
|
|
|
|
case dfu:
|
|
|
|
{
|
|
|
|
if(HAL_GPIO_ReadPin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin) == GPIO_PIN_SET)//power led is off
|
|
|
|
{
|
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_RESET);//turn on power led
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);//turn on run led
|
|
|
|
osDelay(300);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_SET);//turn off sys run led
|
|
|
|
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);//turn off run led
|
|
|
|
osDelay(300);
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
2020-08-21 17:44:46 +08:00
|
|
|
}
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END StartLedBlinkTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN Header_StartIWDGRefreshTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
/**
|
|
|
|
* @brief Function implementing the IWDGRefreshTask thread.
|
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END Header_StartIWDGRefreshTask */
|
|
|
|
void StartIWDGRefreshTask(void *argument)
|
2020-04-10 19:05:38 +08:00
|
|
|
{
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN StartIWDGRefreshTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
HAL_IWDG_Refresh(&hiwdg);
|
2020-04-17 15:55:14 +08:00
|
|
|
// printf("2\n");
|
2020-04-10 19:05:38 +08:00
|
|
|
osDelay(1000);
|
|
|
|
}
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END StartIWDGRefreshTask */
|
2020-04-02 22:18:11 +08:00
|
|
|
}
|
|
|
|
|
2020-08-05 19:22:37 +08:00
|
|
|
/* USER CODE BEGIN Header_StartEventDetect */
|
2020-04-17 15:55:14 +08:00
|
|
|
/**
|
2020-08-05 19:22:37 +08:00
|
|
|
* @brief Function implementing the EventDetect thread.
|
2020-04-17 15:55:14 +08:00
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
2020-08-05 19:22:37 +08:00
|
|
|
/* USER CODE END Header_StartEventDetect */
|
|
|
|
void StartEventDetect(void *argument)
|
2020-04-17 15:55:14 +08:00
|
|
|
{
|
2020-08-05 19:22:37 +08:00
|
|
|
/* USER CODE BEGIN StartEventDetect */
|
2020-08-25 14:03:16 +08:00
|
|
|
osDelay(100);
|
|
|
|
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port,SYS_CUSTOM_BTN_Pin) == GPIO_PIN_RESET)
|
|
|
|
{
|
|
|
|
printf("Custom button has been pushed. \n");
|
|
|
|
NaviKit.sys.next_sta = isp;
|
|
|
|
}
|
2020-04-17 15:55:14 +08:00
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
2020-08-05 19:22:37 +08:00
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
if(NaviKit.sys.power_btn == true)
|
|
|
|
{//power btn has been pushed
|
2020-07-15 18:42:01 +08:00
|
|
|
osDelay(1000);
|
2020-07-15 18:26:22 +08:00
|
|
|
if(NaviKit.sys.power_btn == true)
|
2020-07-15 18:42:01 +08:00
|
|
|
{//power btn has been pushed more than 1000 ms
|
2020-08-05 19:22:37 +08:00
|
|
|
// while(NaviKit.sys.power_btn == true);//wait to release button
|
2020-08-21 17:44:46 +08:00
|
|
|
switch(NaviKit.sys.sta){
|
|
|
|
case runing:{//system is runing now, user request to shutdown
|
|
|
|
NaviKit.sys.next_sta = shutdown;
|
|
|
|
}break;
|
|
|
|
case shutdown:{//system is shutdown now , user request to power on
|
|
|
|
NaviKit.sys.next_sta = runing;
|
|
|
|
}break;
|
|
|
|
case dfu:{
|
|
|
|
NaviKit.sys.next_sta = shutdown;
|
|
|
|
}break;
|
|
|
|
case sleep:{
|
|
|
|
NaviKit.sys.next_sta = runing;
|
|
|
|
}break;
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
|
|
|
}
|
2020-08-05 19:22:37 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//sleep mode is unused
|
|
|
|
// if(NaviKit.sys.sta == runing)
|
|
|
|
// NaviKit.sys.sta = sleep;
|
|
|
|
// else if(NaviKit.sys.sta == sleep)
|
|
|
|
// NaviKit.sys.sta = runing;
|
|
|
|
}
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
|
|
|
if(NaviKit.sys.custom_btn == true )
|
|
|
|
{//custom button has been pushed
|
2020-08-21 17:44:46 +08:00
|
|
|
osDelay(2000);
|
2020-07-15 18:26:22 +08:00
|
|
|
if(NaviKit.sys.custom_btn == true )
|
2020-07-15 18:42:01 +08:00
|
|
|
{//custom button has been pushed over 1000 ms
|
2020-08-21 17:44:46 +08:00
|
|
|
if((NaviKit.sys.power_btn == true) && (NaviKit.sys.sta == shutdown))//into dfu state
|
|
|
|
NaviKit.sys.next_sta = dfu;
|
|
|
|
else//TODO: force restart
|
2020-08-05 19:22:37 +08:00
|
|
|
NaviKit.sys.next_sta = shutdown;
|
2020-08-21 17:44:46 +08:00
|
|
|
// if(NaviKit.sys.sta == runing)
|
|
|
|
// NaviKit.sys.next_sta = shutdown;
|
|
|
|
// else if(NaviKit.sys.sta == shutdown)
|
|
|
|
// NaviKit.sys.next_sta = runing;
|
2020-04-27 16:58:16 +08:00
|
|
|
}
|
2020-04-17 15:55:14 +08:00
|
|
|
}
|
2020-04-27 16:58:16 +08:00
|
|
|
|
2020-08-05 19:22:37 +08:00
|
|
|
osDelay(10);
|
2020-04-17 15:55:14 +08:00
|
|
|
}
|
2020-08-05 19:22:37 +08:00
|
|
|
/* USER CODE END StartEventDetect */
|
2020-04-17 15:55:14 +08:00
|
|
|
}
|
|
|
|
|
2020-04-27 18:19:02 +08:00
|
|
|
/* USER CODE BEGIN Header_StartCoulombRead */
|
|
|
|
/**
|
|
|
|
* @brief Function implementing the CoulombRead thread.
|
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
/* USER CODE END Header_StartCoulombRead */
|
|
|
|
void StartCoulombRead(void *argument)
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN StartCoulombRead */
|
2020-04-29 18:30:35 +08:00
|
|
|
//写寄存器方法
|
|
|
|
coulomb_write_config_load();
|
2020-04-29 17:49:27 +08:00
|
|
|
coulomb_write_config_actual_to_raw();
|
|
|
|
coulomb_write_config();
|
2020-04-29 18:30:35 +08:00
|
|
|
//读寄存器方法
|
|
|
|
coulomb_read_status_and_config();
|
|
|
|
coulomb_read_status_raw_to_actual();
|
|
|
|
coulomb_read_config_raw_to_actual();
|
2020-04-29 17:49:27 +08:00
|
|
|
|
2020-04-27 18:19:02 +08:00
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
2020-04-29 17:49:27 +08:00
|
|
|
coulomb_read_status_and_config();
|
|
|
|
coulomb_read_status_raw_to_actual();
|
2020-07-15 18:26:22 +08:00
|
|
|
if(NaviKit.sys.sta)
|
2020-04-28 18:44:48 +08:00
|
|
|
osDelay(500);
|
|
|
|
else
|
|
|
|
osDelay(5000);
|
2020-04-27 18:19:02 +08:00
|
|
|
}
|
|
|
|
/* USER CODE END StartCoulombRead */
|
|
|
|
}
|
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
/* USER CODE BEGIN Header_StartStateSwitchTask */
|
|
|
|
/**
|
|
|
|
* @brief Function implementing the StateSwitchTask thread.
|
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
/* USER CODE END Header_StartStateSwitchTask */
|
|
|
|
void StartStateSwitchTask(void *argument)
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN StartStateSwitchTask */
|
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
2020-08-21 17:44:46 +08:00
|
|
|
osDelay(10);
|
2020-08-05 19:22:37 +08:00
|
|
|
if(NaviKit.sys.next_sta != NaviKit.sys.sta)
|
2020-07-15 18:26:22 +08:00
|
|
|
{
|
2020-08-05 19:22:37 +08:00
|
|
|
switch(NaviKit.sys.next_sta)
|
|
|
|
{
|
|
|
|
case shutdown:
|
|
|
|
{//only from runing state
|
2020-08-25 14:03:16 +08:00
|
|
|
if(NaviKit.sys.sta == runing)
|
|
|
|
enter_shutdown_state();
|
|
|
|
}break;
|
2020-08-05 19:22:37 +08:00
|
|
|
case runing:
|
|
|
|
{//from sleep and shutdown state
|
2020-08-25 14:03:16 +08:00
|
|
|
enter_runing_state();
|
|
|
|
}break;
|
2020-08-05 19:22:37 +08:00
|
|
|
case sleep:
|
|
|
|
{//only form runing state
|
2020-08-25 14:03:16 +08:00
|
|
|
if(NaviKit.sys.sta == runing)
|
|
|
|
enter_sleep_state();
|
2020-08-05 19:22:37 +08:00
|
|
|
|
2020-08-25 14:03:16 +08:00
|
|
|
}break;
|
2020-08-21 17:44:46 +08:00
|
|
|
case dfu:
|
|
|
|
{
|
|
|
|
enter_dfu_state();
|
|
|
|
}break;
|
2020-08-25 14:03:16 +08:00
|
|
|
case isp:
|
|
|
|
{
|
|
|
|
enter_isp_state();
|
|
|
|
}break;
|
2020-08-05 19:22:37 +08:00
|
|
|
}
|
|
|
|
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* USER CODE END StartStateSwitchTask */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* USER CODE BEGIN Header_StartSOMPowerManageTask */
|
|
|
|
/**
|
|
|
|
* @brief Function implementing the SOMPowerManageTask thread.
|
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
/* USER CODE END Header_StartSOMPowerManageTask */
|
|
|
|
void StartSOMPowerManageTask(void *argument)
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN StartSOMPowerManageTask */
|
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
osDelay(1);
|
2020-08-05 19:22:37 +08:00
|
|
|
|
|
|
|
// //module request to stop
|
|
|
|
// if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port,SOM_SHUTDOWN_REQ_Pin) == GPIO_PIN_SET)
|
|
|
|
// {
|
|
|
|
// //1.the last step of normal power off process
|
|
|
|
// //2.Thermal shutdown
|
|
|
|
// //3.vdd_in's wave more than 5% of 5.0V
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port,SOM_POWER_EN_Pin,GPIO_PIN_RESET);
|
|
|
|
// }
|
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
|
|
|
/* USER CODE END StartSOMPowerManageTask */
|
|
|
|
}
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* Private application code --------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN Application */
|
2020-07-15 18:42:01 +08:00
|
|
|
|
2020-08-25 14:03:16 +08:00
|
|
|
//write "bios update flag" to bkp register, and reset system
|
|
|
|
void enter_isp_state()
|
|
|
|
{
|
|
|
|
RTC_HandleTypeDef hrtc;
|
|
|
|
|
|
|
|
hrtc.Instance = RTC;
|
|
|
|
|
|
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
__HAL_RCC_BKP_CLK_ENABLE();
|
|
|
|
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_HSE_DIV128);
|
|
|
|
__HAL_RCC_RTC_ENABLE();
|
|
|
|
HAL_PWR_EnableBkUpAccess();
|
2020-07-15 18:42:01 +08:00
|
|
|
|
2020-08-25 14:03:16 +08:00
|
|
|
HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR1,0x32f2);
|
|
|
|
|
|
|
|
HAL_Delay(10);
|
|
|
|
if(HAL_RTCEx_BKUPRead(&hrtc,RTC_BKP_DR1) == 0x32f2)
|
|
|
|
{//write successful
|
|
|
|
Beep(100);
|
|
|
|
Beep(100);
|
|
|
|
Beep(100);
|
|
|
|
printf("Enter to BIOS update state.\n");
|
|
|
|
printf("System will reboot ,then run ISP automatic.\n");
|
|
|
|
HAL_NVIC_SystemReset();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
printf("Backup Register Writen error, can not enter BIOS update state \n");
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 18:26:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void enter_shutdown_state()
|
|
|
|
{
|
2020-07-23 17:43:36 +08:00
|
|
|
printf("Enter to shutdown state \n");
|
|
|
|
Beep(50);
|
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port ,SOM_POWER_EN_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
2020-08-21 17:44:46 +08:00
|
|
|
// HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port,SOC_GE_SW_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port,USB3_VBUS_CTL_4_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port,USB3_VBUS_CTL_3_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port,USB3_VBUS_CTL_2_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port,USB3_VBUS_CTL_1_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port,USB3_VBUS_CTL_6_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port,USB3_VBUS_CTL_5_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port,USB2_VBUS_CTL_6_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port,USB2_VBUS_CTL_5_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port,USB2_VBUS_CTL_4_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port,USB2_VBUS_CTL_3_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port,USB2_VBUS_CTL_2_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port,SYS_FAN_CTL_1_Pin,GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port,SYS_FAN_CTL_2_Pin,GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin,GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port ,PMB_PS_ON_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
}
|
|
|
|
void enter_sleep_state()
|
|
|
|
{
|
2020-07-23 17:43:36 +08:00
|
|
|
printf("Enter to sleep state \n");
|
|
|
|
Beep(50);
|
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
// HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
2020-08-21 17:44:46 +08:00
|
|
|
// HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port,SOC_GE_SW_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port,USB3_VBUS_CTL_4_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port,USB3_VBUS_CTL_3_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port,USB3_VBUS_CTL_2_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port,USB3_VBUS_CTL_1_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port,USB3_VBUS_CTL_6_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port,USB3_VBUS_CTL_5_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port,USB2_VBUS_CTL_6_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port,USB2_VBUS_CTL_5_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port,USB2_VBUS_CTL_4_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port,USB2_VBUS_CTL_3_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port,USB2_VBUS_CTL_2_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port,SYS_FAN_CTL_1_Pin,GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port,SYS_FAN_CTL_2_Pin,GPIO_PIN_RESET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin,GPIO_PIN_RESET); osDelay(100);
|
|
|
|
}
|
2020-08-21 17:44:46 +08:00
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
void enter_runing_state()
|
|
|
|
{
|
2020-07-23 17:43:36 +08:00
|
|
|
|
2020-08-05 19:22:37 +08:00
|
|
|
printf("Enter to runing state \n");
|
|
|
|
Beep(200);
|
2020-07-23 17:43:36 +08:00
|
|
|
|
2020-08-21 17:44:46 +08:00
|
|
|
HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port ,SOM_FORCE_RECOVERY_Pin, GPIO_PIN_SET); osDelay(100);
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port ,PMB_PS_ON_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port,SYS_FAN_CTL_1_Pin,GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port,SYS_FAN_CTL_2_Pin,GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin,GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
2020-08-21 17:44:46 +08:00
|
|
|
// HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
2020-07-15 18:26:22 +08:00
|
|
|
HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port,SOC_GE_SW_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port,USB2_VBUS_CTL_2_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port,USB2_VBUS_CTL_3_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port,USB2_VBUS_CTL_4_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port,USB2_VBUS_CTL_5_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port,USB2_VBUS_CTL_6_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port,USB3_VBUS_CTL_5_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port,USB3_VBUS_CTL_6_Pin, GPIO_PIN_SET); osDelay(100);
|
2020-08-21 17:44:46 +08:00
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port,USB3_VBUS_CTL_1_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port,USB3_VBUS_CTL_2_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port,USB3_VBUS_CTL_3_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port,USB3_VBUS_CTL_4_Pin, GPIO_PIN_SET); osDelay(100);
|
2020-07-15 18:26:22 +08:00
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port ,SOM_POWER_EN_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
}
|
2020-04-14 17:27:52 +08:00
|
|
|
|
2020-08-21 17:44:46 +08:00
|
|
|
void enter_dfu_state()
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("Enter to dfu state \n");
|
|
|
|
Beep(200);
|
|
|
|
Beep(200);
|
|
|
|
Beep(200);
|
|
|
|
Beep(200);
|
|
|
|
Beep(200);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port ,SOM_FORCE_RECOVERY_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port ,PMB_PS_ON_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port,SYS_FAN_CTL_1_Pin,GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port,SYS_FAN_CTL_2_Pin,GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin,GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port,SOC_GE_SW_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port,USB2_VBUS_CTL_2_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port,USB2_VBUS_CTL_3_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port,USB2_VBUS_CTL_4_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port,USB2_VBUS_CTL_5_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port,USB2_VBUS_CTL_6_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port,USB3_VBUS_CTL_5_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port,USB3_VBUS_CTL_6_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port,USB3_VBUS_CTL_1_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port,USB3_VBUS_CTL_2_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port,USB3_VBUS_CTL_3_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port,USB3_VBUS_CTL_4_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port ,SOM_POWER_EN_Pin, GPIO_PIN_SET); osDelay(1000);
|
|
|
|
//
|
|
|
|
// HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port ,SOM_FORCE_RECOVERY_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port ,SOM_SYS_RESET_Pin, GPIO_PIN_RESET); osDelay(100);
|
|
|
|
//
|
|
|
|
// osDelay(5000);
|
|
|
|
// HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port ,SOM_SYS_RESET_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
// HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port ,SOM_FORCE_RECOVERY_Pin, GPIO_PIN_SET); osDelay(100);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2020-04-14 17:27:52 +08:00
|
|
|
|
2020-07-15 18:42:01 +08:00
|
|
|
//printf redefine
|
2020-04-10 19:05:38 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
|
|
|
PUTCHAR_PROTOTYPE
|
|
|
|
{
|
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY_TX){}
|
|
|
|
HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,0xffff);
|
2020-04-10 19:05:38 +08:00
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
#endif
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Application */
|
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|