master
ThinkPad-T460P 2021-01-07 15:11:11 +08:00
parent bb3304bd27
commit cef1099bbe
7 changed files with 344 additions and 299 deletions

View File

@ -128,7 +128,7 @@ enum Device_t{USB2_Port1,USB2_Port2,USB2_Port3,USB2_Port4,USB2_Port5,USB2_Port6,
SOC_USB2_HUB,SOC_USB3_HUB,SOC_USB3_HOST,SOC_USB3_GEC,SOC_GE_SW, //SOC on Board
SYS_FAN1,SYS_FAN2,SYS_FAN3, //Fan on Board
SYS_RUN_LED,SYS_PWR_LED, //LED on Board
SOM_PWR_EN,SOM_DFU,SOM_RESET, //SOM Control
SOM_PWR_EN,SOM_DFU,SOM_RESET,SOM_SLEEP, //SOM Control
PMB_PS_ON}; //Power Management Board
void PWR_Enable(enum Device_t device,bool en,uint16_t delay);
@ -143,6 +143,7 @@ void enter_run_state(uint16_t delay);
void enter_idle_state(uint16_t delay);
void enter_sleep_state(uint16_t delay);
void enter_dfu_state(uint16_t delay);
void som_reboot(uint16_t delay);
//non-blocking beep function with os delay
void TaskBeep(uint32_t time_ms, uint8_t n);

View File

@ -28,7 +28,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "navikit.h"
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
@ -59,6 +59,7 @@ void FLASH_IRQHandler(void);
void RCC_IRQHandler(void);
void EXTI0_IRQHandler(void);
void EXTI3_IRQHandler(void);
void EXTI4_IRQHandler(void);
void DMA1_Channel1_IRQHandler(void);
void ADC1_2_IRQHandler(void);
void EXTI9_5_IRQHandler(void);

View File

