master
ThinkPad-T460P 2021-03-10 11:03:35 +08:00
parent 292790c0e5
commit 28148e57b4
19 changed files with 699 additions and 454 deletions

View File

@ -3,7 +3,9 @@
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.502298629">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.502298629" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/>
<externalSettings>
<externalSetting/>
</externalSettings>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
@ -38,7 +40,7 @@
</tool>
<tool command="gcc" commandLinePattern="${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT}" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.770357739" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.883307296" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g3" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.1182522958" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.og" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.1182522958" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o0" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.1676188920" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
<listOptionValue builtIn="false" value="STM32F107xC"/>
@ -125,6 +127,7 @@
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1239010509" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.3 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.base.gnu-tools-for-stm32 || STM32F107VCTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Middlewares/Third_Party/FreeRTOS/Source/include | ../USB_DEVICE/Target | ..//CMSIS/Driver/Include | ../Middlewares/ST/STM32_USB_Device_Library/Core/Inc | ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 | ../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3 | ../Drivers/CMSIS/Device/ST/STM32F1xx/Include | ../Drivers/CMSIS/Include | ../Core/Inc | ../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc | ../USB_DEVICE/App | ../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy | ../Drivers/STM32F1xx_HAL_Driver/Inc | ../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc || || || USE_HAL_DRIVER | STM32F107xC || || Drivers | CMSIS | Core/Startup | Middlewares | Core | USB_DEVICE || || || ${workspace_loc:/${ProjName}/STM32F107VCTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || " valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.convertbinary.1121264663" name="Convert to binary file (-O binary)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.convertbinary" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.converthex.1737555266" name="Convert to Intel Hex file (-O ihex)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.converthex" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat.1638170040" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat" value="true" valueType="boolean"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.238068216" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
<builder buildPath="${workspace_loc:/NaviKit_stm32}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.95113451" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.1535045086" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
@ -133,28 +136,27 @@
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.632904416" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.1856652564" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g0" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.2079025018" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o3" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.2079025018" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o0" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.1412817126" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
<listOptionValue builtIn="false" value="STM32F107xC"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths.968919675" name="Include paths (-I)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FreeRTOS/Source/include"/>
<listOptionValue builtIn="false" value="../USB_DEVICE/Target"/>
<listOptionValue builtIn="false" value="..//CMSIS/Driver/Include"/>
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Core/Inc"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3"/>
<listOptionValue builtIn="false" value="../App/Inc"/>
<listOptionValue builtIn="false" value="../Core/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F1xx/Include"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../Core/Inc"/>
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc"/>
<listOptionValue builtIn="false" value="../USB_DEVICE/App"/>
<listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy"/>
<listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc"/>
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc"/>
<listOptionValue builtIn="false" value="../Middlewares/Log"/>
<listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy"/>
<listOptionValue builtIn="false" value="../Middlewares/Coulomb"/>
<listOptionValue builtIn="false" value="../Middlewares/EasyLogger/easylogger/inc"/>
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc"/>
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Core/Inc"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FreeRTOS/Source/include"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3"/>
<listOptionValue builtIn="false" value="../USB_DEVICE/App"/>
<listOptionValue builtIn="false" value="../USB_DEVICE/Target"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.77383630" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>
@ -183,10 +185,10 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="App"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="CMSIS"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry excluding="EasyLogger/easylogger/plugins" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="USB_DEVICE"/>
</sourceEntries>
</configuration>
@ -209,6 +211,9 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Multiple configurations">
<resource resourceType="PROJECT" workspacePath="/NaviKit_EC_stm32"/>
</configuration>
<configuration configurationName="Debug">
<resource resourceType="PROJECT" workspacePath="/NaviKit_stm32"/>
</configuration>

41
App/Inc/th_button.h Normal file
View File

@ -0,0 +1,41 @@
/*
* @Description:
* @Date: 2021-03-10 10:50:02
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-10 10:56:12
* @FilePath: \NaviKit_EC_stm32\App\Inc\th_button.h
*/
#ifndef __TH_BUTTON_H__
#define __TH_BUTTON_H__
#include "cmsis_os2.h"
/* Definitions for ButtonDetect */
osThreadId_t ButtonDetectHandle;
const osThreadAttr_t ButtonDetect_attributes;
//Timer
osTimerId_t PwrBtnLongPressTimerHandle;
const osTimerAttr_t PwrBtnLongPressTimer_attributes;
osTimerId_t CustBtnLongPressTimerHandle;
const osTimerAttr_t CustBtnLongPressTimer_attributes;
osTimerId_t PwrBtnShortPressTimerHandle;
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);
//callback
void PwrBtnLongPressTimerCallback(void *argument);
void CustBtnLongPressTimerCallback(void *argument);
void PwrBtnShortPressTimerCallback(void *argument);
void CustBtnShortPressTimerCallback(void *argument);
#endif

