From c1c0b6bfbfdb87d2ce5d459d8e11a2a5e9aba718 Mon Sep 17 00:00:00 2001 From: ThinkPad-T460P Date: Wed, 10 Mar 2021 12:03:49 +0800 Subject: [PATCH] update --- .vscode/settings.json | 3 +- App/Inc/th_button.h | 5 +- App/Inc/th_default.h | 24 ++++++ App/Inc/th_elog.h | 2 + App/Src/isp.c | 3 +- App/Src/th_button.c | 12 +-- App/Src/th_cdc.c | 1 + App/Src/th_default.c | 164 +++++++++++++++++++++++++++++++++++ App/Src/th_elog.c | 3 + Core/Inc/navikit.h | 4 +- Core/Src/freertos.c | 194 ++++-------------------------------------- Core/Src/navikit.c | 3 +- NaviKit_EC_stm32.ioc | 14 +-- README.md | 13 ++- 14 files changed, 239 insertions(+), 206 deletions(-) create mode 100644 App/Inc/th_default.h create mode 100644 App/Src/th_default.c diff --git a/.vscode/settings.json b/.vscode/settings.json index ba6487b..03d6ba1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "*.txt": "txt", "navikit.h": "c", "isp.h": "c", - "cdc.h": "c" + "cdc.h": "c", + "th_elog.h": "c" } } \ No newline at end of file diff --git a/App/Inc/th_button.h b/App/Inc/th_button.h index 3596128..55dce98 100644 --- a/App/Inc/th_button.h +++ b/App/Inc/th_button.h @@ -2,7 +2,7 @@ * @Description: * @Date: 2021-03-10 10:50:02 * @LastEditors: CK.Zh - * @LastEditTime: 2021-03-10 10:56:12 + * @LastEditTime: 2021-03-10 11:50:39 * @FilePath: \NaviKit_EC_stm32\App\Inc\th_button.h */ #ifndef __TH_BUTTON_H__ @@ -27,8 +27,6 @@ const osTimerAttr_t PwrBtnShortPressTimer_attributes; osTimerId_t CustBtnShortPressTimerHandle; const osTimerAttr_t CustBtnShortPressTimer_attributes; -osTimerId_t IdleStateHoldTimerHandle; -const osTimerAttr_t IdleStateHoldTimer_attributes; void StartButtonDetect(void *argument); @@ -38,4 +36,5 @@ void CustBtnLongPressTimerCallback(void *argument); void PwrBtnShortPressTimerCallback(void *argument); void CustBtnShortPressTimerCallback(void *argument); + #endif diff --git a/App/Inc/th_default.h b/App/Inc/th_default.h new file mode 100644 index 0000000..2ef275b --- /dev/null +++ b/App/Inc/th_default.h @@ -0,0 +1,24 @@ +/* + * @Description: + * @Date: 2021-03-10 11:44:17 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 11:46:08 + * @FilePath: \NaviKit_EC_stm32\App\Inc\th_default.h + */ +#ifndef __TH_DEFAULT_H__ +#define __TH_DEFAULT_H__ + +#include "cmsis_os2.h" + +/* Definitions for defaultTask */ +osThreadId_t defaultTaskHandle; +const osThreadAttr_t defaultTask_attributes; +void StartDefaultTask(void *argument); + + + +osTimerId_t IdleStateHoldTimerHandle; +const osTimerAttr_t IdleStateHoldTimer_attributes; +void IdleStateHoldTimerCallback(void *argument); + +#endif diff --git a/App/Inc/th_elog.h b/App/Inc/th_elog.h index b6f5a1b..737f13d 100644 --- a/App/Inc/th_elog.h +++ b/App/Inc/th_elog.h @@ -3,6 +3,8 @@ #include "cmsis_os2.h" +const osMutexAttr_t ElogOutputMutex_attributes; + osThreadId_t ElogInitTaskHandle; osThreadId_t ElogFlushTaskHandle; diff --git a/App/Src/isp.c b/App/Src/isp.c index f47eec7..bdb7b36 100644 --- a/App/Src/isp.c +++ b/App/Src/isp.c @@ -2,7 +2,7 @@ * @Description: * @Date: 2021-03-09 10:21:58 * @LastEditors: CK.Zh - * @LastEditTime: 2021-03-09 17:42:16 + * @LastEditTime: 2021-03-10 11:15:23 * @FilePath: \NaviKit_EC_stm32\App\Src\isp.c */ #include @@ -62,6 +62,7 @@ bool ISP_Prepare(){ log_v("Enter to EC update state."); log_i("EC will reboot ,then run ISP automatic."); HAL_NVIC_SystemReset(); + return true; } else{ log_e("Backup register writen error, can not enter EC update state."); diff --git a/App/Src/th_button.c b/App/Src/th_button.c index e6274f8..bbcea02 100644 --- a/App/Src/th_button.c +++ b/App/Src/th_button.c @@ -2,7 +2,7 @@ * @Description: * @Date: 2021-03-10 10:49:52 * @LastEditors: CK.Zh - * @LastEditTime: 2021-03-10 10:56:58 + * @LastEditTime: 2021-03-10 11:57:47 * @FilePath: \NaviKit_EC_stm32\App\Src\th_button.c */ #define LOG_TAG "TH-Button" @@ -31,9 +31,7 @@ const osTimerAttr_t PwrBtnShortPressTimer_attributes = { const osTimerAttr_t CustBtnShortPressTimer_attributes = { .name = "CustBtnShortPressTimer" }; -const osTimerAttr_t IdleStateHoldTimer_attributes = { - .name = "IdleStateHoldTimer" -}; + /* USER CODE BEGIN Header_StartButtonDetect */ @@ -141,9 +139,3 @@ void CustBtnShortPressTimerCallback(void *argument) default : break; } } -void IdleStateHoldTimerCallback(void *argument){ - if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){ - log_v("Idle state duration more than 5000ms."); - NaviKit.sys.next_sta = standby; - } -} diff --git a/App/Src/th_cdc.c b/App/Src/th_cdc.c index 2d96d80..5c45cf7 100644 --- a/App/Src/th_cdc.c +++ b/App/Src/th_cdc.c @@ -24,6 +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"); for(;;){ if(number_restart){ number_restart_temp = number_restart; diff --git a/App/Src/th_default.c b/App/Src/th_default.c new file mode 100644 index 0000000..de2fc39 --- /dev/null +++ b/App/Src/th_default.c @@ -0,0 +1,164 @@ +/* + * @Description: + * @Date: 2021-03-10 11:43:58 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 11:46:56 + * @FilePath: \NaviKit_EC_stm32\App\Src\th_default.c + */ +#define LOG_TAG "TH-Default" + +#include + +#include "main.h" +#include "navikit.h" + + +extern void MX_USB_DEVICE_Init(void); + +const osThreadAttr_t defaultTask_attributes = { + .name = "defaultTask", + .priority = (osPriority_t) osPriorityNormal, + .stack_size = 128 * 4 +}; + +const osTimerAttr_t IdleStateHoldTimer_attributes = { + .name = "IdleStateHoldTimer" +}; + +bool isWakeUpFromReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);} + +/* USER CODE BEGIN Header_StartDefaultTask */ +/** + * @brief Function implementing the defaultTask thread. + * @param argument: Not used + * @retval None + */ +/* USER CODE END Header_StartDefaultTask */ +void StartDefaultTask(void *argument) +{ + /* init code for USB_DEVICE */ + MX_USB_DEVICE_Init(); + /* USER CODE BEGIN StartDefaultTask */ + osVersion_t osVersion; + char id_buf[20]; + unsigned char id_size=20; + + HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port,USB2_FS_ENUM_CTL_Pin, GPIO_PIN_SET); + if(isWakeUpFromReset()){//judge reset source form "wakeup event" + + __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); + __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); + + if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){ + if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET) + NaviKit.sys.next_sta = dfu; + else{ + NaviKit.sys.power_btn = true; + } + log_i("EC Reset source :Power Button WakeUP"); + }else{ + NaviKit.sys.next_sta = idle; + log_i("EC Reset source :RTC WakeUP"); + enter_standby_state(); + } + }else{//judge reset source "power on" + 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; + }else{ + NaviKit.sys.next_sta = idle; + } +// TaskBeep(50,1); + } + + log_i("----------------------------------------------"); + log_i("Copyright (c) Powered by www.autolabor.com.cn"); + #ifdef DEBUG + log_i("EC Firmware: %s[DEBUG], build: %s, %s",APP_VERSION,__DATE__ ,__TIME__); + #else + log_i("EC Firmware: %s[RELEASE], build: %s, %s",APP_VERSION,__DATE__ ,__TIME__); + #endif + log_i("HAL Version: 0x%X ", HAL_GetHalVersion()); + log_i("Revision ID: 0x%X ", HAL_GetREVID()); + log_i("Device ID: 0x%X ", HAL_GetDEVID()); + log_i("Chip UID: 0x%X%X%X ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2()); + + if(osOK == osKernelGetInfo(&osVersion,id_buf,id_size)){ + 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("Log Library Version: V%s",ELOG_SW_VERSION); + + log_i("Core initial successfully"); + log_i("----------------------------------------------"); + + /* Infinite loop */ + for(;;) + { +// HAL_IWDG_Refresh(&hiwdg); + osDelay(20); + if(NaviKit.sys.sta != NaviKit.sys.next_sta){ + switch(NaviKit.sys.next_sta){ + case standby: { + enter_standby_state(); + }break; + case idle: { + enter_idle_state(100); + NaviKit.sys.sta = NaviKit.sys.next_sta; + } break; + case run: { +// if(NaviKit.pmb.rails.main_pwr>19){ + enter_run_state(100); + NaviKit.sys.sta = NaviKit.sys.next_sta; +// }else{ +// NaviKit.sys.next_sta = NaviKit.sys.sta; +// TaskBeep(500,2); +// log_e(,"Main power not exist, retry after plug in it."); +// log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); +// } + }break; + case sleep:{ + enter_sleep_state(100); + NaviKit.sys.sta = NaviKit.sys.next_sta; + }break; + case dfu:{ +// if(NaviKit.pmb.rails.main_pwr>19){ + enter_dfu_state(100); + NaviKit.sys.sta = NaviKit.sys.next_sta; +// }else{ +// NaviKit.sys.next_sta = NaviKit.sys.sta; +// TaskBeep(500,2); +// log_e(,"Main power not exist, retry after plug in it."); +// log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); +// } + }break; + case isp:{ + enter_isp_state(); + NaviKit.sys.sta = NaviKit.sys.next_sta; + }break; + } + } + + if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){//idle state +// if((NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) +// || (NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)){//Not Charge or float charge +// NaviKit.sys.next_sta = standby; +// } + + if(!osTimerIsRunning(IdleStateHoldTimerHandle)){ + osTimerStart(IdleStateHoldTimerHandle,5000); + } + } + + } + /* USER CODE END StartDefaultTask */ +} +void IdleStateHoldTimerCallback(void *argument){ + if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){ + log_v("Idle state duration more than 5000ms."); + NaviKit.sys.next_sta = standby; + } +} diff --git a/App/Src/th_elog.c b/App/Src/th_elog.c index d6334fd..24e3b72 100644 --- a/App/Src/th_elog.c +++ b/App/Src/th_elog.c @@ -11,6 +11,9 @@ #include #include "main.h" +const osMutexAttr_t ElogOutputMutex_attributes = { + .name = "ElogOutputMutex" +}; const osThreadAttr_t ElogInitTask_attributes = { .name = "ElogInitTask", diff --git a/Core/Inc/navikit.h b/Core/Inc/navikit.h index 3a66ca8..65dd71c 100644 --- a/Core/Inc/navikit.h +++ b/Core/Inc/navikit.h @@ -12,8 +12,8 @@ * Author: oarap */ -#ifndef INC_NAVIKIT_H_ -#define INC_NAVIKIT_H_ +#ifndef _NAVIKIT_H_ +#define _NAVIKIT_H_ #include "main.h" #include "adc.h" diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 15a6c42..e9681f5 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -2,7 +2,7 @@ * @Description: * @Date: 2020-04-02 21:44:31 * @LastEditors: CK.Zh - * @LastEditTime: 2021-03-10 10:56:36 + * @LastEditTime: 2021-03-10 11:07:48 * @FilePath: \NaviKit_EC_stm32\Core\Src\freertos.c */ /* USER CODE BEGIN Header */ @@ -38,7 +38,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "timers.h" -#include "navikit.h" +#include #include #include #include @@ -69,46 +69,18 @@ /* USER CODE BEGIN Variables */ - -//Thread - - - - - -//Queue -//osMessageQueueId_t LogMessageQueueHandle; -//const osMessageQueueAttr_t LogMessageQueue_attributes = { -// .name = "LogMessageQueue" -//}; - /* USER CODE END Variables */ -/* Definitions for defaultTask */ -osThreadId_t defaultTaskHandle; -const osThreadAttr_t defaultTask_attributes = { - .name = "defaultTask", - .priority = (osPriority_t) osPriorityNormal, - .stack_size = 128 * 4 -}; - - /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ -bool isWakeUpReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);} - -void IdleStateHoldTimerCallback(void *argument); - /* USER CODE END FunctionPrototypes */ -void StartDefaultTask(void *argument); -extern void MX_USB_DEVICE_Init(void); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ /* Hook prototypes */ @@ -127,7 +99,7 @@ __weak void configureTimerForRunTimeStats(void) __weak unsigned long getRunTimeCounterValue(void) { -// return osKernelGetTickCount(); + return osKernelGetTickCount(); } /* USER CODE END 1 */ @@ -188,12 +160,14 @@ __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime) void MX_FREERTOS_Init(void) { /* USER CODE BEGIN Init */ + ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes); my_elog_init(); NaviKit_var_init(); /* USER CODE END Init */ /* USER CODE BEGIN RTOS_MUTEX */ /* add mutexes, ... */ + /* USER CODE END RTOS_MUTEX */ /* USER CODE BEGIN RTOS_SEMAPHORES */ @@ -202,11 +176,11 @@ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ -// PwrBtnLongPressTimerHandle = osTimerNew(PwrBtnLongPressTimerCallback, osTimerOnce, NULL, &PwrBtnLongPressTimer_attributes); -// CustBtnLongPressTimerHandle = osTimerNew(CustBtnLongPressTimerCallback, osTimerOnce, NULL, &CustBtnLongPressTimer_attributes); -// PwrBtnShortPressTimerHandle = osTimerNew(PwrBtnShortPressTimerCallback, osTimerOnce, NULL, &PwrBtnShortPressTimer_attributes); -// CustBtnShortPressTimerHandle = osTimerNew(CustBtnShortPressTimerCallback, osTimerOnce, NULL, &CustBtnShortPressTimer_attributes); -// IdleStateHoldTimerHandle = osTimerNew(IdleStateHoldTimerCallback, osTimerOnce, NULL, &IdleStateHoldTimer_attributes); + PwrBtnLongPressTimerHandle = osTimerNew(PwrBtnLongPressTimerCallback, osTimerOnce, NULL, &PwrBtnLongPressTimer_attributes); + CustBtnLongPressTimerHandle = osTimerNew(CustBtnLongPressTimerCallback, osTimerOnce, NULL, &CustBtnLongPressTimer_attributes); + PwrBtnShortPressTimerHandle = osTimerNew(PwrBtnShortPressTimerCallback, osTimerOnce, NULL, &PwrBtnShortPressTimer_attributes); + CustBtnShortPressTimerHandle = osTimerNew(CustBtnShortPressTimerCallback, osTimerOnce, NULL, &CustBtnShortPressTimer_attributes); + IdleStateHoldTimerHandle = osTimerNew(IdleStateHoldTimerCallback, osTimerOnce, NULL, &IdleStateHoldTimer_attributes); /* USER CODE END RTOS_TIMERS */ @@ -218,7 +192,6 @@ void MX_FREERTOS_Init(void) { /* Create the thread(s) */ /* creation of defaultTask */ - defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* creation of LedBlinkTask */ // LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes); @@ -235,20 +208,23 @@ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ + //Default Task + defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); + //Power-------------------------------------------- // PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes); //Button-------------------------------------------- - ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes); +// ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes); //LED-------------------------------------------- - LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes); +// LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes); //CDC-------------------------------------------- - cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); +// cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); //Coulomb-------------------------------------------- @@ -257,8 +233,9 @@ void MX_FREERTOS_Init(void) { //Elog-------------------------------------------- // ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes); +#ifdef ELOG_BUF_OUTPUT_ENABLE ElogFlushTaskHandle = osThreadNew(StartElogFlushTask, NULL, &ElogFlushTask_attributes); -// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes); +#endif //Demo-------------------------------------------- @@ -271,146 +248,11 @@ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ - PwrBtnLongPressTimerHandle = osTimerNew(PwrBtnLongPressTimerCallback, osTimerOnce, NULL, &PwrBtnLongPressTimer_attributes); - CustBtnLongPressTimerHandle = osTimerNew(CustBtnLongPressTimerCallback, osTimerOnce, NULL, &CustBtnLongPressTimer_attributes); - PwrBtnShortPressTimerHandle = osTimerNew(PwrBtnShortPressTimerCallback, osTimerOnce, NULL, &PwrBtnShortPressTimer_attributes); - CustBtnShortPressTimerHandle = osTimerNew(CustBtnShortPressTimerCallback, osTimerOnce, NULL, &CustBtnShortPressTimer_attributes); - IdleStateHoldTimerHandle = osTimerNew(IdleStateHoldTimerCallback, osTimerOnce, NULL, &IdleStateHoldTimer_attributes); - - /* USER CODE END RTOS_EVENTS */ } -/* USER CODE BEGIN Header_StartDefaultTask */ -/** - * @brief Function implementing the defaultTask thread. - * @param argument: Not used - * @retval None - */ -/* USER CODE END Header_StartDefaultTask */ -void StartDefaultTask(void *argument) -{ - /* init code for USB_DEVICE */ - MX_USB_DEVICE_Init(); - /* USER CODE BEGIN StartDefaultTask */ - osVersion_t osVersion; - char id_buf[20]; - unsigned char id_size=20; - HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port,USB2_FS_ENUM_CTL_Pin, GPIO_PIN_SET); - if(isWakeUpReset()){//judge reset source form "wakeup event" - - __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); - __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); - - if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){ - if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET) - NaviKit.sys.next_sta = dfu; - else{ - NaviKit.sys.power_btn = true; - } - log_i("EC Reset source :Power Button WakeUP"); - }else{ - NaviKit.sys.next_sta = idle; - log_i("EC Reset source :RTC WakeUP"); - enter_standby_state(); - } - }else{//judge reset source "power on" - 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; - }else{ - NaviKit.sys.next_sta = idle; - } -// TaskBeep(50,1); - } - - log_i("----------------------------------------------"); - log_i("Copyright (c) Powered by www.autolabor.com.cn"); - #ifdef DEBUG - log_i("EC Firmware: %s[DEBUG], build: %s, %s",APP_VERSION,__DATE__ ,__TIME__); - #else - log_i("EC Firmware: %s[RELEASE], build: %s, %s",APP_VERSION,__DATE__ ,__TIME__); - #endif - log_i("HAL Version: 0x%X ", HAL_GetHalVersion()); - log_i("Revision ID: 0x%X ", HAL_GetREVID()); - log_i("Device ID: 0x%X ", HAL_GetDEVID()); - log_i("Chip UID: 0x%X%X%X ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2()); - - if(osOK == osKernelGetInfo(&osVersion,id_buf,id_size)){ - 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("Log Library Version: V%s",ELOG_SW_VERSION); - - log_i("Core initial successfully"); - log_i("----------------------------------------------"); - - /* Infinite loop */ - for(;;) - { -// HAL_IWDG_Refresh(&hiwdg); - osDelay(20); - if(NaviKit.sys.sta != NaviKit.sys.next_sta){ - switch(NaviKit.sys.next_sta){ - case standby: { - enter_standby_state(); - }break; - case idle: { - enter_idle_state(100); - NaviKit.sys.sta = NaviKit.sys.next_sta; - } break; - case run: { -// if(NaviKit.pmb.rails.main_pwr>19){ - enter_run_state(100); - NaviKit.sys.sta = NaviKit.sys.next_sta; -// }else{ -// NaviKit.sys.next_sta = NaviKit.sys.sta; -// TaskBeep(500,2); -// log_e(,"Main power not exist, retry after plug in it."); -// log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); -// } - }break; - case sleep:{ - enter_sleep_state(100); - NaviKit.sys.sta = NaviKit.sys.next_sta; - }break; - case dfu:{ -// if(NaviKit.pmb.rails.main_pwr>19){ - enter_dfu_state(100); - NaviKit.sys.sta = NaviKit.sys.next_sta; -// }else{ -// NaviKit.sys.next_sta = NaviKit.sys.sta; -// TaskBeep(500,2); -// log_e(,"Main power not exist, retry after plug in it."); -// log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); -// } - }break; - case isp:{ - enter_isp_state(); - NaviKit.sys.sta = NaviKit.sys.next_sta; - }break; - } - } - - if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){//idle state -// if((NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) -// || (NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)){//Not Charge or float charge -// NaviKit.sys.next_sta = standby; -// } - - if(!osTimerIsRunning(IdleStateHoldTimerHandle)){ - osTimerStart(IdleStateHoldTimerHandle,5000); - } - } - - } - /* USER CODE END StartDefaultTask */ -} diff --git a/Core/Src/navikit.c b/Core/Src/navikit.c index 87f81ea..c3fe894 100644 --- a/Core/Src/navikit.c +++ b/Core/Src/navikit.c @@ -22,7 +22,6 @@ void NaviKit_var_init() { NaviKit.sys.sta = idle; NaviKit.sys.next_sta = idle; - } void TaskBeep(uint32_t time_ms , uint8_t n) @@ -102,7 +101,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) void enter_standby_state(){ - log_i("Enter to STANDBY Mode to save power, see you!"); + log_i("EC enter to STANDBY Mode to save power, see you!"); HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);//Enable PA0 wakeup function __HAL_RCC_RTC_DISABLE(); HAL_PWR_EnterSTANDBYMode(); diff --git a/NaviKit_EC_stm32.ioc b/NaviKit_EC_stm32.ioc index e19c529..91d1368 100644 --- a/NaviKit_EC_stm32.ioc +++ b/NaviKit_EC_stm32.ioc @@ -52,7 +52,7 @@ ARM.CMSIS.5.6.0.CMSISOoDriverJjWiFiJjCustom=true ARM.CMSIS.5.6.0.DeviceJjIRQOoControllerJjGIC=true ARM.CMSIS.5.6.0.DeviceJjOSOoTickJjPrivateOoTimer=true ARM.CMSIS.5.6.0.DeviceJjStartup=COoStartup -ARM.CMSIS.5.6.0.IPParameters=CMSISJjNNOoLib,DeviceJjIRQOoControllerJjGIC,DeviceJjOSOoTickJjPrivateOoTimer,CMSISOoDriverJjUSARTJjCustom,CMSISOoDriverJjSPIJjCustom,CMSISOoDriverJjSAIJjCustom,CMSISOoDriverJjI2CJjCustom,CMSISOoDriverJjCANJjCustom,CMSISOoDriverJjFlashJjCustom,CMSISOoDriverJjMCIJjCustom,CMSISOoDriverJjNANDJjCustom,CMSISOoDriverJjEthernetJjCustom,CMSISOoDriverJjEthernetOoMACJjCustom,CMSISOoDriverJjEthernetOoPHYJjCustom,CMSISOoDriverJjUSBOoDeviceJjCustom,CMSISOoDriverJjUSBOoHostJjCustom,CMSISOoDriverJjWiFiJjCustom,CMSISJjDSP,DeviceJjStartup +ARM.CMSIS.5.6.0.IPParameters=DeviceJjIRQOoControllerJjGIC,DeviceJjOSOoTickJjPrivateOoTimer,CMSISJjNNOoLib,CMSISOoDriverJjUSARTJjCustom,CMSISOoDriverJjSPIJjCustom,CMSISOoDriverJjSAIJjCustom,CMSISOoDriverJjI2CJjCustom,CMSISOoDriverJjCANJjCustom,CMSISOoDriverJjFlashJjCustom,CMSISOoDriverJjMCIJjCustom,CMSISOoDriverJjNANDJjCustom,CMSISOoDriverJjEthernetJjCustom,CMSISOoDriverJjEthernetOoMACJjCustom,CMSISOoDriverJjEthernetOoPHYJjCustom,CMSISOoDriverJjUSBOoDeviceJjCustom,CMSISOoDriverJjUSBOoHostJjCustom,CMSISOoDriverJjWiFiJjCustom,DeviceJjStartup,CMSISJjDSP ARM.CMSIS.5.6.0_SwParameter=CMSISOoDriverJjUSARTJjCustom\:true;DeviceJjOSOoTickJjPrivateOoTimer\:true;CMSISOoDriverJjUSBOoDeviceJjCustom\:true;CMSISOoDriverJjCANJjCustom\:true;CMSISOoDriverJjFlashJjCustom\:true;CMSISOoDriverJjNANDJjCustom\:true;CMSISOoDriverJjEthernetJjCustom\:true;CMSISOoDriverJjEthernetOoMACJjCustom\:true;CMSISOoDriverJjUSBOoHostJjCustom\:true;CMSISOoDriverJjSAIJjCustom\:true;CMSISOoDriverJjWiFiJjCustom\:true;CMSISJjDSP\:Library;CMSISOoDriverJjSPIJjCustom\:true;CMSISOoDriverJjMCIJjCustom\:true;CMSISOoDriverJjEthernetOoPHYJjCustom\:true;DeviceJjIRQOoControllerJjGIC\:true;CMSISJjNNOoLib\:true;DeviceJjStartup\:COoStartup;CMSISOoDriverJjI2CJjCustom\:true; Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY Dma.ADC1.0.Instance=DMA1_Channel1 @@ -75,7 +75,7 @@ FREERTOS.INCLUDE_xTaskAbortDelay=1 FREERTOS.INCLUDE_xTaskGetCurrentTaskHandle=1 FREERTOS.INCLUDE_xTaskGetHandle=1 FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configUSE_TICKLESS_IDLE,INCLUDE_xTaskGetCurrentTaskHandle,INCLUDE_xTaskGetHandle,configUSE_APPLICATION_TASK_TAG,FootprintOK,configUSE_IDLE_HOOK,configUSE_TICK_HOOK,configUSE_MALLOC_FAILED_HOOK,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS,configUSE_TRACE_FACILITY,HEAP_NUMBER,configTOTAL_HEAP_SIZE,configCHECK_FOR_STACK_OVERFLOW,configUSE_TASK_NOTIFICATIONS,INCLUDE_xTaskAbortDelay,INCLUDE_xEventGroupSetBitFromISR,INCLUDE_xSemaphoreGetMutexHolder,INCLUDE_pcTaskGetTaskName,INCLUDE_vTaskCleanUpResources -FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;LedBlinkTask,8,128,StartLedBlinkTask,Default,NULL,Dynamic,NULL,NULL;CoulombRead,8,128,StartCoulombRead,Default,NULL,Dynamic,NULL,NULL;PowerMonitTask,8,128,StartPowerMonitTask,Default,NULL,Dynamic,NULL,NULL;EventDetect,8,128,StartEventDetect,Default,NULL,Dynamic,NULL,NULL +FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL FREERTOS.configCHECK_FOR_STACK_OVERFLOW=1 FREERTOS.configGENERATE_RUN_TIME_STATS=1 FREERTOS.configMAX_TASK_NAME_LEN=32 @@ -188,8 +188,8 @@ Mcu.ThirdParty0=ARM.CMSIS.5.6.0 Mcu.ThirdPartyNb=1 Mcu.UserConstants= Mcu.UserName=STM32F107VCTx -MxCube.Version=6.1.0 -MxDb.Version=DB.6.0.10 +MxCube.Version=6.2.0 +MxDb.Version=DB.6.0.20 NVIC.ADC1_2_IRQn=true\:5\:0\:false\:true\:true\:8\:true\:true\:true NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.DMA1_Channel1_IRQn=true\:5\:0\:false\:true\:true\:9\:true\:false\:true @@ -558,8 +558,8 @@ ProjectManager.MainLocation=Core/Src ProjectManager.NoMain=false ProjectManager.PreviousToolchain= ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=NaviKit_stm32.ioc -ProjectManager.ProjectName=NaviKit_stm32 +ProjectManager.ProjectFileName=NaviKit_EC_stm32.ioc +ProjectManager.ProjectName=NaviKit_EC_stm32 ProjectManager.RegisterCallBack= ProjectManager.StackSize=0x800 ProjectManager.TargetToolchain=STM32CubeIDE @@ -652,4 +652,4 @@ VP_SYS_VS_tim1.Signal=SYS_VS_tim1 VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS board=custom -isbadioc=false +isbadioc=true diff --git a/README.md b/README.md index 02ec096..d198825 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-02-05 18:22:00 + * @LastEditTime: 2021-03-10 11:40:42 --> # NaviKit_stm32 PM1导航套件中电源控制板源码,STM32F107VCT6,开发环境STM32CubeIDE @@ -28,11 +28,16 @@ # Note 在使用usb的时候, - `stm32f1xx_hal_pcd.c`文件内 - `void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)`函数内 - `HAL_PCD_SuspendCallback(hpcd); `代码段 务必屏蔽,否则导致枚举失败,提示获取设备描述符失败。 + 文件`stm32f1xx_hal_pcd.c` + 函数`void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)` + 代码段`HAL_PCD_SuspendCallback(hpcd); ` 务必屏蔽,否则导致枚举失败,提示获取设备描述符失败。 > EC日志输出口波特率为56000bps +# 维护指南 +* 为提高可移植性、可维护性、可阅读性,开发(应用层)时尽量使用`CMSIS_OS2`的抽象接口,特殊情况时再考虑使用RTOS的原生接口 +* 线程任务实例及属性、句柄的声明及定义,独立存放在`App`文件夹 +* 线程、定时器、事件标志、互斥锁、信号量、消息队列等功能的初始化统一在`freertos.c`文件中进行初始化(内核启动前的预装载) +* `freertos.c`中的任务实体只保留默认任务即可 # 勘误 硬件的v1.0以前版本中,SYS_RESET脚和MOD_SLEEP到单片机的实际连接与网络标号是相反的(问题发生在TXB0108PWR芯片附近),故代码中在GPIO处进行了相反的设置。 \ No newline at end of file