@ -2,7 +2,7 @@
* @Description:
* @Date: 2020-04-02 21:44:31
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-04 17:49:58
* @LastEditTime: 2021-01-07 14:49:31
* @FilePath: \NaviKit_stm32\Core\Src\freertos.c
*/
/* USER CODE BEGIN Header */
@ -62,18 +62,22 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
osEventFlagsId_t buttonEventHandle;
const osEventFlagsAttr_t buttonEvent_attributes = {
.name = "buttonEvent"
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"
};
//osThreadId_t StateSwitchTaskHandle;
//const osThreadAttr_t StateSwitchTask_attributes = {
// .name = "StateSwitchTask",
// .priority = (osPriority_t) osPriorityNormal,
// .stack_size = 128 * 4
//};
/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
@ -110,25 +114,17 @@ const osThreadAttr_t EventDetect_attributes = {
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
/* Definitions for PwrBtnTimer */
osTimerId_t PwrBtnTimerHandle;
const osTimerAttr_t PwrBtnTimer_attributes = {
.name = "PwrBtnTimer"
};
/* Definitions for CustBtnTimer */
osTimerId_t CustBtnTimerHandle;
const osTimerAttr_t CustBtnTimer_attributes = {
.name = "CustBtnTimer"
};
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
//void osEnterSleepState();
//void osEnterRuningState();
//void StartStateSwitchTask(void *argument);
//void StartChangeStateTask(state_t target_sta);
bool isWakeUpReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);}
void PwrBtnLongPressTimerCallback(void *argument);
void CustBtnLongPressTimerCallback(void *argument);
void PwrBtnShortPressTimerCallback(void *argument);
void CustBtnShortPressTimerCallback(void *argument);
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void *argument);
@ -136,8 +132,6 @@ void StartLedBlinkTask(void *argument);
void StartCoulombRead(void *argument);
void StartPowerMonitTask(void *argument);
void StartEventDetect(void *argument);
void PwrBtnTimerCallback(void *argument);
void CustBtnTimerCallback(void *argument);
extern void MX_USB_DEVICE_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
@ -158,7 +152,7 @@ __weak void configureTimerForRunTimeStats(void)
__weak unsigned long getRunTimeCounterValue(void)
{
return osKernelGetTickCount();
// return osKernelGetTickCount();
}
/* USER CODE END 1 */
@ -229,15 +223,12 @@ void MX_FREERTOS_Init(void) {
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* Create the timer(s) */
/* creation of PwrBtnTimer */
PwrBtnTimerHandle = osTimerNew(PwrBtnTimerCallback, osTimerOnce, NULL, &PwrBtnTimer_attributes);
/* creation of CustBtnTimer */
CustBtnTimerHandle = osTimerNew(CustBtnTimerCallback, osTimerOnce, NULL, &CustBtnTimer_attributes);
/* 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);
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
@ -252,7 +243,7 @@ void MX_FREERTOS_Init(void) {
LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
/* creation of CoulombRead */
CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
/* creation of PowerMonitTask */
PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes);
@ -262,13 +253,11 @@ void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
// StateSwitchTaskHandle = osThreadNew(StartStateSwitchTask, NULL, &defaultTask_attributes);
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */
buttonEventHandle = osEventFlagsNew(&buttonEvent_attributes);
/* USER CODE END RTOS_EVENTS */
}
@ -289,22 +278,23 @@ void StartDefaultTask(void *argument)
char id_buf[20];
unsigned char id_size=20;
HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port,USB2_FS_ENUM_CTL_Pin, GPIO_PIN_SET);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
if(isWakeUpReset()){//judge reset source form "wakeup event"
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){
NaviKit.sys.next_sta = run;
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET)
NaviKit.sys.next_sta = dfu;
else{
NaviKit.sys.power_btn = true;
}
Log(info,"EC Reset source :Power Button WakeUP");
}else{
NaviKit.sys.next_sta = idle;
Log(info,"EC Reset source :RTC WakeUP");
// HAL_IWDG_Refresh(&hiwdg);
// HAL_PWR_EnterSTANDBYMode();
enter_standby_state();
}
}else{//judge reset source "power on"
Log(info,"EC Reset source :PowerON");
@ -314,6 +304,7 @@ void StartDefaultTask(void *argument)
}else{
NaviKit.sys.next_sta = idle;
}
TaskBeep(50,1);
}
Log(info,"----------------------------------------------");
@ -332,29 +323,45 @@ void StartDefaultTask(void *argument)
Log(info,"Core initial successfully");
Log(info,"----------------------------------------------");
TaskBeep(50,1);
/* Infinite loop */
for(;;)
{
// HAL_IWDG_Refresh(&hiwdg);
osDelay(100);
osDelay(20);
if(NaviKit.sys.sta != NaviKit.sys.next_sta){
switch(NaviKit.sys.next_sta){
case standby: {
enter_standby_state();
}break;
case idle: {
enter_idle_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta;
} break;
case run: {
enter_run_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta;
if(NaviKit.pmb.rails.main_pwr>19){
enter_run_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta;
}else{
NaviKit.sys.next_sta = NaviKit.sys.sta;
TaskBeep(500,2);
Log(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));
}
}break;
case sleep:{
enter_sleep_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta;
}break;
case dfu:{
enter_dfu_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta;
if(NaviKit.pmb.rails.main_pwr>19){
enter_dfu_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta;
}else{
NaviKit.sys.next_sta = NaviKit.sys.sta;
TaskBeep(500,2);
Log(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));
}
}break;
case isp:{
enter_isp_state();
@ -378,27 +385,22 @@ void StartLedBlinkTask(void *argument)
{
/* USER CODE BEGIN StartLedBlinkTask */
/* Infinite loop */
// Log(trace,"Start LED Blink");
for(;;)
{
osDelay(1000);
switch(NaviKit.sys.sta){
case run: {
if(!PWR_Status(SYS_PWR_LED)){
PWR_Enable(SYS_PWR_LED,true,100);//turn on power led
}
PWR_Enable(SYS_PWR_LED,true,0);//turn on power led
if(!PWR_Status(SYS_RUN_LED)){//sys run led is off
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:{
if(PWR_Status(SYS_PWR_LED))
PWR_Enable(SYS_PWR_LED,false,0);//turn on power led//turn off power led
PWR_Enable(SYS_PWR_LED,false,0);//turn on power led//turn off power led
if(PWR_Status(SYS_RUN_LED))//sys run led is off
PWR_Enable(SYS_RUN_LED,true,20);//turn on sys run led
else
PWR_Enable(SYS_RUN_LED,false,3000);//turn off sys run led
}break;
case sleep:{//sleep mode
@ -424,11 +426,10 @@ void StartLedBlinkTask(void *argument)
}
}break;
case dfu:{
PWR_Enable(SYS_PWR_LED,!PWR_Status(SYS_PWR_LED),150);
PWR_Enable(SYS_RUN_LED,!PWR_Status(SYS_PWR_LED),150);
PWR_Enable(SYS_PWR_LED,!PWR_Status(SYS_PWR_LED),0);
PWR_Enable(SYS_RUN_LED,!PWR_Status(SYS_PWR_LED),0);
}break;
case isp:
break;
default : break;
}
}
/* USER CODE END StartLedBlinkTask */
@ -444,6 +445,7 @@ void StartLedBlinkTask(void *argument)
void StartCoulombRead(void *argument)
{
/* USER CODE BEGIN StartCoulombRead */
// Log(trace,"Start Coulomb Read Task");
//写寄存器方法
coulomb_write_config_load();
coulomb_write_config_actual_to_raw();
@ -476,11 +478,22 @@ void StartCoulombRead(void *argument)
void StartPowerMonitTask(void *argument)
{
/* USER CODE BEGIN StartPowerMonitTask */
// Log(trace,"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(fatal,"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));
TaskBeep(200,1);
}
//stat1 stat2 lead-acid
//1 1 Not Charging
//1 0 Float Charge
@ -498,56 +511,47 @@ void StartPowerMonitTask(void *argument)
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));
if(NaviKit.sys.sta == run || NaviKit.sys.next_sta == run ){
osDelay(2000);
if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6)
Log(fatal,"24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
else
Log(trace,"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,"5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
else
Log(trace,"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 ,"12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
else
Log(trace,"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));
else
Log(trace,"Backup battery is regular:%dmV",(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));
}else
Log(trace,"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));
else
Log(trace,"PMB's 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));
else
Log(trace,"PMB's 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));
else
Log(trace,"PMB's 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));
else
Log(trace,"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){//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
Log(info,"EC enter STANDBY Mode to save power");
// __HAL_PWR_CLEAR_FLAG
__HAL_RCC_RTC_DISABLE();
HAL_PWR_EnterSTANDBYMode();
}
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;
}
}
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));
}
if(NaviKit.pmb.rails.bkp_bat > 15){
Log(fatal,"Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
TaskBeep(200,1);
}
Log(debug,"state :%d",NaviKit.sys.sta);
Log(debug,"next_state :%d",NaviKit.sys.next_sta);
}
/* USER CODE END StartPowerMonitTask */
@ -564,56 +568,55 @@ void StartEventDetect(void *argument)
{
/* USER CODE BEGIN StartEventDetect */
/* Infinite loop */
// Log(trace,"Start Event Detect Task.");
for(;;)
{
osDelay(10);
if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnTimerHandle)){
osTimerStart(PwrBtnTimerHandle,2000);
//power button
if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){
osTimerStart(PwrBtnLongPressTimerHandle,1500);
osTimerStart(PwrBtnShortPressTimerHandle,200);
}
if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnTimerHandle)){
osTimerStart(CustBtnTimerHandle,2000);
osDelay(2);
if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){
osTimerStop(PwrBtnLongPressTimerHandle);
osTimerStop(PwrBtnShortPressTimerHandle);
}
if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnTimerHandle)){
osTimerStop(PwrBtnTimerHandle);
Log(trace,"power btn short pressed");
osDelay(2);
//custom button
if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnLongPressTimerHandle)){
osTimerStop(CustBtnLongPressTimerHandle);
osTimerStop(CustBtnShortPressTimerHandle);
}
if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnTimerHandle)){
osTimerStop(CustBtnTimerHandle);
Log(trace,"custom btn short pressed");
osDelay(2);
if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){
osTimerStart(CustBtnLongPressTimerHandle,1500);
osTimerStart(CustBtnShortPressTimerHandle,200);
}
osDelay(2);
}
/* USER CODE END StartEventDetect */
}
/* PwrBtnTimerCallback function */
void PwrBtnTimerCallback(void *argument)
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
void PwrBtnLongPressTimerCallback(void *argument)
{
/* USER CODE BEGIN PwrBtnTimerCallback */
// Log(debug,"power btn timer callback");
Log(trace,"power btn long pressed");
Log(trace,"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;
default : break;
}
/* USER CODE END PwrBtnTimerCallback */
}
/* CustBtnTimerCallback function */
void CustBtnTimerCallback(void *argument)
void CustBtnLongPressTimerCallback(void *argument)
{
/* USER CODE BEGIN CustBtnTimerCallback */
// Log(debug,"custom btn timer callback");
Log(trace,"custom btn long pressed");
Log(trace,"custom btn long pressed.");
switch(NaviKit.sys.sta){
case run:{//system is run now, user request to restart system
PWR_Enable(SOM_RESET,true,10);
PWR_Enable(SOM_RESET,false,0);
Log(info,"SOM Reset.");
case run:{//system is run now, user request to reboot SOM
som_reboot(200);
}break;
case idle:{
}break;
@ -621,32 +624,41 @@ void CustBtnTimerCallback(void *argument)
}break;
case sleep:{
}break;
case isp:{
}break;
default : break;
}
/* USER CODE END CustBtnTimerCallback */
}
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
//printf redirect
#ifdef __GNUC__
//#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define PUTCHAR_PROTOTYPE int putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
void PwrBtnShortPressTimerCallback(void *argument)
{
while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY_TX){}
HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,1);
return ch;
Log(trace,"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.");
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(trace,"custom btn short pressed.");
switch(NaviKit.sys.sta){
case run:{//system is run now, user request to reboot SOM
}break;
case idle:{
}break;
case dfu:{
}break;
case sleep:{
}break;
default : break;
}
}
/* USER CODE END Application */

