Wakeup and Standby systems

This commit is contained in:
2024-05-18 02:11:54 +02:00
parent 467d7c4de9
commit 3869b31b03
4 changed files with 173 additions and 32 deletions

View File

@@ -38,6 +38,8 @@
/* USER CODE BEGIN Includes */
#include "ulog.h"
#include "stdio.h"
#include "BSP_POWER.h"
#include "BSP_GPIO.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -81,7 +83,7 @@ void ULOG_SendLPUART(ulog_level_t level, char *msg);
* @retval int
*/
int main(void)
{
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
@@ -108,7 +110,7 @@ int main(void)
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
BSP_POWER_WakeUp();
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
@@ -129,40 +131,18 @@ int main(void)
MX_TIM2_Init();
MX_LPTIM4_Init();
/* USER CODE BEGIN 2 */
ULOG_INIT();
ULOG_SUBSCRIBE(ULOG_SendLPUART,ULOG_DEBUG_LEVEL);
GPIO_PinState K15 = HAL_GPIO_ReadPin(K15_Detect_GPIO_Port, K15_Detect_Pin);
while (K15 == GPIO_PIN_RESET)
{
K15 = HAL_GPIO_ReadPin(K15_Detect_GPIO_Port, K15_Detect_Pin);
ULOG_DEBUG("Wait for K15 Signal Wait Wait Wait");
HAL_Delay(100);
}
GPIO_PinState HL = HAL_GPIO_ReadPin(Headlight_Detect_GPIO_Port, Headlight_Detect_Pin);
while (HL == GPIO_PIN_RESET)
{
HL = HAL_GPIO_ReadPin(Headlight_Detect_GPIO_Port, Headlight_Detect_Pin);
ULOG_DEBUG("Wait for K15 Signal Wait Wait Wait");
HAL_Delay(100);
}
BSP_GPIO_PeriperalsOn();
BSP_POWER_Init();
ULOG_INIT();
ULOG_SUBSCRIBE(ULOG_SendLPUART,ULOG_DEBUG_LEVEL);
ULOG_DEBUG("Setup Logger");
HAL_GPIO_WritePin(Periph_Power_GPIO_Port,Periph_Power_Pin,GPIO_PIN_RESET);
HAL_GPIO_WritePin(CLS_POWER_GPIO_Port, CLS_POWER_Pin, GPIO_PIN_SET);
ULOG_DEBUG("Enable Power on CLS and Periph");
gCLS_DEVICE_ADDRESS = 0x11;
gCLS_DEVICE_ADDRESS = 0x11; // Address is set to master
ULOG_DEBUG("Setting Global CLS address to 0b10001");
ULOG_DEBUG("Init Kernel and start schedule");
/* USER CODE END 2 */
/* Init scheduler */
osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */
MX_FREERTOS_Init();
@@ -364,6 +344,13 @@ void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
ULOG_ERROR("Error Handler");
osThreadId_t error_thread = osThreadGetId();
if(error_thread != NULL) {
const char * osThreadGetName(error_thread);
ULOG_ERROR("Error in thread: %s", osThreadGetName(error_thread));
}
__disable_irq();
while (1)
{