master
ThinkPad-T460P 2021-03-12 13:38:28 +08:00
parent eb930609aa
commit fcda752b65
14 changed files with 70 additions and 48 deletions

View File

@ -15,7 +15,7 @@
const osThreadAttr_t ButtonDetectTask_attributes = {
.name = "ButtonDetectTask",
.priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128 * 4
.stack_size = 128 * 8
};
//Timer
@ -45,7 +45,7 @@ void StartButtonDetectTask(void *argument)
{
/* USER CODE BEGIN StartButtonDetect */
/* Infinite loop */
log_v("Start Button Detect Task");
log_d("Start Button Detect Task");
for(;;)
{
//power button

View File

@ -15,8 +15,8 @@ extern uint32_t number_restart;
//task attributes
const osThreadAttr_t cdcMonitorTask_attributes = {
.name = "cdcMonitorTask",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 4
.priority = (osPriority_t) osPriorityBelowNormal7,
.stack_size = 128 * 8
};
//task instance
@ -24,7 +24,7 @@ void StartCdcMonitorTask(void *argument){
uint8_t port_restart_temp[64]={0};
uint32_t number_restart_temp =0;
bool beep_flag = false;
log_v("Start CDC Monitor Task");
log_d("Start CDC Monitor Task");
for(;;){
if(number_restart){
number_restart_temp = number_restart;

View File

@ -30,7 +30,7 @@ const osThreadAttr_t CoulombRead_attributes = {
void StartCoulombRead(void *argument)
{
/* USER CODE BEGIN StartCoulombRead */
log_v("Start Coulomb Read Task");
log_d("Start Coulomb Read Task");
//写寄存器方法
coulomb_write_config_load();
coulomb_write_config_actual_to_raw();

View File

@ -23,17 +23,17 @@ const osThreadAttr_t DemoTask2_attributes = {
};
void StartDemoTask1(void *argument){
uint8_t i=0;
log_v("Start Demo Task1");
log_d("Start Demo Task1");
for(;;){
log_v("demo task 1 [%d].",i++);
log_v("DemoTask1 counter [%d].",i++);
osDelay(100);
}
}
void StartDemoTask2(void *argument){
uint8_t i=0;
log_v("Start Demo Task2");
log_d("Start Demo Task2");
for(;;){
log_v("demo task 2 [%d].",i++);
osDelay(100);
log_v("DemoTask2 counter [%d].",i++);
}
}

View File

@ -40,7 +40,7 @@ void StartElogInitTask(void *argument){
void StartElogFlushTask(void *argument){
uint8_t i=0;
log_v("Start Elog Flush Task");
log_d("Start Elog Flush Task");
for(;;){
elog_flush();
osDelay(1);

View File

@ -15,13 +15,14 @@
const osThreadAttr_t IWDGTask_attributes = {
.name = "IWDGTask",
.priority = (osPriority_t) osPriorityHigh,
.stack_size = 128 * 4
.stack_size = 128 * 8
};
void StartIWDGTask(void *argument){
log_v("Start IWDG Task");
log_d("Start IWDG Task");
for(;;){
HAL_IWDG_Refresh(&hiwdg);
log_v("IWDG Counter Refreshed");
osDelay(1000);
}
}

View File

@ -13,7 +13,7 @@
const osThreadAttr_t LedBlinkTask_attributes = {
.name = "LedBlinkTask",
.priority = (osPriority_t) osPriorityBelowNormal,
.priority = (osPriority_t) osPriorityLow7,
.stack_size = 128 * 8
};
@ -28,7 +28,7 @@ void StartLedBlinkTask(void *argument)
{
/* USER CODE BEGIN StartLedBlinkTask */
/* Infinite loop */
log_v("Start LED Blink Task");
log_d("Start LED Blink Task");
for(;;)
{

View File

@ -15,7 +15,7 @@
const osThreadAttr_t PowerMonitTask_attributes = {
.name = "PowerMonitTask",
.priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128 * 4
.stack_size = 128 * 8
};
@ -29,7 +29,7 @@ const osThreadAttr_t PowerMonitTask_attributes = {
void StartPowerMonitTask(void *argument)
{
/* USER CODE BEGIN StartPowerMonitTask */
log_v("Start Power Monitor Task");
log_d("Start Power Monitor Task");
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT);
osDelay(100);

View File

@ -188,8 +188,13 @@ void Error_Handler(void);
#define IIC1_SDA_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
//define application software version
#define APP_VERSION "v0.9.6"
// set iwdg enable or disable
//#define IWDG_ENABLE
#undef IWDG_ENABLE
/* USER CODE END Private defines */
#ifdef __cplusplus

View File

@ -124,13 +124,17 @@ typedef struct
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
enum Device_t{USB2_Port1=0x00,USB2_Port2,USB2_Port3,USB2_Port4,USB2_Port5,USB2_Port6, //USB2.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
SOC_USB2_HUB=0x10,SOC_USB3_HUB,SOC_USB3_HOST,SOC_USB3_GEC,SOC_GE_SW, //SOC on Board
SYS_FAN1=0x20,SYS_FAN2,SYS_FAN3, //Fan on Board
SYS_RUN_LED,SYS_PWR_LED, //LED on Board
SOM_PWR_EN,SOM_DFU,SOM_RESET,SOM_SLEEP, //SOM Control
PMB_PS_ON}; //Power Management Board
SOM_PWR_EN=0x30,SOM_DFU,SOM_RESET,SOM_SLEEP, //SOM Control
PMB_PS_ON=0x40}; //Power Management Board
void PWR_Enable(enum Device_t device,bool en,uint16_t delay);
bool PWR_Status(enum Device_t device);

View File

@ -206,7 +206,9 @@ void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
//IWDG--------------------------------------------
#ifdef IWDG_ENABLE
IWDGTaskHandle = osThreadNew(StartIWDGTask, NULL, &IWDGTask_attributes);
#endif
//Power--------------------------------------------
// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes);
@ -276,14 +278,14 @@ osVersion_t osVersion;
else{
NaviKit.sys.power_btn = true;
}
log_i("EC Reset source :Power Button WakeUP");
log_i("EC Reset source: [Power Button WakeUP]");
}else{
NaviKit.sys.next_sta = idle;
log_i("EC Reset source :RTC WakeUP");
log_i("EC Reset source: [RTC WakeUP]");
enter_standby_state();
}
}else{//judge reset source "power on"
log_i("EC Reset source :PowerON");
log_i("EC Reset source: [PowerON]");
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){
log_d("EC next state isp");
NaviKit.sys.next_sta = isp;
@ -309,8 +311,8 @@ osVersion_t osVersion;
log_i("OS Kernel Version : %u ", osVersion.kernel);
log_i("OS Kernel ID : %s ",id_buf);
}
log_i("OS Kernel Tick Frequence: %d ",osKernelGetTickFreq());
log_i("OS Kernel System Timer Frequence: %d ",osKernelGetSysTimerFreq());
log_i("OS Kernel Tick Frequency: %d Hz",osKernelGetTickFreq());
log_i("System Timer Frequency : %d Hz",osKernelGetSysTimerFreq());
log_i("Log Library Version : V%s",ELOG_SW_VERSION);
log_i("Core initial successfully");
@ -368,7 +370,8 @@ osVersion_t osVersion;
// }
if(!osTimerIsRunning(IdleStateHoldTimerHandle)){
// osTimerStart(IdleStateHoldTimerHandle,5000);
osTimerStart(IdleStateHoldTimerHandle,5000);
log_i("Idle state hold timer started.");
}
}
@ -382,7 +385,7 @@ osVersion_t osVersion;
void IdleStateHoldTimerCallback(void *argument){
if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){
log_v("Idle state duration more than 5000ms.");
log_i("Idle state duration more than 5000ms.");
NaviKit.sys.next_sta = standby;
}
}

View File

@ -97,7 +97,7 @@ int main(void)
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C1_Init();
MX_IWDG_Init();
// MX_IWDG_Init();
MX_UART4_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();
@ -107,16 +107,19 @@ int main(void)
MX_NVIC_Init();
/* USER CODE BEGIN 2 */
//print log before kernel start
// uint8_t log_head[]="Autolabor EC Booting...\r\n";
// HAL_UART_Transmit_DMA(&huart1, log_head, sizeof(log_head));
if( hiwdg.Instance->SR & IWDG_KEY_ENABLE){
uint8_t log_head[]="iwdg enable\r\n";
HAL_UART_Transmit_DMA(&huart1, log_head, sizeof(log_head));
}else{
uint8_t log_head[]="iwdg disable\r\n";
#ifdef IWDG_ENABLE
__HAL_DBGMCU_FREEZE_IWDG(); //stop iwdg counter while cpu pause by debug mode
#endif
#ifdef DEBUG
HAL_DBGMCU_EnableDBGSleepMode();
HAL_DBGMCU_EnableDBGStopMode();
HAL_DBGMCU_EnableDBGStandbyMode();
#endif
uint8_t log_head[]="Autolabor EC Booting...\r\n";
HAL_UART_Transmit_DMA(&huart1, log_head, sizeof(log_head));
}
/* USER CODE END 2 */
/* Init scheduler */

View File

@ -12,6 +12,7 @@
* Author: oarap
*/
#define LOG_TAG "NAVIKIT"
#include "navikit.h"
#include "cmsis_os2.h" // ::CMSIS:RTOS2
@ -254,6 +255,7 @@ void PWR_Enable(enum Device_t device,bool en,uint16_t delay){
case PMB_PS_ON: {HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port, PMB_PS_ON_Pin, en); }break;
default: {log_e("PWR_Enable device parameter is invalid."); }break;
}
log_v("Device 0x%X has been %s",device,en ? "enabled" : "disabled");
osDelay(delay);
}

View File

@ -27,12 +27,16 @@
* 电池管理部分
# Note
* 官方的HAL中USB库已知问题
在使用usb的时候
文件`stm32f1xx_hal_pcd.c`
函数`void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)`
代码段`HAL_PCD_SuspendCallback(hpcd); ` 务必屏蔽,否则导致枚举失败,提示获取设备描述符失败。
* FreeRTOS调试指南
* 莫名进入`HardFault`错误
* 一般是堆栈大小不足导致,可通过`Static Stack Analyzer`中的`Call graph`来分析每个任务所占用的栈大小(并且以大纲视图看出任务中占用栈较大的函数),从而修改每个任务的`stack_size`为合适大小
* 如`elog_output()`该函数占用栈大小为400字节如果有任务调用了该日志输出接口那么freertos的默认`128*4=512`字节显然非常容易溢出
# 维护指南
* 为提高可移植性、可维护性、可阅读性,开发(应用层)时尽量使用`CMSIS_OS2`的抽象接口特殊情况时再考虑使用RTOS的原生接口