View File

@ -96,9 +96,9 @@ int main(void)
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C1_Init();
// MX_I2C1_Init();
// MX_IWDG_Init();
MX_UART4_Init();
// MX_UART4_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();
// MX_RTC_Init();
@ -161,8 +161,8 @@ void SystemClock_Config(void)
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV4;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV8;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV16;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
@ -218,6 +218,24 @@ static void MX_NVIC_Init(void)
/* USART1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
/* EXTI0_IRQn interrupt configuration */
HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
/* EXTI3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
/* EXTI9_5_IRQn interrupt configuration */
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
/* RTC_Alarm_IRQn interrupt configuration */
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
/* RTC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(RTC_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(RTC_IRQn);
/* EXTI4_IRQn interrupt configuration */
HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
}
/* USER CODE BEGIN 4 */

View File

@ -2,7 +2,7 @@
* @Description:
* @Date: 2020-04-17 13:16:16
* @LastEditors: CK.Zh
* @LastEditTime: 2020-12-30 14:19:14
* @LastEditTime: 2021-01-06 17:04:41
* @FilePath: \NaviKit_stm32\Core\Src\navikit.c
*/
/*
@ -27,9 +27,9 @@ void TaskBeep(uint32_t time_ms , uint8_t n)
{
for(uint8_t i=0;i<n;i++){
HAL_GPIO_WritePin(SYS_BUZZ_CTL_GPIO_Port,SYS_BUZZ_CTL_Pin, GPIO_PIN_RESET);
osDelay(time_ms>>1);
osDelay(time_ms>>1);//equal "time divided by 2"
HAL_GPIO_WritePin(SYS_BUZZ_CTL_GPIO_Port,SYS_BUZZ_CTL_Pin, GPIO_PIN_SET);
osDelay(time_ms>>1);
osDelay(time_ms>>1);//equal "time divided by 2"
}
}
@ -57,39 +57,54 @@ void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == SOM_SHUTDOWN_REQ_Pin){
if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port, SOM_SHUTDOWN_REQ_Pin)==GPIO_PIN_RESET){//falling edge trigger
if(NaviKit.sys.sta == run){//if jetson nano shutdown output low,the power_en should be set low less than 10us
HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port ,SOM_POWER_EN_Pin, GPIO_PIN_RESET);
NaviKit.sys.next_sta = idle;
Log(info,"SOM request to shutdown");
}
}
else{//Rising edge trigger
}
}
else if(GPIO_Pin == 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.");
}
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_RESET){//falling edge trigger
NaviKit.sys.power_btn = false;
Log(debug,"power_btn status: released.");
}
}
else if(GPIO_Pin == 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.");
NaviKit.sys.custom_btn = true;
}
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger
Log(debug,"custom_btn status: released.");
NaviKit.sys.custom_btn = false;
}
switch (GPIO_Pin){
case SOM_SHUTDOWN_REQ_Pin:{
if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port, SOM_SHUTDOWN_REQ_Pin)==GPIO_PIN_RESET){//falling edge trigger
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.");
}
}else{//Rising edge trigger
}
}break;
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.");
}else{//falling edge trigger
Log(trace,"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.");
}else{//falling edge trigger
NaviKit.sys.power_btn = false;
Log(debug,"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.");
NaviKit.sys.custom_btn = true;
}else{//Rising edge trigger
Log(debug,"custom_btn status: released.");
NaviKit.sys.custom_btn = false;
}
}break;
}
}
void enter_standby_state(){
Log(info,"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();
}
//write "bios update flag" to bkp register, and reset system
void enter_isp_state()
{
@ -108,9 +123,9 @@ void enter_isp_state()
osDelay(10);
if(HAL_RTCEx_BKUPRead(&hrtc,ISP_BKP_DR) == BKP_DR_Jump_to_ISP)
{//write successful
TaskBeep(500,5);
TaskBeep(400,5);
Log(info,"Enter to EC update state.");
Log(info,"System will reboot ,then run ISP automatic.");
Log(info,"EC will reboot ,then run ISP automatic.");
HAL_NVIC_SystemReset();
}
else{
@ -121,16 +136,10 @@ void enter_isp_state()
//timeout:the time of wait
void enter_idle_state(uint16_t delay)
{
Log(info,"Enter to idle state");
Log(info,"Enter to idle state.");
TaskBeep(50,1);
PWR_Enable(SOM_PWR_EN ,false, delay);
PWR_Enable(SOC_USB3_HUB ,false, delay);
PWR_Enable(SOC_USB2_HUB ,false, delay);
PWR_Enable(SOC_USB3_HOST,false, delay);
PWR_Enable(SOC_USB3_GEC ,false, delay);
PWR_Enable(SOC_GE_SW ,false, delay);
PWR_Enable(SOM_SLEEP,true,delay);
PWR_Enable(USB3_Port4,false, delay);
PWR_Enable(USB3_Port3,false, delay);
@ -146,12 +155,23 @@ void enter_idle_state(uint16_t delay)
PWR_Enable(USB2_Port2,false, delay);
PWR_Enable(USB2_Port1,false, delay);
PWR_Enable(SOC_USB3_HUB ,false, delay);
PWR_Enable(SOC_USB2_HUB ,false, delay);
PWR_Enable(SOC_USB3_HOST,false, delay);
PWR_Enable(SOC_USB3_GEC ,false, delay);
PWR_Enable(SOC_GE_SW ,false, delay);
PWR_Enable(SYS_FAN1 ,false , delay);
PWR_Enable(SYS_FAN2 ,false , delay);
PWR_Enable(SYS_FAN3 ,false , delay);
PWR_Enable(PMB_PS_ON ,false , delay);
osDelay(5000);
TaskBeep(50,1);
PWR_Enable(SOM_PWR_EN ,false, delay);
PWR_Enable(PMB_PS_ON ,false , delay);
}
@ -161,14 +181,16 @@ void enter_run_state(uint16_t delay)
Log(info,"Enter to run state");
TaskBeep(200,1);
PWR_Enable(SOM_DFU ,false, delay);
PWR_Enable(PMB_PS_ON ,true, delay);
PWR_Enable(SOM_DFU ,false, delay);
PWR_Enable(SYS_FAN1 ,true , delay);
PWR_Enable(SYS_FAN2 ,true , delay);
PWR_Enable(SYS_FAN3 ,true , delay);
PWR_Enable(SOM_PWR_EN , true , delay);
PWR_Enable(SOC_USB3_HUB ,true , delay);
PWR_Enable(SOC_USB2_HUB ,true , delay);
PWR_Enable(SOC_USB3_HOST,true , delay);
@ -189,93 +211,84 @@ void enter_run_state(uint16_t delay)
PWR_Enable(USB3_Port3,true , delay);
PWR_Enable(USB3_Port4,true , delay);
PWR_Enable(SOM_PWR_EN , true , delay);
}
void enter_sleep_state(uint16_t delay)
{
Log(info,"Enter to sleep state");
Log(info,"Enter to sleep state.");
TaskBeep(50,1);
}
void enter_dfu_state(uint16_t delay)
{
Log(info,"Enter to DFU state");
TaskBeep(500,3);
PWR_Enable(SOM_DFU , true , delay);
Log(info,"Enter to DFU state.");
TaskBeep(500,3);
PWR_Enable(PMB_PS_ON , true , delay);
PWR_Enable(SOM_DFU , true , delay);
PWR_Enable(SYS_FAN1 , true , delay);
PWR_Enable(SYS_FAN2 , true , delay);
PWR_Enable(SYS_FAN3 , true , delay);
PWR_Enable(SOC_USB3_HUB , true , delay);
PWR_Enable(SOC_USB2_HUB , true , delay);
PWR_Enable(SOC_USB3_HOST , true , delay);
PWR_Enable(SOC_USB3_GEC , true , delay);
PWR_Enable(SOC_GE_SW , true , delay);
PWR_Enable(USB2_Port1 , true , delay);
PWR_Enable(USB2_Port2 , true , delay);
PWR_Enable(USB2_Port3 , true , delay);
PWR_Enable(USB2_Port4 , true , delay);
PWR_Enable(USB2_Port5 , true , delay);
PWR_Enable(USB2_Port6 , true , delay);
PWR_Enable(USB2_Port1 , true , delay);
PWR_Enable(USB2_Port1 , true , delay);
PWR_Enable(USB3_Port5,true , delay);
PWR_Enable(USB3_Port6,true , delay);
PWR_Enable(USB3_Port1,true , delay);
PWR_Enable(USB3_Port2,true , delay);
PWR_Enable(USB3_Port3,true , delay);
PWR_Enable(USB3_Port4,true , delay);
PWR_Enable(SOM_PWR_EN , true , delay);
//
// HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port ,SOM_FORCE_RECOVERY_Pin, GPIO_PIN_RESET); HAL_Delay(100);
// HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port ,SOM_SYS_RESET_Pin, GPIO_PIN_RESET); HAL_Delay(100);
//
// HAL_Delay(5000);
// HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port ,SOM_SYS_RESET_Pin, GPIO_PIN_SET); HAL_Delay(100);
// HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port ,SOM_FORCE_RECOVERY_Pin, GPIO_PIN_SET); HAL_Delay(100);
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);
}
//device power enable or disable
//delay: After executing the operation delay (ms)
void PWR_Enable(enum Device_t device,bool en,uint16_t delay){
switch (device){
case USB2_Port1: {HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, en); }break;
case USB2_Port2: {HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port,USB2_VBUS_CTL_2_Pin, en); }break;
case USB2_Port3: {HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port,USB2_VBUS_CTL_3_Pin, en); }break;
case USB2_Port4: {HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port,USB2_VBUS_CTL_4_Pin, en); }break;
case USB2_Port5: {HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port,USB2_VBUS_CTL_5_Pin, en); }break;
case USB2_Port6: {HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port,USB2_VBUS_CTL_6_Pin, en); }break;
case USB3_Port1: {HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port,USB3_VBUS_CTL_1_Pin, en); }break;
case USB3_Port2: {HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port,USB3_VBUS_CTL_2_Pin, en); }break;
case USB3_Port3: {HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port,USB3_VBUS_CTL_3_Pin, en); }break;
case USB3_Port4: {HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port,USB3_VBUS_CTL_4_Pin, en); }break;
case USB3_Port5: {HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port,USB3_VBUS_CTL_5_Pin, en); }break;
case USB3_Port6: {HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port,USB3_VBUS_CTL_6_Pin, en); }break;
case SOC_USB2_HUB: {HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, en); }break;
case SOC_USB3_HUB: {HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, en); }break;
case SOC_USB3_HOST: {HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, en); }break;
case SOC_USB3_GEC: {HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, en); }break;
case SOC_GE_SW: {HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port,SOC_GE_SW_PWR_CTL_Pin, en); }break;
case SYS_FAN1: {HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port,SYS_FAN_CTL_1_Pin, en); }break;
case SYS_FAN2: {HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port,SYS_FAN_CTL_2_Pin, en); }break;
case SYS_FAN3: {HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin, en); }break;
case SYS_RUN_LED: {HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin, !en); }break;
case SYS_PWR_LED: {HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin, !en); }break;
case SOM_PWR_EN: {HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port,SOM_POWER_EN_Pin, en); }break;
case SOM_DFU: {HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin, !en); }break;
case SOM_RESET: {HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_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;
case USB2_Port1: {HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port, USB2_VBUS_CTL_1_Pin, en); }break;
case USB2_Port2: {HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port, USB2_VBUS_CTL_2_Pin, en); }break;
case USB2_Port3: {HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port, USB2_VBUS_CTL_3_Pin, en); }break;
case USB2_Port4: {HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port, USB2_VBUS_CTL_4_Pin, en); }break;
case USB2_Port5: {HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port, USB2_VBUS_CTL_5_Pin, en); }break;
case USB2_Port6: {HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port, USB2_VBUS_CTL_6_Pin, en); }break;
case USB3_Port1: {HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port, USB3_VBUS_CTL_1_Pin, en); }break;
case USB3_Port2: {HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port, USB3_VBUS_CTL_2_Pin, en); }break;
case USB3_Port3: {HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port, USB3_VBUS_CTL_3_Pin, en); }break;
case USB3_Port4: {HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port, USB3_VBUS_CTL_4_Pin, en); }break;
case USB3_Port5: {HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port, USB3_VBUS_CTL_5_Pin, en); }break;
case USB3_Port6: {HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port, USB3_VBUS_CTL_6_Pin, en); }break;
case SOC_USB2_HUB: {HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, en); }break;
case SOC_USB3_HUB: {HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, en); }break;
case SOC_USB3_HOST: {HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, en); }break;
case SOC_USB3_GEC: {HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, en); }break;
case SOC_GE_SW: {HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port, SOC_GE_SW_PWR_CTL_Pin, en); }break;
case SYS_FAN1: {HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port, SYS_FAN_CTL_1_Pin, en); }break;
case SYS_FAN2: {HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port, SYS_FAN_CTL_2_Pin, en); }break;
case SYS_FAN3: {HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port, SYS_FAN_CTL_3_Pin, en); }break;
case SYS_RUN_LED: {HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port, SYS_RUN_LED_CTL_Pin, !en); }break;
case SYS_PWR_LED: {HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port, SYS_POWER_LED_CTL_Pin, !en); }break;
case SOM_PWR_EN: {HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port, SOM_POWER_EN_Pin, en); }break;
case SOM_DFU: {HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin, !en); }break;
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;
}
osDelay(delay);
}
@ -309,8 +322,11 @@ bool PWR_Status(enum Device_t device){
case SOM_PWR_EN: {sta = HAL_GPIO_ReadPin(SOM_POWER_EN_GPIO_Port,SOM_POWER_EN_Pin); }break;
case SOM_DFU: {sta = !HAL_GPIO_ReadPin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin); }break;
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;
}
return sta;
}

View File

@ -6,7 +6,7 @@
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
@ -55,12 +55,6 @@ void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
__HAL_RCC_BKP_CLK_ENABLE();
/* RTC clock enable */
__HAL_RCC_RTC_ENABLE();
/* RTC interrupt Init */
HAL_NVIC_SetPriority(RTC_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(RTC_IRQn);
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */

View File

@ -9,7 +9,7 @@ ADC1.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_4
ADC1.Channel-4\#ChannelRegularConversion=ADC_CHANNEL_5
ADC1.Channel-5\#ChannelRegularConversion=ADC_CHANNEL_6
ADC1.Channel-6\#ChannelRegularConversion=ADC_CHANNEL_7
ADC1.ContinuousConvMode=DISABLE
ADC1.ContinuousConvMode=ENABLE
ADC1.EnableAnalogWatchDog=true
ADC1.ExternalTrigConv=ADC_SOFTWARE_START
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,ContinuousConvMode,Rank-1\#ChannelRegularConversion,Channel-1\#ChannelRegularConversion,SamplingTime-1\#ChannelRegularConversion,Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion,Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,NbrOfConversion,Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,Rank-5\#ChannelRegularConversion,Channel-5\#ChannelRegularConversion,SamplingTime-5\#ChannelRegularConversion,ExternalTrigConv,master,EnableAnalogWatchDog,Rank-6\#ChannelRegularConversion,Channel-6\#ChannelRegularConversion,SamplingTime-6\#ChannelRegularConversion,WatchdogMode,AWD1ITMode,WatchdogChannel,AWD1HighThreshold,AWD1LowThreshold
@ -65,7 +65,6 @@ Dma.ADC1.0.Priority=DMA_PRIORITY_LOW
Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
Dma.Request0=ADC1
Dma.RequestsNb=1
FREERTOS.Events01=
FREERTOS.FootprintOK=true
FREERTOS.HEAP_NUMBER=4
FREERTOS.INCLUDE_pcTaskGetTaskName=1
@ -75,9 +74,8 @@ FREERTOS.INCLUDE_xSemaphoreGetMutexHolder=1
FREERTOS.INCLUDE_xTaskAbortDelay=1
FREERTOS.INCLUDE_xTaskGetCurrentTaskHandle=1
FREERTOS.INCLUDE_xTaskGetHandle=1
FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configUSE_TICKLESS_IDLE,INCLUDE_xTaskGetCurrentTaskHandle,INCLUDE_xTaskGetHandle,configUSE_APPLICATION_TASK_TAG,FootprintOK,configUSE_IDLE_HOOK,configUSE_TICK_HOOK,configUSE_MALLOC_FAILED_HOOK,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS,configUSE_TRACE_FACILITY,HEAP_NUMBER,configTOTAL_HEAP_SIZE,configCHECK_FOR_STACK_OVERFLOW,configUSE_TASK_NOTIFICATIONS,INCLUDE_xTaskAbortDelay,INCLUDE_xEventGroupSetBitFromISR,INCLUDE_xSemaphoreGetMutexHolder,INCLUDE_pcTaskGetTaskName,INCLUDE_vTaskCleanUpResources,Events01,Timers01
FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configUSE_TICKLESS_IDLE,INCLUDE_xTaskGetCurrentTaskHandle,INCLUDE_xTaskGetHandle,configUSE_APPLICATION_TASK_TAG,FootprintOK,configUSE_IDLE_HOOK,configUSE_TICK_HOOK,configUSE_MALLOC_FAILED_HOOK,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS,configUSE_TRACE_FACILITY,HEAP_NUMBER,configTOTAL_HEAP_SIZE,configCHECK_FOR_STACK_OVERFLOW,configUSE_TASK_NOTIFICATIONS,INCLUDE_xTaskAbortDelay,INCLUDE_xEventGroupSetBitFromISR,INCLUDE_xSemaphoreGetMutexHolder,INCLUDE_pcTaskGetTaskName,INCLUDE_vTaskCleanUpResources
FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;LedBlinkTask,8,128,StartLedBlinkTask,Default,NULL,Dynamic,NULL,NULL;CoulombRead,8,128,StartCoulombRead,Default,NULL,Dynamic,NULL,NULL;PowerMonitTask,8,128,StartPowerMonitTask,Default,NULL,Dynamic,NULL,NULL;EventDetect,8,128,StartEventDetect,Default,NULL,Dynamic,NULL,NULL
FREERTOS.Timers01=PwrBtnTimer,PwrBtnTimerCallback,osTimerOnce,Default,NULL,Dynamic,NULL;CustBtnTimer,CustBtnTimerCallback,osTimerOnce,Default,NULL,Dynamic,NULL
FREERTOS.configCHECK_FOR_STACK_OVERFLOW=1
FREERTOS.configGENERATE_RUN_TIME_STATS=1
FREERTOS.configMAX_TASK_NAME_LEN=32
@ -196,9 +194,10 @@ NVIC.ADC1_2_IRQn=true\:5\:0\:false\:true\:true\:8\:true\:true\:true
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.DMA1_Channel1_IRQn=true\:5\:0\:false\:true\:true\:9\:true\:false\:true
NVIC.DebugMonitor_IRQn=true\:0\:0\:true\:false\:true\:false\:false\:false
NVIC.EXTI0_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true
NVIC.EXTI3_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true
NVIC.EXTI9_5_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true
NVIC.EXTI0_IRQn=true\:5\:0\:false\:true\:true\:11\:true\:true\:true
NVIC.EXTI3_IRQn=true\:5\:0\:false\:true\:true\:12\:true\:true\:true
NVIC.EXTI4_IRQn=true\:5\:0\:false\:true\:true\:16\:true\:true\:true
NVIC.EXTI9_5_IRQn=true\:5\:0\:true\:true\:true\:13\:true\:true\:true
NVIC.FLASH_IRQn=true\:5\:0\:false\:true\:true\:2\:true\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
@ -211,8 +210,8 @@ NVIC.PVD_IRQn=true\:5\:0\:true\:true\:true\:1\:false\:true\:true
NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.RCC_IRQn=true\:5\:0\:false\:true\:true\:3\:true\:true\:false
NVIC.RTC_Alarm_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true
NVIC.RTC_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true
NVIC.RTC_Alarm_IRQn=true\:5\:0\:false\:true\:true\:14\:true\:true\:true
NVIC.RTC_IRQn=true\:5\:0\:false\:true\:true\:15\:true\:true\:true
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false
NVIC.SavedPendsvIrqHandlerGenerated=true
NVIC.SavedSvcallIrqHandlerGenerated=true
@ -314,13 +313,14 @@ PB3.GPIOParameters=GPIO_Label
PB3.GPIO_Label=SYS_SWO
PB3.Mode=Trace_Asynchronous_SW
PB3.Signal=SYS_TRACESWO
PB4.GPIOParameters=PinState,GPIO_Label
PB4.GPIO_Label=SOM_SYS_RESET
PB4.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
PB4.GPIO_Label=SOM_MOD_SLEEP
PB4.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING
PB4.GPIO_PuPd=GPIO_PULLUP
PB4.Locked=true
PB4.PinState=GPIO_PIN_SET
PB4.Signal=GPIO_Output
PB4.Signal=GPXTI4
PB5.GPIOParameters=GPIO_Label
PB5.GPIO_Label=SOM_MOD_SLEEP
PB5.GPIO_Label=SOM_SYS_RESET
PB5.Locked=true
PB5.Signal=GPIO_Input
PB8.GPIOParameters=GPIO_Label
@ -564,16 +564,16 @@ ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-true,4-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_IWDG_Init-IWDG-false-HAL-true,7-MX_UART4_Init-UART4-false-HAL-true,8-MX_ADC1_Init-ADC1-false-HAL-true,9-MX_USART1_UART_Init-USART1-false-HAL-true,10-MX_RTC_Init-RTC-false-HAL-true
RCC.ADCFreqValue=281250
RCC.ADCFreqValue=140625
RCC.ADCPresc=RCC_ADCPCLK2_DIV8
RCC.AHBCLKDivider=RCC_SYSCLK_DIV4
RCC.AHBFreq_Value=18000000
RCC.APB1CLKDivider=RCC_HCLK_DIV8
RCC.APB1Freq_Value=2250000
RCC.APB1TimFreq_Value=4500000
RCC.APB2CLKDivider=RCC_HCLK_DIV8
RCC.APB2Freq_Value=2250000
RCC.APB2TimFreq_Value=4500000
RCC.APB1CLKDivider=RCC_HCLK_DIV16
RCC.APB1Freq_Value=1125000
RCC.APB1TimFreq_Value=2250000
RCC.APB2CLKDivider=RCC_HCLK_DIV16
RCC.APB2Freq_Value=1125000
RCC.APB2TimFreq_Value=2250000
RCC.FCLKCortexFreq_Value=18000000
RCC.FamilyName=M
RCC.HCLKFreq_Value=18000000
@ -610,6 +610,8 @@ SH.GPXTI0.0=GPIO_EXTI0
SH.GPXTI0.ConfNb=1
SH.GPXTI3.0=GPIO_EXTI3
SH.GPXTI3.ConfNb=1
SH.GPXTI4.0=GPIO_EXTI4
SH.GPXTI4.ConfNb=1
SH.GPXTI5.0=GPIO_EXTI5
SH.GPXTI5.ConfNb=1
SH.GPXTI6.0=GPIO_EXTI6
@ -618,11 +620,12 @@ SH.GPXTI7.0=GPIO_EXTI7
SH.GPXTI7.ConfNb=1
SH.GPXTI8.0=GPIO_EXTI8
SH.GPXTI8.ConfNb=1
UART4.BaudRate=115200
UART4.BaudRate=56000
UART4.IPParameters=VirtualMode,BaudRate
UART4.IPParametersWithoutCheck=BaudRate
UART4.VirtualMode=Asynchronous
USART1.IPParameters=VirtualMode,WordLength
USART1.BaudRate=56000
USART1.IPParameters=VirtualMode,WordLength,BaudRate
USART1.VirtualMode=VM_ASYNC
USART1.WordLength=WORDLENGTH_8B
USB_DEVICE.CLASS_NAME_FS=CDC
@ -647,4 +650,4 @@ VP_SYS_VS_tim1.Signal=SYS_VS_tim1
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS
board=custom
isbadioc=false
isbadioc=true