19
App/Inc/th_coulomb.h Normal file
View File

@ -0,0 +1,19 @@
/*
* @Description:
* @Date: 2021-03-10 10:36:01
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-10 10:39:06
* @FilePath: \NaviKit_EC_stm32\App\Inc\th_coulomb.h
*/
#ifndef __TH_COULOMB_H__
#define __TH_COULOMB_H__
#include "cmsis_os2.h"
osThreadId_t CoulombReadHandle;
const osThreadAttr_t CoulombRead_attributes;
void StartCoulombRead(void *argument);
#endif

View File

@ -2,9 +2,15 @@
#define __TH_ELOG_H__
#include "cmsis_os2.h"
osThreadId_t ElogInitTaskHandle;
osThreadId_t ElogFlushTaskHandle;
const osThreadAttr_t ElogInitTask_attributes;
const osThreadAttr_t ElogFlushTask_attributes;
void StartElogInitTask(void *argument);
void StartElogFlushTask(void *argument);
void my_elog_init();
#endif

19
App/Inc/th_led.h Normal file
View File

@ -0,0 +1,19 @@
/*
* @Description:
* @Date: 2021-03-10 10:11:23
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-10 10:12:24
* @FilePath: \NaviKit_EC_stm32\App\Inc\th_led.h
*/
#ifndef __TH_LED_H__
#define __TH_LED_H__
#include "cmsis_os2.h"
/* Definitions for LedBlinkTask */
osThreadId_t LedBlinkTaskHandle;
const osThreadAttr_t LedBlinkTask_attributes;
void StartLedBlinkTask(void *argument);
#endif

18
App/Inc/th_power.h Normal file
View File

@ -0,0 +1,18 @@
/*
* @Description:
* @Date: 2021-03-10 10:44:21
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-10 10:45:51
* @FilePath: \NaviKit_EC_stm32\App\Inc\th_power.h
*/
#ifndef __TH_POWER_H__
#define __TH_POWER_H__
#include "cmsis_os2.h"
/* Definitions for PowerMonitTask */
osThreadId_t PowerMonitTaskHandle;
const osThreadAttr_t PowerMonitTask_attributes;
void StartPowerMonitTask(void *argument);
#endif

149
App/Src/th_button.c Normal file
View File

@ -0,0 +1,149 @@
/*
* @Description:
* @Date: 2021-03-10 10:49:52
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-10 10:56:58
* @FilePath: \NaviKit_EC_stm32\App\Src\th_button.c
*/
#define LOG_TAG "TH-Button"
#include <th_button.h>
#include "main.h"
#include "navikit.h"
//Thread
const osThreadAttr_t ButtonDetect_attributes = {
.name = "ButtonDetect",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
//Timer
const osTimerAttr_t PwrBtnLongPressTimer_attributes = {
.name = "PwrBtnLongPressTimer"
};
const osTimerAttr_t CustBtnLongPressTimer_attributes = {
.name = "CustBtnLongPressTimer"
};
const osTimerAttr_t PwrBtnShortPressTimer_attributes = {
.name = "PwrBtnShortPressTimer"
};
const osTimerAttr_t CustBtnShortPressTimer_attributes = {
.name = "CustBtnShortPressTimer"
};
const osTimerAttr_t IdleStateHoldTimer_attributes = {
.name = "IdleStateHoldTimer"
};
/* USER CODE BEGIN Header_StartButtonDetect */
/**
* @brief Function implementing the ButtonDetect thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartButtonDetect */
void StartButtonDetect(void *argument)
{
/* USER CODE BEGIN StartButtonDetect */
/* Infinite loop */
log_v("Start Button Detect Task");
for(;;)
{
//power button
if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){
osTimerStart(PwrBtnLongPressTimerHandle,1500);
osTimerStart(PwrBtnShortPressTimerHandle,100);
}
osDelay(2);
if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){
osTimerStop(PwrBtnLongPressTimerHandle);
osTimerStop(PwrBtnShortPressTimerHandle);
}
osDelay(2);
//custom button
if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnLongPressTimerHandle)){
osTimerStop(CustBtnLongPressTimerHandle);
osTimerStop(CustBtnShortPressTimerHandle);
}
osDelay(2);
if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){
osTimerStart(CustBtnLongPressTimerHandle,1500);
osTimerStart(CustBtnShortPressTimerHandle,100);
}
osDelay(2);
}
/* USER CODE END StartButtonDetect */
}
void PwrBtnLongPressTimerCallback(void *argument)
{
log_v("power btn long pressed.");
switch(NaviKit.sys.sta){
case run: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;//system is run now, user request to idle
case idle: {NaviKit.sys.next_sta = run;log_v("change to run"); }break;//system is idle now , user request to power on
case dfu: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;
case sleep:{NaviKit.sys.next_sta = run;log_v("change to run"); }break;
case isp: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;
default : break;
}
}
void CustBtnLongPressTimerCallback(void *argument)
{
log_v("custom btn long pressed.");
switch(NaviKit.sys.sta){
case run:{//system is run now, user request to reboot SOM
som_reboot(100);
}break;
case idle:{
}break;
case dfu:{
som_reboot(100);
}break;
case sleep:{
}break;
default : break;
}
}
void PwrBtnShortPressTimerCallback(void *argument)
{
log_v("power btn short pressed.");
switch(NaviKit.sys.sta){
case run: {//som is running, send sleep requeset to operate system
log_v("Request operate system pop up the shutdown dialog.");
PWR_Enable(SOM_SLEEP,true,100);
PWR_Enable(SOM_SLEEP,false,0);
}break;
case idle: { }break;//system is idle now , user request to power on
case dfu: { }break;
case sleep:{ }break;
case isp: { }break;
default : break;
}
}
void CustBtnShortPressTimerCallback(void *argument)
{
log_v("custom btn short pressed.");
switch(NaviKit.sys.sta){
case run:{
}break;
case idle:{
}break;
case dfu:{
}break;
case sleep:{
}break;
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;
}
}

