refactor: 精简R8裸机工程并补强调试链路
This commit is contained in:
+14
-4
@@ -52,6 +52,8 @@ static int apply_uart_config(uart_channel_t channel)
|
||||
{
|
||||
uart_channel_ctx_t *ctx = &g_channels[channel];
|
||||
UART_HandleTypeDef *huart = ctx->huart;
|
||||
uint32_t word_length;
|
||||
uint32_t parity;
|
||||
|
||||
if (huart == NULL) {
|
||||
return -1;
|
||||
@@ -63,21 +65,29 @@ static int apply_uart_config(uart_channel_t channel)
|
||||
}
|
||||
|
||||
huart->Init.BaudRate = ctx->config.baudrate;
|
||||
huart->Init.WordLength = (ctx->config.data_bits == 9u) ? UART_WORDLENGTH_9B : UART_WORDLENGTH_8B;
|
||||
huart->Init.StopBits = (ctx->config.stop_bits == 2u) ? UART_STOPBITS_2 : UART_STOPBITS_1;
|
||||
|
||||
switch (ctx->config.parity) {
|
||||
case 1:
|
||||
huart->Init.Parity = UART_PARITY_ODD;
|
||||
parity = UART_PARITY_ODD;
|
||||
break;
|
||||
case 2:
|
||||
huart->Init.Parity = UART_PARITY_EVEN;
|
||||
parity = UART_PARITY_EVEN;
|
||||
break;
|
||||
default:
|
||||
huart->Init.Parity = UART_PARITY_NONE;
|
||||
parity = UART_PARITY_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (parity == UART_PARITY_NONE) {
|
||||
word_length = (ctx->config.data_bits == 9u) ? UART_WORDLENGTH_9B : UART_WORDLENGTH_8B;
|
||||
} else {
|
||||
word_length = (ctx->config.data_bits >= 8u) ? UART_WORDLENGTH_9B : UART_WORDLENGTH_8B;
|
||||
}
|
||||
|
||||
huart->Init.WordLength = word_length;
|
||||
huart->Init.Parity = parity;
|
||||
|
||||
return (HAL_UART_Init(huart) == HAL_OK) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user