feat: add delayed uart and runtime mac configuration

This commit is contained in:
2026-04-29 04:35:48 +08:00
parent c9ece65182
commit ac0c464910
7 changed files with 93 additions and 15 deletions
+1
View File
@@ -47,6 +47,7 @@ void MX_USART2_UART_Init(void);
void MX_USART3_UART_Init(void);
/* USER CODE BEGIN Prototypes */
void USART_SetConfiguredBaudrates(uint32_t usart2_baudrate, uint32_t usart3_baudrate);
/* USER CODE END Prototypes */
+9 -2
View File
@@ -68,6 +68,7 @@ void MX_FREERTOS_Init(void);
/* USER CODE BEGIN PFP */
static void CH390_HardwareReset(void);
static void LED_Init(void);
static void ApplyConfiguredUartBaudrates(void);
void Debug_TrapWithRttHint(const char *tag);
/* USER CODE END PFP */
@@ -109,6 +110,12 @@ void LED_Toggle(void)
HAL_GPIO_TogglePin(LED_PORT, LED_PIN);
}
static void ApplyConfiguredUartBaudrates(void)
{
USART_SetConfiguredBaudrates(config_get_uart_baudrate(LINK_UART_U0),
config_get_uart_baudrate(LINK_UART_U1));
}
/* USER CODE END 0 */
/**
@@ -143,6 +150,8 @@ int main(void)
MX_GPIO_Init();
MX_DMA_Init();
MX_USART1_UART_Init();
config_init();
ApplyConfiguredUartBaudrates();
MX_USART2_UART_Init();
MX_USART3_UART_Init();
MX_SPI1_Init();
@@ -155,8 +164,6 @@ int main(void)
/* CH390 硬件复位 */
CH390_HardwareReset();
/* Initialize configuration from Flash (fallback to defaults on invalid data) */
config_init();
debug_log_boot("config-ready");
/* USER CODE END 2 */
+11 -2
View File
@@ -22,6 +22,9 @@
/* USER CODE BEGIN 0 */
static uint32_t g_usart2_baudrate = 115200u;
static uint32_t g_usart3_baudrate = 115200u;
/* USER CODE END 0 */
UART_HandleTypeDef huart1;
@@ -76,7 +79,7 @@ void MX_USART2_UART_Init(void)
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.BaudRate = g_usart2_baudrate;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
@@ -105,7 +108,7 @@ void MX_USART3_UART_Init(void)
/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.BaudRate = g_usart3_baudrate;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
@@ -396,4 +399,10 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
/* USER CODE BEGIN 1 */
void USART_SetConfiguredBaudrates(uint32_t usart2_baudrate, uint32_t usart3_baudrate)
{
g_usart2_baudrate = usart2_baudrate;
g_usart3_baudrate = usart3_baudrate;
}
/* USER CODE END 1 */