change uart sender to blocking mode, not dma

fixed:  log lost  bug
remove : uart sender mutex
master
ThinkPad-T460P 2021-03-16 18:52:01 +08:00
parent 3fc9d2c2b2
commit dc280db762
13 changed files with 75 additions and 56 deletions

View File

@ -58,9 +58,9 @@ bool ISP_Prepare(){
osDelay(10);
if(HAL_RTCEx_BKUPRead(&hrtc,MAGIC_VALUE_ADDRESS) == MAGIC_VALUE)
{//write successful
TaskBeep(400,5);
log_v("Enter to EC update state.");
log_i("EC will reboot ,then run ISP automatic.");
TaskBeep(400,5);
HAL_NVIC_SystemReset();
return true;
}

View File

@ -45,7 +45,7 @@ void ElogInitTask(void *argument){
//intervalbuffer flush time interval
void ElogFlushTask(uint8_t intervnal){
log_d("Start log Flush Task");
log_d("Start Log Flush Task");
for(;;){
elog_flush();
osDelay(intervnal);
@ -59,8 +59,8 @@ void my_elog_init(){
setbuf(stdout, NULL);
#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;
#else //release mode :only output level、time information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TIME;
#endif
/* set EasyLogger log format */
/* 断言:输出所有内容 */
@ -83,8 +83,9 @@ void my_elog_init(){
elog_start();
}
void HAL_UART1_TxHalfCpltCallback(UART_HandleTypeDef *huart){
void HAL_UART1_TxCpltCallback(UART_HandleTypeDef *huart){
osSemaphoreRelease(ElogUartBinarySemHandle);
}
//void elog_set_filter(uint8_t level, const char *tag, const char *keyword);

View File

@ -9,16 +9,40 @@
#include <th_info.h>
#include "main.h"
#include "cmsis_os2.h"
const osThreadAttr_t InfoOutputTask_attributes = {
.name = "InfoOutputTask",
.priority = (osPriority_t) osPriorityLow2,
.priority = (osPriority_t) osPriorityLow1,
.stack_size = 256 * 4
};
void InfoOutputTask(void *argument){
osVersion_t osVersion;
char id_buf[20];
unsigned char id_size=20;
log_d("Start Info Output Task");
for(;;){
osThreadExit();
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 Frequency: %d Hz",osKernelGetTickFreq());
log_i("System Timer Frequency : %d Hz",osKernelGetSysTimerFreq());
log_i("Log Library Version : V%s",ELOG_SW_VERSION);
osThreadExit();
}

View File

@ -28,7 +28,7 @@ void LedBlinkTask(void *argument)
{
/* USER CODE BEGIN LedBlinkTask */
/* Infinite loop */
log_d(" LED Blink Task");
log_d("Start LED Blink Task");
for(;;)
{

View File

@ -44,7 +44,7 @@ void PowerMonitTask(void *argument)
{
if((NaviKit.pmb.rails.main_pwr > 30) || (NaviKit.pmb.rails.main_pwr < 19)){
NaviKit.pmb.main_pwr_good = false;
log_e("Main power:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
log_e("Main power :%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
if((NaviKit.sys.next_sta == run) && (NaviKit.sys.next_sta == run)){
TaskBeep(200,2);
}

View File

@ -189,7 +189,7 @@ void Error_Handler(void);
/* USER CODE BEGIN Private defines */
//define application software version
#define APP_VERSION "v0.9.6"
#define APP_VERSION "v0.9.7"
// set iwdg enable or disable
//#define IWDG_ENABLE

View File

@ -105,7 +105,7 @@ bool PWR_Status(enum Device_t device);
void NaviKit_var_init();
//power state machine switch function
void enter_standby_state();
void enter_standby_state(uint16_t delay);
void enter_isp_state();
void enter_run_state(uint16_t delay);
void enter_idle_state(uint16_t delay);

View File

@ -38,6 +38,7 @@
#include <th_power.h>
#include <th_exti.h>
#include <th_iwdg.h>
#include <th_info.h>
/* USER CODE END Includes */
@ -170,11 +171,12 @@ __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */
ElogUartBinarySemHandle = osSemaphoreNew(1, 0, &ElogUartBinarySem_attributes);
ElogOutputBinarySemHandle = osSemaphoreNew(1, 0, &ElogOutputBinarySem_attributes);
// ElogUartBinarySemHandle = osSemaphoreNew(1, 1, &ElogUartBinarySem_attributes);
ElogOutputBinarySemHandle = osSemaphoreNew(1, 1, &ElogOutputBinarySem_attributes);
my_elog_init();
NaviKit_var_init();
/* USER CODE END Init */
/* USER CODE BEGIN RTOS_MUTEX */
@ -244,6 +246,9 @@ void MX_FREERTOS_Init(void) {
// DemoTask2Handle = osThreadNew(DemoTask2, NULL, &DemoTask2_attributes);
//InfoOutput--------------------------------------------
InfoOutputTaskHandle = osThreadNew(InfoOutputTask, NULL, &InfoOutputTask_attributes);
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */
@ -266,9 +271,6 @@ 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;
// ResetSourceJudge();
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"
@ -283,7 +285,7 @@ osVersion_t osVersion;
}else{
NaviKit.sys.next_sta = idle;
log_i("EC Reset source: [RTC WakeUP]");
enter_standby_state();
enter_standby_state(100);
}
}else{//judge reset source "power on"
log_i("EC Reset source: [PowerON]");
@ -296,35 +298,16 @@ osVersion_t osVersion;
TaskBeep(50,1);
}
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 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");
/* Infinite loop */
for(;;)
{
osDelay(20);
osDelay(50);
if(NaviKit.sys.sta != NaviKit.sys.next_sta){
switch(NaviKit.sys.next_sta){
case standby: {
enter_standby_state();
enter_standby_state(100);
}break;
case idle: {
enter_idle_state(100);
@ -332,6 +315,7 @@ osVersion_t osVersion;
} break;
case run: {
if(NaviKit.pmb.main_pwr_good){
log_d("Main power good.");
enter_run_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta;
}else{
@ -346,6 +330,7 @@ osVersion_t osVersion;
}break;
case dfu:{
if(NaviKit.pmb.main_pwr_good){
log_d("Main power good.");
enter_dfu_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta;
}else{
@ -365,7 +350,6 @@ osVersion_t osVersion;
// || (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);
log_i("Idle state hold timer started.");

View File

@ -23,6 +23,7 @@ void NaviKit_var_init()
{
NaviKit.sys.sta = idle;
NaviKit.sys.next_sta = idle;
NaviKit.pmb.main_pwr_good = true;
}
void TaskBeep(uint32_t time_ms , uint8_t n)
@ -59,9 +60,9 @@ void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
}
void enter_standby_state(){
void enter_standby_state(uint16_t delay){
log_i("EC enter to STANDBY Mode to save power, see you!");
osDelay(10);
osDelay(delay);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);//Enable PA0 wakeup function
__HAL_RCC_RTC_DISABLE();
HAL_PWR_EnterSTANDBYMode();
@ -180,7 +181,7 @@ void PWR_Enable(enum Device_t device,bool en,uint16_t delay){
bool result = false;
result = PWR_Enable_IRQ(device,en,0);
if(result){
log_v("Device 0x%X has been %s",device,en ? "enabled" : "disabled");
log_v("Device 0x%02X -> %s",device,(en == true) ? "[ON]" : "[OFF]");
osDelay(delay);
}else{
log_e("Power_Enable device parameter is invalid!");

View File

@ -269,12 +269,12 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
}
/* USER CODE BEGIN 1 */
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart){
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
if(huart->Instance == USART1){
HAL_UART1_TxHalfCpltCallback(huart);
HAL_UART1_TxCpltCallback(huart);
}
}
__weak void HAL_UART1_TxHalfCpltCallback(UART_HandleTypeDef *huart){
__weak void HAL_UART1_TxCpltCallback(UART_HandleTypeDef *huart){
UNUSED(huart);
}

@ -1 +1 @@
Subproject commit 69ca6cd42c7370db783c8df9943fc44bc3761574
Subproject commit 949ef83b618c5119d915cba163f772c923310051

View File

@ -35,7 +35,7 @@
<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"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="enable"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fLaunchAttribute&quot;:&quot;monitor reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset&quot;],&quot;fCmdOptions&quot;:[]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]}}]}"/>
<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"/>
@ -68,6 +68,10 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="e810000,0xe810000"/>

View File

@ -5,7 +5,7 @@
<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.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"/>
@ -24,18 +24,18 @@
<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"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_shared_stlink" value="true"/>
<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.log_file" value="E:\source\STM32CubeIDE\NaviKit_EC_stm32\Debug\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"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="enable"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fLaunchAttribute&quot;:&quot;monitor reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset&quot;],&quot;fCmdOptions&quot;:[]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]}}]}"/>
<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"/>
@ -58,7 +58,7 @@
<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.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"/>
@ -68,6 +68,11 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="e810000,0xe810000"/>
</launchConfiguration>