fix: improve boot fault visibility and defer watchdog start

This commit is contained in:
2026-04-20 08:12:06 +08:00
parent 77da670f5c
commit c8f27e21f1
7 changed files with 54 additions and 9 deletions
+13
View File
@@ -75,6 +75,19 @@ void debug_log_fault(const char *tag)
debug_log_printf("[FAULT] %s\r\n", (tag != NULL) ? tag : "(null)");
}
void debug_log_fault_context(const char *tag, const char *file, int line)
{
debug_log_printf("[FAULT] %s file=%s line=%d free=%lu min=%lu seq=%lu drop=%lu last_drop=%lu\r\n",
(tag != NULL) ? tag : "(null)",
(file != NULL) ? file : "(null)",
line,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize(),
(unsigned long)g_rtt_log_seq,
(unsigned long)g_rtt_log_drop_count,
(unsigned long)g_rtt_log_last_drop_seq);
}
void debug_log_runtime_snapshot(void)
{
UBaseType_t default_hwm;
+11 -1
View File
@@ -89,13 +89,23 @@ static void StartDefaultTask(void *argument)
{
TickType_t last_snapshot = xTaskGetTickCount();
BaseType_t alive_logged = pdFALSE;
BaseType_t iwdg_ready = pdFALSE;
(void)argument;
debug_log_boot("default-task");
if (MX_IWDG_Init() == HAL_OK) {
debug_log_write("[BOOT] iwdg-started\r\n");
iwdg_ready = pdTRUE;
} else {
debug_log_write("[BOOT] iwdg-init-fail\r\n");
}
for (;;) {
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_IWDG_Refresh(&hiwdg);
if (iwdg_ready == pdTRUE) {
HAL_IWDG_Refresh(&hiwdg);
}
if (alive_logged == pdFALSE) {
debug_log_write("[RTOS] alive\r\n");
alive_logged = pdTRUE;
+3 -3
View File
@@ -27,7 +27,7 @@
IWDG_HandleTypeDef hiwdg;
/* IWDG init function */
void MX_IWDG_Init(void)
HAL_StatusTypeDef MX_IWDG_Init(void)
{
/* USER CODE BEGIN IWDG_Init 0 */
@@ -42,12 +42,12 @@ void MX_IWDG_Init(void)
hiwdg.Init.Reload = 4095;
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
{
Error_Handler();
return HAL_ERROR;
}
/* USER CODE BEGIN IWDG_Init 2 */
/* USER CODE END IWDG_Init 2 */
return HAL_OK;
}
/* USER CODE BEGIN 1 */
+23 -3
View File
@@ -142,7 +142,6 @@ int main(void)
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_IWDG_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_USART3_UART_Init();
@@ -231,7 +230,28 @@ void SystemClock_Config(void)
*/
void Debug_TrapWithRttHint(const char *tag)
{
debug_log_fault(tag);
debug_log_fault_context(tag, __FILE__, __LINE__);
}
void vApplicationMallocFailedHook(void)
{
debug_log_fault_context("malloc-failed", __FILE__, __LINE__);
__disable_irq();
for (;;)
{
}
}
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
{
debug_log_printf("[FAULT] stack-overflow task=%s\r\n",
(pcTaskName != NULL) ? pcTaskName : "(null)");
debug_log_fault_context("stack-overflow", __FILE__, __LINE__);
(void)xTask;
__disable_irq();
for (;;)
{
}
}
/* USER CODE END 4 */
@@ -244,7 +264,7 @@ void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
debug_log_fault("error-handler");
debug_log_fault_context("error-handler", __FILE__, __LINE__);
__disable_irq();
while (1)
{