release v0.9.5

master
ThinkPad-T460P 2021-01-07 19:01:08 +08:00
parent cef1099bbe
commit e50455a16b
11 changed files with 248 additions and 157 deletions

View File

@ -43,7 +43,7 @@
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
<listOptionValue builtIn="false" value="STM32F107xC"/>
<listOptionValue builtIn="false" value="DEBUG"/>
<listOptionValue builtIn="false" value="APP_VERSION=&quot;V0.9.4&quot;"/>
<listOptionValue builtIn="false" value="APP_VERSION=&quot;V0.9.5&quot;"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths.186388616" 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="../Core/Inc"/>

View File

@ -174,11 +174,11 @@ void ISP_Judge();
#define SOM_FORCE_RECOVERY_GPIO_Port GPIOD
#define SYS_SWO_Pin GPIO_PIN_3
#define SYS_SWO_GPIO_Port GPIOB
#define SOM_SYS_RESET_Pin GPIO_PIN_4
#define SOM_SYS_RESET_GPIO_Port GPIOB
#define SOM_SYS_RESET_EXTI_IRQn EXTI4_IRQn
#define SOM_MOD_SLEEP_Pin GPIO_PIN_5
#define SOM_MOD_SLEEP_Pin GPIO_PIN_4
#define SOM_MOD_SLEEP_GPIO_Port GPIOB
#define SOM_MOD_SLEEP_EXTI_IRQn EXTI4_IRQn
#define SOM_SYS_RESET_Pin GPIO_PIN_5
#define SOM_SYS_RESET_GPIO_Port GPIOB
#define IIC1_SCL_Pin GPIO_PIN_8
#define IIC1_SCL_GPIO_Port GPIOB
#define IIC1_SDA_Pin GPIO_PIN_9

View File