55
App/Src/th_coulomb.c Normal file
View File

@ -0,0 +1,55 @@
/*
* @Description:
* @Date: 2021-03-10 10:35:58
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-10 10:38:44
* @FilePath: \NaviKit_EC_stm32\App\Src\th_coulomb.c
*/
#define LOG_TAG "TH-Coulomb"
#include <th_coulomb.h>
#include "coulomb.h"
#include "main.h"
#include "navikit.h"
/* Definitions for CoulombRead */
const osThreadAttr_t CoulombRead_attributes = {
.name = "CoulombRead",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
/* 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 */
log_v("Start Coulomb Read Task");
//写寄存器方法
coulomb_write_config_load();
coulomb_write_config_actual_to_raw();
coulomb_write_config();
//读寄存器方法
coulomb_read_status_and_config();
coulomb_read_status_raw_to_actual();
coulomb_read_config_raw_to_actual();
/* Infinite loop */
for(;;)
{
coulomb_read_status_and_config();
coulomb_read_status_raw_to_actual();
if(NaviKit.sys.sta == run)
osDelay(500);
else
osDelay(5000);
}
/* USER CODE END StartCoulombRead */
}

View File

@ -16,6 +16,7 @@ const osThreadAttr_t DemoTask2_attributes = {
};
void StartDemoTask1(void *argument){
uint8_t i=0;
log_v("Start Demo Task1");
for(;;){
log_v("demo task 1 [%d].",i++);
osDelay(1000);
@ -23,6 +24,7 @@ void StartDemoTask1(void *argument){
}
void StartDemoTask2(void *argument){
uint8_t i=0;
log_v("Start Demo Task2");
for(;;){
log_v("demo task 2 [%d].",i++);
osDelay(1000);

View File

@ -2,7 +2,7 @@
* @Description:
* @Date: 2021-03-09 11:30:52
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-09 17:50:24
* @LastEditTime: 2021-03-10 10:59:15
* @FilePath: \NaviKit_EC_stm32\App\Src\th_elog.c
*/
@ -14,58 +14,41 @@
const osThreadAttr_t ElogInitTask_attributes = {
.name = "ElogInitTask",
.priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128 * 4
};
const osThreadAttr_t ElogFlushTask_attributes = {
.name = "ElogFlushTask",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
void StartElogInitTask(void *argument){
elog_init();
/* close printf buffer */
setbuf(stdout, NULL);
#ifndef DEBUG //release mode :only output level、tag、time information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME;
#else //debug mode:output all information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_ALL ;
#endif
/* set EasyLogger log format */
/* 断言:输出所有内容 */
elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_SETTING);
/* 错误:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_SETTING);
/* 警告:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_SETTING);
/* 信息:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_SETTING);
/* 调试:输出除了方法名之外的所有内容 */
elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_SETTING);
/* 详细:输出除了方法名之外的所有内容 */
elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_SETTING);
// my_elog_init();
/* start EasyLogger */
elog_start();
// log_a("Hello EasyLogger!");
// log_e("Hello EasyLogger!");
// log_w("Hello EasyLogger!");
// log_i("Hello EasyLogger!");
// log_d("Hello EasyLogger!");
// log_v("Hello EasyLogger!");
//
// osDelay(10000);
// log_d("Hello EasyLogger!");
// osThreadExit();//exit this thread,execute this code only once
}
void StartElogFlushTask(void *argument){
log_v("Start Elog Flush Task");
for(;;){
elog_flush();
osDelay(5);
}
}
void my_elog_init(){
elog_init();
/* close printf buffer */
setbuf(stdout, NULL);
#ifndef DEBUG //release mode :only output level、tag、time information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME;
#else //debug mode:output all information
#ifdef DEBUG //debug mode:output all information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_ALL ;
#else //release mode :only output level、tag、time information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME;
#endif
/* set EasyLogger log format */
/* 断言:输出所有内容 */

80
App/Src/th_led.c Normal file
View File

@ -0,0 +1,80 @@
/*
* @Description:
* @Date: 2021-03-10 10:11:18
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-10 10:13:16
* @FilePath: \NaviKit_EC_stm32\App\Src\th_led.c
*/
#define LOG_TAG "TH-Led"
#include <th_led.h>
#include "main.h"
#include "navikit.h"
const osThreadAttr_t LedBlinkTask_attributes = {
.name = "LedBlinkTask",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
/* USER CODE BEGIN Header_StartLedBlinkTask */
/**
* @brief Function implementing the LedBlinkTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartLedBlinkTask */
void StartLedBlinkTask(void *argument)
{
/* USER CODE BEGIN StartLedBlinkTask */
/* Infinite loop */
log_v("Start LED Blink Task");
for(;;)
{
osDelay(1000);
switch(NaviKit.sys.sta){
case run: {
PWR_Enable(SYS_PWR_LED,true,0);//turn on power led
PWR_Enable(SYS_RUN_LED,true,50);//turn on sys run led
PWR_Enable(SYS_RUN_LED,false,0);//turn off sys run led
}break;
case idle:{
PWR_Enable(SYS_PWR_LED,false,0);//turn on power led//turn off power led
PWR_Enable(SYS_RUN_LED,true,20);//turn on sys run led
PWR_Enable(SYS_RUN_LED,false,3000);//turn off sys run led
}break;
case sleep:{//sleep mode
for(uint16_t i=0;i<25;i++){//20 light level
for(uint16_t j=0;j<3;j++){//the time length of every light level
PWR_Enable(SYS_PWR_LED,false,0);
PWR_Enable(SYS_RUN_LED,false,0);
osDelay(i);
PWR_Enable(SYS_PWR_LED,true,0);
PWR_Enable(SYS_RUN_LED,true,0);
osDelay(25-i);
}
}
for(uint16_t i=0;i<25;i++){
for(uint16_t j=0;j<3;j++){
PWR_Enable(SYS_PWR_LED,false,0);
PWR_Enable(SYS_RUN_LED,false,0);
osDelay(25-i);
PWR_Enable(SYS_PWR_LED,true,0);
PWR_Enable(SYS_RUN_LED,true,0);
osDelay(i);
}
}
}break;
case dfu:{
PWR_Enable(SYS_PWR_LED,!PWR_Status(SYS_PWR_LED),0);
PWR_Enable(SYS_RUN_LED,!PWR_Status(SYS_PWR_LED),0);
}break;
default : break;
}
}
/* USER CODE END StartLedBlinkTask */
}

103
App/Src/th_power.c Normal file
View File

@ -0,0 +1,103 @@
/*
* @Description:
* @Date: 2021-03-10 10:44:19
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-10 10:45:36
* @FilePath: \NaviKit_EC_stm32\App\Src\th_power.c
*/
#define LOG_TAG "TH-Power"
#include <th_power.h>
#include "main.h"
#include "adc.h"
#include "navikit.h"
const osThreadAttr_t PowerMonitTask_attributes = {
.name = "PowerMonitTask",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
/* USER CODE BEGIN Header_StartPowerMonitTask */
/**
* @brief Function: Monit som power status and PMB status
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartPowerMonitTask */
void StartPowerMonitTask(void *argument)
{
/* USER CODE BEGIN StartPowerMonitTask */
log_v("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);
/* Infinite loop */
for(;;)
{
if(NaviKit.pmb.rails.main_pwr > 30){
TaskBeep(200,1);
log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}
if(NaviKit.pmb.rails.bkp_bat > 15){
log_e("Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
TaskBeep(200,1);
}
//stat1 stat2 lead-acid
//1 1 Not Charging
//1 0 Float Charge
//0 1 Absorption Charge
//0 0 Bulk Charge
NaviKit.pmb.sta.chrg_stat1 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT1_GPIO_Port, PMB_CHRG_STAT1_Pin);
NaviKit.pmb.sta.chrg_stat2 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT2_GPIO_Port, PMB_CHRG_STAT2_Pin);
if(!NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
log_v("Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
log_v("Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
log_v("Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
log_v("Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.sys.sta == run || NaviKit.sys.sta == dfu ){
if(NaviKit.pmb.rails.main_pwr < 19){
TaskBeep(200,1);
log_w("Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}else
log_v("Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6)
log_e("24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
else
log_v("24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5)
log_e("5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
else
log_v("5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8)
log_e("12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
else
log_v("12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
if(NaviKit.pmb.rails.bkp_bat < 9.5)
log_w("Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
else
log_v("Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
osDelay(2000);
}else {//not run state
osDelay(5000);
}
// log_d("state :%d",NaviKit.sys.sta);
// log_d("next_state :%d",NaviKit.sys.next_sta);
}
/* USER CODE END StartPowerMonitTask */
}

View File

@ -33,9 +33,9 @@ extern "C" {
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdbool.h"
#include "log.h"
#include "stdio.h"
#include "elog.h"
#include <isp.h>
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
@ -57,7 +57,7 @@ extern "C" {
void Error_Handler(void);
/* USER CODE BEGIN EFP */
void ISP_Judge();
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
@ -190,12 +190,6 @@ void ISP_Judge();
#define APP_VERSION "v0.9.6"
#ifdef DEBUG
#define DEPLOY_MODE "DEBUG" //debug mode
#else
#define DEPLOY_MODE "RELEASE" //release mode
#endif
/* USER CODE END Private defines */
#ifdef __cplusplus

View File

@ -17,6 +17,7 @@
#include "main.h"
#include "adc.h"
#include <isp.h>
//#include "stm32f1xx_hal.h"
//#include "gpio.h"

View File

@ -2,7 +2,7 @@
* @Description:
* @Date: 2020-04-02 21:44:31
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-09 18:11:08
* @LastEditTime: 2021-03-10 10:56:36
* @FilePath: \NaviKit_EC_stm32\Core\Src\freertos.c
*/
/* USER CODE BEGIN Header */
@ -25,7 +25,7 @@
*/
//TODO:拆分该文件中的功能到不同的文件中,按照任务进行模块化拆分
#define LOG_TAG "RTOS"
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
@ -39,10 +39,14 @@
/* USER CODE BEGIN Includes */
#include "timers.h"
#include "navikit.h"
#include "coulomb.h"
#include <th_cdc.h>
#include <th_demo.h>
#include <th_elog.h>
#include <th_led.h>
#include <th_coulomb.h>
#include <th_power.h>
#include <th_button.h>
/* USER CODE END Includes */
@ -64,36 +68,11 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
//Timer
osTimerId_t PwrBtnLongPressTimerHandle;
const osTimerAttr_t PwrBtnLongPressTimer_attributes = {
.name = "PwrBtnLongPressTimer"
};
osTimerId_t CustBtnLongPressTimerHandle;
const osTimerAttr_t CustBtnLongPressTimer_attributes = {
.name = "CustBtnLongPressTimer"
};
osTimerId_t PwrBtnShortPressTimerHandle;
const osTimerAttr_t PwrBtnShortPressTimer_attributes = {
.name = "PwrBtnShortPressTimer"
};
osTimerId_t CustBtnShortPressTimerHandle;
const osTimerAttr_t CustBtnShortPressTimer_attributes = {
.name = "CustBtnShortPressTimer"
};
osTimerId_t IdleStateHoldTimerHandle;
const osTimerAttr_t IdleStateHoldTimer_attributes = {
.name = "IdleStateHoldTimer"
};
//Thread
osThreadId_t LogtoUartTaskHandle;
const osThreadAttr_t LogtoUartTask_attributes = {
.name = "LogtoUartTask",
.priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128 * 4
};
@ -111,58 +90,23 @@ const osThreadAttr_t defaultTask_attributes = {
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 4
};
/* Definitions for LedBlinkTask */
osThreadId_t LedBlinkTaskHandle;
const osThreadAttr_t LedBlinkTask_attributes = {
.name = "LedBlinkTask",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
/* Definitions for CoulombRead */
osThreadId_t CoulombReadHandle;
const osThreadAttr_t CoulombRead_attributes = {
.name = "CoulombRead",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
/* Definitions for PowerMonitTask */
osThreadId_t PowerMonitTaskHandle;
const osThreadAttr_t PowerMonitTask_attributes = {
.name = "PowerMonitTask",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
/* Definitions for EventDetect */
osThreadId_t EventDetectHandle;
const osThreadAttr_t EventDetect_attributes = {
.name = "EventDetect",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
bool isWakeUpReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);}
//callback
void PwrBtnLongPressTimerCallback(void *argument);
void CustBtnLongPressTimerCallback(void *argument);
void PwrBtnShortPressTimerCallback(void *argument);
void CustBtnShortPressTimerCallback(void *argument);
void IdleStateHoldTimerCallback(void *argument);
//task
void StartLogtoUartTask(void *argument);
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void *argument);
void StartLedBlinkTask(void *argument);
void StartCoulombRead(void *argument);
void StartPowerMonitTask(void *argument);
void StartEventDetect(void *argument);
extern void MX_USB_DEVICE_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
@ -243,7 +187,7 @@ __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
*/
void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */
// elog_init();
my_elog_init();
NaviKit_var_init();
/* USER CODE END Init */
@ -258,11 +202,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 */
@ -277,7 +221,7 @@ void MX_FREERTOS_Init(void) {
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of LedBlinkTask */
LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
// LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
/* creation of CoulombRead */
// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
@ -286,22 +230,54 @@ void MX_FREERTOS_Init(void) {
// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes);
/* creation of EventDetect */
EventDetectHandle = osThreadNew(StartEventDetect, NULL, &EventDetect_attributes);
// EventDetectHandle = osThreadNew(StartEventDetect, NULL, &EventDetect_attributes);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
// LogtoUartTaskHandle = osThreadNew(StartLogtoUartTask, NULL, &LogtoUartTask_attributes);
//Power--------------------------------------------
// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes);
//Button--------------------------------------------
ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes);
//LED--------------------------------------------
LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
//CDC--------------------------------------------
cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes);
//Coulomb--------------------------------------------
// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
//Elog--------------------------------------------
// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes);
ElogFlushTaskHandle = osThreadNew(StartElogFlushTask, NULL, &ElogFlushTask_attributes);
// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes);
//Demo--------------------------------------------
// DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes);
// DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes);
cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes);
// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes);
// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes);
/* USER CODE END RTOS_THREADS */
/* 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 */
}
@ -351,26 +327,28 @@ void StartDefaultTask(void *argument)
// TaskBeep(50,1);
}
log_i("----------------------------------------------");
log_i("Copyright (c) Powered by www.autolabor.com.cn");
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());
log_i("EC Firmware: %s[%s], build: %s, %s, by STD:%u",APP_VERSION,DEPLOY_MODE,__DATE__ ,__TIME__,__STDC_VERSION__ );
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);
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("EasyLogger V%s is initialize success.", ELOG_SW_VERSION);
log_i("----------------------------------------------");
log_i("Core initial successfully");
log_i("----------------------------------------------");
/* Infinite loop */
for(;;)
@ -434,301 +412,15 @@ void StartDefaultTask(void *argument)
/* USER CODE END StartDefaultTask */
}
/* USER CODE BEGIN Header_StartLedBlinkTask */
/**
* @brief Function implementing the LedBlinkTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartLedBlinkTask */
void StartLedBlinkTask(void *argument)
{
/* USER CODE BEGIN StartLedBlinkTask */
/* Infinite loop */
// log_v("Start LED Blink");
for(;;)
{
osDelay(1000);
switch(NaviKit.sys.sta){
case run: {
PWR_Enable(SYS_PWR_LED,true,0);//turn on power led
PWR_Enable(SYS_RUN_LED,true,50);//turn on sys run led
PWR_Enable(SYS_RUN_LED,false,0);//turn off sys run led
}break;
case idle:{
PWR_Enable(SYS_PWR_LED,false,0);//turn on power led//turn off power led
PWR_Enable(SYS_RUN_LED,true,20);//turn on sys run led
PWR_Enable(SYS_RUN_LED,false,3000);//turn off sys run led
}break;
case sleep:{//sleep mode
for(uint16_t i=0;i<25;i++){//20 light level
for(uint16_t j=0;j<3;j++){//the time length of every light level
PWR_Enable(SYS_PWR_LED,false,0);
PWR_Enable(SYS_RUN_LED,false,0);
osDelay(i);
PWR_Enable(SYS_PWR_LED,true,0);
PWR_Enable(SYS_RUN_LED,true,0);
osDelay(25-i);
}
}
for(uint16_t i=0;i<25;i++){
for(uint16_t j=0;j<3;j++){
PWR_Enable(SYS_PWR_LED,false,0);
PWR_Enable(SYS_RUN_LED,false,0);
osDelay(25-i);
PWR_Enable(SYS_PWR_LED,true,0);
PWR_Enable(SYS_RUN_LED,true,0);
osDelay(i);
}
}
}break;
case dfu:{
PWR_Enable(SYS_PWR_LED,!PWR_Status(SYS_PWR_LED),0);
PWR_Enable(SYS_RUN_LED,!PWR_Status(SYS_PWR_LED),0);
}break;
default : break;
}
}
/* USER CODE END StartLedBlinkTask */
}
/* 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 */
// log_v("Start Coulomb Read Task");
//写寄存器方法
coulomb_write_config_load();
coulomb_write_config_actual_to_raw();
coulomb_write_config();
//读寄存器方法
coulomb_read_status_and_config();
coulomb_read_status_raw_to_actual();
coulomb_read_config_raw_to_actual();
/* Infinite loop */
for(;;)
{
coulomb_read_status_and_config();
coulomb_read_status_raw_to_actual();
if(NaviKit.sys.sta == run)
osDelay(500);
else
osDelay(5000);
}
/* USER CODE END StartCoulombRead */
}
/* USER CODE BEGIN Header_StartPowerMonitTask */
/**
* @brief Function: Monit som power status and PMB status
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartPowerMonitTask */
void StartPowerMonitTask(void *argument)
{
/* USER CODE BEGIN StartPowerMonitTask */
// log_v("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);
/* Infinite loop */
for(;;)
{
if(NaviKit.pmb.rails.main_pwr > 30){
TaskBeep(200,1);
log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}
if(NaviKit.pmb.rails.bkp_bat > 15){
log_e("Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
TaskBeep(200,1);
}
//stat1 stat2 lead-acid
//1 1 Not Charging
//1 0 Float Charge
//0 1 Absorption Charge
//0 0 Bulk Charge
NaviKit.pmb.sta.chrg_stat1 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT1_GPIO_Port, PMB_CHRG_STAT1_Pin);
NaviKit.pmb.sta.chrg_stat2 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT2_GPIO_Port, PMB_CHRG_STAT2_Pin);
if(!NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
log_v("Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
log_v("Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
log_v("Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
log_v("Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.sys.sta == run || NaviKit.sys.sta == dfu ){
if(NaviKit.pmb.rails.main_pwr < 19){
TaskBeep(200,1);
log_w("Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}else
log_v("Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6)
log_e("24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
else
log_v("24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5)
log_e("5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
else
log_v("5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8)
log_e("12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
else
log_v("12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
if(NaviKit.pmb.rails.bkp_bat < 9.5)
log_w("Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
else
log_v("Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
osDelay(2000);
}else {//not run state
osDelay(5000);
}
// log_d("state :%d",NaviKit.sys.sta);
// log_d("next_state :%d",NaviKit.sys.next_sta);
}
/* USER CODE END StartPowerMonitTask */
}
/* USER CODE BEGIN Header_StartEventDetect */
/**
* @brief Function implementing the EventDetect thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartEventDetect */
void StartEventDetect(void *argument)
{
/* USER CODE BEGIN StartEventDetect */
/* Infinite loop */
// log_v("Start Event Detect Task.");
for(;;)
{
//power button
if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){
osTimerStart(PwrBtnLongPressTimerHandle,1500);
osTimerStart(PwrBtnShortPressTimerHandle,100);
}
osDelay(2);
if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){
osTimerStop(PwrBtnLongPressTimerHandle);
osTimerStop(PwrBtnShortPressTimerHandle);
}
osDelay(2);
//custom button
if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnLongPressTimerHandle)){
osTimerStop(CustBtnLongPressTimerHandle);
osTimerStop(CustBtnShortPressTimerHandle);
}
osDelay(2);
if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){
osTimerStart(CustBtnLongPressTimerHandle,1500);
osTimerStart(CustBtnShortPressTimerHandle,100);
}
osDelay(2);
}
/* USER CODE END StartEventDetect */
}
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
void StartLogtoUartTask(void *argument){
// HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,2);
}
void PwrBtnLongPressTimerCallback(void *argument)
{
log_v("power btn long pressed.");
switch(NaviKit.sys.sta){
case run: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;//system is run now, user request to idle
case idle: {NaviKit.sys.next_sta = run;log_v("change to run"); }break;//system is idle now , user request to power on
case dfu: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;
case sleep:{NaviKit.sys.next_sta = run;log_v("change to run"); }break;
case isp: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;
default : break;
}
}
void CustBtnLongPressTimerCallback(void *argument)
{
log_v("custom btn long pressed.");
switch(NaviKit.sys.sta){
case run:{//system is run now, user request to reboot SOM
som_reboot(100);
}break;
case idle:{
}break;
case dfu:{
som_reboot(100);
}break;
case sleep:{
}break;
default : break;
}
}
void PwrBtnShortPressTimerCallback(void *argument)
{
log_v("power btn short pressed.");
switch(NaviKit.sys.sta){
case run: {//som is running, send sleep requeset to operate system
log_v("Request operate system pop up the shutdown dialog.");
PWR_Enable(SOM_SLEEP,true,100);
PWR_Enable(SOM_SLEEP,false,0);
}break;
case idle: { }break;//system is idle now , user request to power on
case dfu: { }break;
case sleep:{ }break;
case isp: { }break;
default : break;
}
}
void CustBtnShortPressTimerCallback(void *argument)
{
log_v("custom btn short pressed.");
switch(NaviKit.sys.sta){
case run:{
}break;
case idle:{
}break;
case dfu:{
}break;
case sleep:{
}break;
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;
}
}
/* USER CODE END Application */

View File

@ -21,7 +21,7 @@
#include "usart.h"
/* USER CODE BEGIN 0 */
#include "log.h"
/* USER CODE END 0 */
UART_HandleTypeDef huart4;

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="com.st.stm32cube.ide.mcu.debug.launch.launchConfigurationType">
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.access_port_id" value="0"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_live_expr" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="false"/>
<intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.formatVersion" value="2"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{&quot;fItems&quot;:[{&quot;fIsFromMainTab&quot;:true,&quot;fPath&quot;:&quot;Release/NaviKit_EC_stm32.elf&quot;,&quot;fProjectName&quot;:&quot;NaviKit_EC_stm32&quot;,&quot;fPerformBuild&quot;:true,&quot;fDownload&quot;:true,&quot;fLoadSymbols&quot;:true}]}"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="default"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.remoteCommand" value="target remote"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startServer" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.divby0" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.unaligned" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.haltonexception" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swd_mode" value="true"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_port" value="61235"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_trace_div" value="8"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_trace_hclk" value="16000000"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.useRemoteTarget" value="true"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.vector_table" value=""/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.verify_flash_download" value="true"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_allow_halt" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_signal_halt" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_external_loader" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_logging" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_max_halt_delay" value="false"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_shared_stlink" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.external_loader" value=""/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.external_loader_init" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.frequency" value="0"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.halt_all_on_reset" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.log_file" value="E:\source\STM32CubeIDE\NaviKit_EC_stm32\Release\st-link_gdbserver_log.txt"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="enable"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.max_halt_delay" value="2"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="connect_under_reset"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value=""/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.swv.swv_wait_for_sync" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="false"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.initCommands" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="ST-LINK (ST-LINK GDB server)"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="61234"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="true"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="remote"/>
<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Release/NaviKit_EC_stm32.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="NaviKit_EC_stm32"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.1260902692"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/NaviKit_EC_stm32"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>

View File

@ -23,7 +23,7 @@
#include "usbd_cdc_if.h"
/* USER CODE BEGIN INCLUDE */
#include "log.h"
/* USER CODE END INCLUDE */
/* Private typedef -----------------------------------------------------------*/

View File

@ -1,3 +1,10 @@
/*
* @Description:
* @Date: 2020-02-20 11:58:24
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-09 18:32:44
* @FilePath: \NaviKit_EC_stm32\USB_DEVICE\Target\usbd_conf.h
*/
/* USER CODE BEGIN Header */
/**
******************************************************************************
@ -69,7 +76,7 @@
/*---------- -----------*/
#define USBD_MAX_STR_DESC_SIZ 512
/*---------- -----------*/
#define USBD_DEBUG_LEVEL 3
#define USBD_DEBUG_LEVEL 0
/*---------- -----------*/
#define USBD_SELF_POWERED 1
/*---------- -----------*/