@ -1,10 +1,3 @@
/*
* @Description:
* @Date: 2020-04-02 21:44:31
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-07 14:49:31
* @FilePath: \NaviKit_stm32\Core\Src\freertos.c
*/
/* USER CODE BEGIN Header */
/**
******************************************************************************
@ -62,6 +55,8 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
//Timer
osTimerId_t PwrBtnLongPressTimerHandle;
const osTimerAttr_t PwrBtnLongPressTimer_attributes = {
.name = "PwrBtnLongPressTimer"
@ -78,6 +73,38 @@ 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
};
osThreadId_t TestTask1Handle;
const osThreadAttr_t TestTask1_attributes = {
.name = "TestTask1",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 4
};
osThreadId_t TestTask2Handle;
const osThreadAttr_t TestTask2_attributes = {
.name = "TestTask2",
.priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128 * 4
};
//Queue
//osMessageQueueId_t LogMessageQueueHandle;
//const osMessageQueueAttr_t LogMessageQueue_attributes = {
// .name = "LogMessageQueue"
//};
/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
@ -119,12 +146,20 @@ const osThreadAttr_t EventDetect_attributes = {
/* 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);
void StartTestTask1(void *argument);
void StartTestTask2(void *argument);
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void *argument);
@ -229,10 +264,14 @@ void MX_FREERTOS_Init(void) {
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 */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
// LogMessageQueueHandle = osMessageQueueNew (1024, sizeof(uint8_t), &LogMessageQueue_attributes);
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
@ -253,6 +292,9 @@ void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
// LogtoUartTaskHandle = osThreadNew(StartLogtoUartTask, NULL, &LogtoUartTask_attributes);
// TestTask1Handle = osThreadNew(StartTestTask1, NULL, &TestTask1_attributes);
// TestTask2Handle = osThreadNew(StartTestTask2, NULL, &TestTask2_attributes);
/* USER CODE END RTOS_THREADS */
@ -290,16 +332,16 @@ void StartDefaultTask(void *argument)
else{
NaviKit.sys.power_btn = true;
}
Log(info,"EC Reset source :Power Button WakeUP");
Log(info,sys,"EC Reset source :Power Button WakeUP");
}else{
NaviKit.sys.next_sta = idle;
Log(info,"EC Reset source :RTC WakeUP");
Log(info,sys,"EC Reset source :RTC WakeUP");
enter_standby_state();
}
}else{//judge reset source "power on"
Log(info,"EC Reset source :PowerON");
Log(info,sys,"EC Reset source :PowerON");
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){
Log(debug,"EC next state isp");
Log(debug,sys,"EC next state isp");
NaviKit.sys.next_sta = isp;
}else{
NaviKit.sys.next_sta = idle;
@ -307,21 +349,21 @@ void StartDefaultTask(void *argument)
TaskBeep(50,1);
}
Log(info,"----------------------------------------------");
Log(info,"Copyright (c) Powered by www.autolabor.com.cn");
Log(info,sys,"----------------------------------------------");
Log(info,sys,"Copyright (c) Powered by www.autolabor.com.cn");
Log(info,"EC Firmware: %s[%s], build: %s, %s, by STD:%u",APP_VERSION,DEPLOY_MODE,__DATE__ ,__TIME__,__STDC_VERSION__ );
Log(info,"HAL Version: %u ", HAL_GetHalVersion());
Log(info,"Revision ID: %u ", HAL_GetREVID());
Log(info,"Device ID: %u ", HAL_GetDEVID());
Log(info,"Chip UID: %u%u%u ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2());
Log(info,sys,"EC Firmware: %s[%s], build: %s, %s, by STD:%u",APP_VERSION,DEPLOY_MODE,__DATE__ ,__TIME__,__STDC_VERSION__ );
Log(info,sys,"HAL Version: %u ", HAL_GetHalVersion());
Log(info,sys,"Revision ID: %u ", HAL_GetREVID());
Log(info,sys,"Device ID: %u ", HAL_GetDEVID());
Log(info,sys,"Chip UID: %u%u%u ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2());
if(osOK == osKernelGetInfo(&osVersion,id_buf,id_size)){
Log(info,"OS Kernel Version: %u ", osVersion.kernel);
Log(info,"OS Kernel ID: %s ",id_buf);
Log(info,sys,"OS Kernel Version: %u ", osVersion.kernel);
Log(info,sys,"OS Kernel ID: %s ",id_buf);
}
Log(info,"Core initial successfully");
Log(info,"----------------------------------------------");
Log(info,sys,"Core initial successfully");
Log(info,sys,"----------------------------------------------");
/* Infinite loop */
for(;;)
@ -344,8 +386,8 @@ void StartDefaultTask(void *argument)
}else{
NaviKit.sys.next_sta = NaviKit.sys.sta;
TaskBeep(500,2);
Log(error,"Main power not exist, retry after plug in it.");
Log(fatal,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
Log(error,pmb,"Main power not exist, retry after plug in it.");
Log(fatal,pmb,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}
}break;
case sleep:{
@ -359,8 +401,8 @@ void StartDefaultTask(void *argument)
}else{
NaviKit.sys.next_sta = NaviKit.sys.sta;
TaskBeep(500,2);
Log(error,"Main power not exist, retry after plug in it.");
Log(fatal,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
Log(error,pmb,"Main power not exist, retry after plug in it.");
Log(fatal,pmb,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}
}break;
case isp:{
@ -370,6 +412,17 @@ void StartDefaultTask(void *argument)
}
}
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 */
}
@ -488,10 +541,10 @@ void StartPowerMonitTask(void *argument)
if(NaviKit.pmb.rails.main_pwr > 30){
TaskBeep(200,1);
Log(fatal,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
Log(fatal,pmb,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}
if(NaviKit.pmb.rails.bkp_bat > 15){
Log(fatal,"Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
Log(fatal,pmb,"Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
TaskBeep(200,1);
}
//stat1 stat2 lead-acid
@ -503,55 +556,49 @@ void StartPowerMonitTask(void *argument)
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(trace,"Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
Log(trace,pmb,"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(trace,"Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
Log(trace,pmb,"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(trace,"Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
Log(trace,pmb,"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(trace,"Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
Log(trace,pmb,"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(warning,"Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
Log(warning,pmb,"Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}else
Log(trace,"Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
Log(trace,pmb,"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(fatal,"PMB's 24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
Log(fatal,pmb,"24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
else
Log(trace,"PMB's 24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
Log(trace,pmb,"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(fatal,"PMB's 5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
Log(fatal,pmb,"5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
else
Log(trace,"PMB's 5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
Log(trace,pmb,"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(fatal ,"PMB's 12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
Log(fatal ,pmb,"12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
else
Log(trace,"PMB's 12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
Log(trace,pmb,"12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
if(NaviKit.pmb.rails.bkp_bat < 9.5)
Log(warning,"Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
Log(warning,pmb,"Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
else
Log(trace,"Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
Log(trace,pmb,"Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
osDelay(2000);
}else {//not run state
osDelay(5000);
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;
// }
NaviKit.sys.next_sta = standby;
}
}
Log(debug,"state :%d",NaviKit.sys.sta);
Log(debug,"next_state :%d",NaviKit.sys.next_sta);
// Log(debug,sys,"state :%d",NaviKit.sys.sta);
// Log(debug,sys,"next_state :%d",NaviKit.sys.next_sta);
}
/* USER CODE END StartPowerMonitTask */
@ -574,7 +621,7 @@ void StartEventDetect(void *argument)
//power button
if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){
osTimerStart(PwrBtnLongPressTimerHandle,1500);
osTimerStart(PwrBtnShortPressTimerHandle,200);
osTimerStart(PwrBtnShortPressTimerHandle,100);
}
osDelay(2);
if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){
@ -590,7 +637,7 @@ void StartEventDetect(void *argument)
osDelay(2);
if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){
osTimerStart(CustBtnLongPressTimerHandle,1500);
osTimerStart(CustBtnShortPressTimerHandle,200);
osTimerStart(CustBtnShortPressTimerHandle,100);
}
osDelay(2);
}
@ -599,28 +646,49 @@ void StartEventDetect(void *argument)
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
void StartLogtoUartTask(void *argument){
// HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,2);
}
void StartTestTask1(void *argument){
uint8_t i=0;
for(;;){
Log(debug,sys,"test task 1 [%d].",i++);
osDelay(1000);
}
}
void StartTestTask2(void *argument){
uint8_t i=0;
for(;;){
Log(debug,sys,"test task 2 [%d].",i++);
osDelay(1000);
}
}
void PwrBtnLongPressTimerCallback(void *argument)
{
Log(trace,"power btn long pressed.");
Log(trace,sys,"power btn long pressed.");
switch(NaviKit.sys.sta){
case run: {NaviKit.sys.next_sta = idle;Log(trace,"change to idle"); }break;//system is run now, user request to idle
case idle: {NaviKit.sys.next_sta = run;Log(trace,"change to run"); }break;//system is idle now , user request to power on
case dfu: {NaviKit.sys.next_sta = idle;Log(trace,"change to idle"); }break;
case sleep:{NaviKit.sys.next_sta = run;Log(trace,"change to run"); }break;
case isp: {NaviKit.sys.next_sta = idle;Log(trace,"change to idle"); }break;
case run: {NaviKit.sys.next_sta = idle;Log(trace,sys,"change to idle"); }break;//system is run now, user request to idle
case idle: {NaviKit.sys.next_sta = run;Log(trace,sys,"change to run"); }break;//system is idle now , user request to power on
case dfu: {NaviKit.sys.next_sta = idle;Log(trace,sys,"change to idle"); }break;
case sleep:{NaviKit.sys.next_sta = run;Log(trace,sys,"change to run"); }break;
case isp: {NaviKit.sys.next_sta = idle;Log(trace,sys,"change to idle"); }break;
default : break;
}
}
void CustBtnLongPressTimerCallback(void *argument)
{
Log(trace,"custom btn long pressed.");
Log(trace,sys,"custom btn long pressed.");
switch(NaviKit.sys.sta){
case run:{//system is run now, user request to reboot SOM
som_reboot(200);
som_reboot(100);
}break;
case idle:{
}break;
case dfu:{
som_reboot(100);
}break;
case sleep:{
}break;
@ -629,11 +697,11 @@ void CustBtnLongPressTimerCallback(void *argument)
}
void PwrBtnShortPressTimerCallback(void *argument)
{
Log(trace,"power btn short pressed.");
Log(trace,sys,"power btn short pressed.");
switch(NaviKit.sys.sta){
case run: {//som is running, send sleep requeset to operate system
PWR_Enable(SOM_SLEEP,true,150);
Log(trace,"Request sleep dialog.");
Log(trace,som,"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
@ -645,9 +713,9 @@ void PwrBtnShortPressTimerCallback(void *argument)
}
void CustBtnShortPressTimerCallback(void *argument)
{
Log(trace,"custom btn short pressed.");
Log(trace,sys,"custom btn short pressed.");
switch(NaviKit.sys.sta){
case run:{//system is run now, user request to reboot SOM
case run:{
}break;
case idle:{
}break;
@ -658,6 +726,12 @@ void CustBtnShortPressTimerCallback(void *argument)
default : break;
}
}
void IdleStateHoldTimerCallback(void *argument){
if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){
Log(trace,sys,"Idle state duration more than 5000ms.");
NaviKit.sys.next_sta = standby;
}
}
/* USER CODE END Application */

View File

@ -65,7 +65,7 @@ void MX_GPIO_Init(void)
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, IIC2_SCL_Pin|IIC2_SDA_Pin|USB2_VBUS_CTL_1_Pin|USB2_VBUS_CTL_2_Pin
|USB2_VBUS_CTL_3_Pin|USB2_VBUS_CTL_4_Pin, GPIO_PIN_RESET);
|USB2_VBUS_CTL_3_Pin|USB2_VBUS_CTL_4_Pin|SOM_SYS_RESET_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, USB2_VBUS_CTL_5_Pin|USB2_VBUS_CTL_6_Pin|USB3_VBUS_CTL_5_Pin|USB3_VBUS_CTL_6_Pin
@ -169,16 +169,17 @@ void MX_GPIO_Init(void)
HAL_GPIO_Init(SOM_SHUTDOWN_REQ_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = SOM_SYS_RESET_Pin;
GPIO_InitStruct.Pin = SOM_MOD_SLEEP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(SOM_SYS_RESET_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_Init(SOM_MOD_SLEEP_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = SOM_MOD_SLEEP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(SOM_MOD_SLEEP_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = SOM_SYS_RESET_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(SOM_SYS_RESET_GPIO_Port, &GPIO_InitStruct);
}

View File

@ -2,7 +2,7 @@
* @Description:
* @Date: 2020-04-17 13:16:16
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-06 17:04:41
* @LastEditTime: 2021-01-07 18:00:29
* @FilePath: \NaviKit_stm32\Core\Src\navikit.c
*/
/*
@ -63,7 +63,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
if(NaviKit.sys.sta == run){//if jetson nano shutdown output low,the power_en should be set low less than 10us
PWR_Enable(SOM_PWR_EN,false,0);
NaviKit.sys.next_sta = idle;
Log(info,"SOM's shutdown_req pin falling edge, SOM request to shutdown.");
Log(info,som,"SOM's shutdown_req pin falling edge, SOM request to shutdown.");
}
}else{//Rising edge trigger
}
@ -71,26 +71,26 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
case SOM_MOD_SLEEP_Pin:{
if(HAL_GPIO_ReadPin(SOM_MOD_SLEEP_GPIO_Port, SOM_MOD_SLEEP_Pin)==GPIO_PIN_SET){//Rising edge trigger
Log(info,"SOM's sleep pin rising edge.");
Log(info,som,"SOM's sleep pin rising edge.");
}else{//falling edge trigger
Log(trace,"SOM's sleep pin falling edge.");
Log(trace,som,"SOM's sleep pin falling edge.");
}
}break;
case SYS_POWER_BTN_Pin:{
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger
NaviKit.sys.power_btn = true;
Log(debug,"power_btn status: pressed.");
Log(debug,sys,"power_btn status: pressed.");
}else{//falling edge trigger
NaviKit.sys.power_btn = false;
Log(debug,"power_btn status: released.");
Log(debug,sys,"power_btn status: released.");
}
}break;
case SYS_CUSTOM_BTN_Pin:{
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){//falling edge trigger
Log(debug,"custom_btn status: pressed.");
Log(debug,sys,"custom_btn status: pressed.");
NaviKit.sys.custom_btn = true;
}else{//Rising edge trigger
Log(debug,"custom_btn status: released.");
Log(debug,sys,"custom_btn status: released.");
NaviKit.sys.custom_btn = false;
}
}break;
@ -100,7 +100,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
void enter_standby_state(){
Log(info,"Enter to STANDBY Mode to save power, see you!");
Log(info,sys,"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();
@ -124,19 +124,19 @@ void enter_isp_state()
if(HAL_RTCEx_BKUPRead(&hrtc,ISP_BKP_DR) == BKP_DR_Jump_to_ISP)
{//write successful
TaskBeep(400,5);
Log(info,"Enter to EC update state.");
Log(info,"EC will reboot ,then run ISP automatic.");
Log(info,sys,"Enter to EC update state.");
Log(info,sys,"EC will reboot ,then run ISP automatic.");
HAL_NVIC_SystemReset();
}
else{
Log(error,"Backup register writen error, can not enter EC update state.");
Log(error,sys,"Backup register writen error, can not enter EC update state.");
}
}
//timeout:the time of wait
void enter_idle_state(uint16_t delay)
{
Log(info,"Enter to idle state.");
Log(info,sys,"Enter to idle state.");
TaskBeep(50,1);
PWR_Enable(SOM_SLEEP,true,delay);
@ -165,25 +165,22 @@ void enter_idle_state(uint16_t delay)
PWR_Enable(SYS_FAN2 ,false , delay);
PWR_Enable(SYS_FAN3 ,false , delay);
osDelay(5000);
TaskBeep(50,1);
PWR_Enable(SOM_PWR_EN ,false, delay);
PWR_Enable(PMB_PS_ON ,false , delay);
PWR_Enable(PMB_PS_ON ,false , 0);
}
void enter_run_state(uint16_t delay)
{
Log(info,"Enter to run state");
Log(info,sys,"Enter to run state");
TaskBeep(200,1);
PWR_Enable(PMB_PS_ON ,true, delay);
PWR_Enable(SOM_DFU ,false, delay);
PWR_Enable(SOM_DFU ,false, 0); //disable dfu pin
PWR_Enable(SOM_RESET , false , 0); //disable reset pin
PWR_Enable(SYS_FAN1 ,true , delay);
PWR_Enable(SYS_FAN2 ,true , delay);
@ -214,18 +211,19 @@ void enter_run_state(uint16_t delay)
}
void enter_sleep_state(uint16_t delay)
{
Log(info,"Enter to sleep state.");
Log(info,sys,"Enter to sleep state.");
TaskBeep(50,1);
}
void enter_dfu_state(uint16_t delay)
{
Log(info,"Enter to DFU state.");
Log(info,sys,"Enter to DFU state.");
TaskBeep(500,3);
PWR_Enable(PMB_PS_ON , true , delay);
PWR_Enable(SOM_DFU , true , delay);
PWR_Enable(SOM_DFU , true , 0);
PWR_Enable(SOM_RESET , false , 0); //disable reset pin
PWR_Enable(SYS_FAN1 , true , delay);
PWR_Enable(SYS_FAN2 , true , delay);
@ -233,27 +231,13 @@ void enter_dfu_state(uint16_t delay)
PWR_Enable(SOM_PWR_EN , true , delay);
osDelay(100);
}
//para, delayreset low level signal duration (ms)
void som_reboot(uint16_t delay){
GPIO_InitTypeDef GPIO_InitStruct = {0};
Log(info,"SOM rebooting...");
GPIO_InitStruct.Pin = SOM_SYS_RESET_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(SOM_SYS_RESET_GPIO_Port, &GPIO_InitStruct);
PWR_Enable(SOM_RESET,true,delay);
TaskBeep(50,1);
PWR_Enable(SOM_RESET,false,0);
GPIO_InitStruct.Pin = SOM_SYS_RESET_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(SOM_SYS_RESET_GPIO_Port, &GPIO_InitStruct);
Log(info,som,"Jetson Nano rebooting...");
PWR_Enable(SOM_RESET,true,0);
TaskBeep(100,1);
PWR_Enable(SOM_RESET,false,0);
}
@ -288,7 +272,7 @@ void PWR_Enable(enum Device_t device,bool en,uint16_t delay){
case SOM_RESET: {HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port, SOM_SYS_RESET_Pin, !en); }break;
case SOM_SLEEP: {HAL_GPIO_WritePin(SOM_SLEEP_WAKE_GPIO_Port, SOM_SLEEP_WAKE_Pin, !en); }break;
case PMB_PS_ON: {HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port, PMB_PS_ON_Pin, en); }break;
default: {Log(error,"PWR_Enable device parameter is invalid."); }break;
default: {Log(error,sys,"PWR_Enable device parameter is invalid."); }break;
}
osDelay(delay);
}
@ -324,7 +308,7 @@ bool PWR_Status(enum Device_t device){
case SOM_RESET: {sta = !HAL_GPIO_ReadPin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_Pin); }break;
case SOM_SLEEP: {sta = !HAL_GPIO_ReadPin(SOM_SLEEP_WAKE_GPIO_Port,SOM_SLEEP_WAKE_Pin); }break;
case PMB_PS_ON: {sta = HAL_GPIO_ReadPin(PMB_PS_ON_GPIO_Port,PMB_PS_ON_Pin); }break;
default: {Log(error,"PWR_Status device parameter is invalid."); }break;
default: {Log(error,sys,"PWR_Status device parameter is invalid."); }break;
}
return sta;
}

View File

@ -91,7 +91,7 @@ void NMI_Handler(void)
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
Log(fatal,"HardFault_Handler");
Log(fatal,sys,"HardFault_Handler");
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
@ -106,7 +106,7 @@ void HardFault_Handler(void)
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
Log(fatal,"MemManage_Handler");
Log(fatal,sys,"MemManage_Handler");
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
@ -121,7 +121,7 @@ void MemManage_Handler(void)
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
Log(fatal,"BusFault_Handler");
Log(fatal,sys,"BusFault_Handler");
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
@ -136,7 +136,7 @@ void BusFault_Handler(void)
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
Log(fatal,"UsageFault_Handler");
Log(fatal,sys,"UsageFault_Handler");
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{

View File

@ -182,11 +182,7 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
PUTCHAR_PROTOTYPE
{
// uint8_t time_out=3;
// while(!__HAL_UART_GET_FLAG(&huart1,UART_FLAG_TXE) && time_out--){
// HAL_Delay(1);
// }
HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,100);
HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,10);
return ch;
}

View File

@ -1,3 +1,10 @@
/*
* @Description:
* @Date: 2020-12-22 18:27:24
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-07 17:54:00
* @FilePath: \NaviKit_stm32\Middlewares\Log\log.c
*/
/*
* log.c
*
@ -6,33 +13,43 @@
*/
#include "log.h"
static bool mutex =false;
void Log(LogLevel_t loglevel,char *format,...)
void Log(LogLevel_t level,LogPositon_t positon,char *format,...)
{
switch(loglevel){
case trace:{
printf("[Trace ] ") ;
}break;
case debug:{
printf("[Debug ] ") ;
}break;
case info:{
printf("[Info ] ") ;
}break;
case warning:{
printf("[Warning] ") ;
}break;
case error:{
printf("[Error ] ") ;
}break;
case fatal:{
printf("[Fatal ] ") ;
}break;
if(mutex){
unsigned char time_out = 100;
while(mutex && time_out--){//100ms timout for multi-thread use log function
osDelay(1);
}
}
if(!mutex){
mutex = true;
switch(level){
case trace: { printf("[Trace ] ") ; }break;
case debug: { printf("[Debug ] ") ; }break;
case info: { printf("[Info ] ") ; }break;
case warning:{ printf("[Warning] ") ; }break;
case error: { printf("[Error ] ") ; }break;
case fatal: { printf("[Fatal ] ") ; }break;
default: { printf("[Undefined Level] ") ; }break;
}
switch (positon)
{
case sys:{ printf("SYS: ") ; }break;
case som:{ printf("SOM: ") ; }break;
case pmb:{ printf("PMB: ") ; }break;
default: { printf("Undefined Position: ") ;}break;
}
printf("%u | ",osKernelGetTickCount());
va_list args;
va_start( args, format );
print(0, format, args );
printf("\n") ;
mutex = false;
}
}

View File

@ -1,3 +1,10 @@
/*
* @Description:
* @Date: 2020-12-22 18:27:24
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-07 17:50:39
* @FilePath: \NaviKit_stm32\Middlewares\Log\log.h
*/
/*
* log.h
*
@ -9,6 +16,7 @@
#define LOG_LOG_H_
#include <stdarg.h>
#include <stdbool.h>
typedef enum {
trace = 0,
@ -19,5 +27,11 @@ typedef enum {
fatal =5
}LogLevel_t;
void Log(LogLevel_t loglevel,char *format, ...);
typedef enum {
sys = 0,//system:board device and ec device
som = 1,//system on module: jetson nano
pmb = 2,//power manage board
}LogPositon_t;
void Log(LogLevel_t level,LogPositon_t positon,char *format, ...);
#endif /* LOG_LOG_H_ */

View File

@ -319,10 +319,12 @@ PB4.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING
PB4.GPIO_PuPd=GPIO_PULLUP
PB4.Locked=true
PB4.Signal=GPXTI4
PB5.GPIOParameters=GPIO_Label
PB5.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultOutputPP
PB5.GPIO_Label=SOM_SYS_RESET
PB5.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
PB5.GPIO_PuPd=GPIO_PULLUP
PB5.Locked=true
PB5.Signal=GPIO_Input
PB5.Signal=GPIO_Output
PB8.GPIOParameters=GPIO_Label
PB8.GPIO_Label=IIC1_SCL
PB8.Locked=true
@ -650,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=true
isbadioc=false

View File

@ -3,7 +3,7 @@
* @Author: CK.Zh
* @Date: 2020-02-20 11:39:38
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-05 16:21:59
* @LastEditTime: 2021-01-07 15:23:09
-->
# NaviKit_stm32
PM1导航套件中电源控制板源码STM32F107VCT6开发环境STM32CubeIDE
@ -32,4 +32,7 @@
`void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)`函数内
`HAL_PCD_SuspendCallback(hpcd); `代码段 务必屏蔽,否则导致枚举失败,提示获取设备描述符失败。
> EC日志输出口波特率为56000bps
> EC日志输出口波特率为56000bps
# 勘误
硬件的v1.0以前版本中SYS_RESET脚和MOD_SLEEP到单片机的实际连接与网络标号是相反的问题发生在TXB0108PWR芯片附近故代码中在GPIO处进行了相反的设置。