refactor: 精简R8裸机工程并补强调试链路
This commit is contained in:
@@ -43,6 +43,13 @@ static err_t tcp_client_on_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
||||
}
|
||||
|
||||
if (p == NULL) {
|
||||
tcp_arg(pcb, NULL);
|
||||
tcp_recv(pcb, NULL);
|
||||
tcp_sent(pcb, NULL);
|
||||
tcp_err(pcb, NULL);
|
||||
if (tcp_close(pcb) != ERR_OK) {
|
||||
tcp_abort(pcb);
|
||||
}
|
||||
ctx->pcb = NULL;
|
||||
ctx->status.state = TCP_CLIENT_STATE_DISCONNECTED;
|
||||
ctx->next_retry_ms = HAL_GetTick() + ctx->config.reconnect_interval_ms;
|
||||
|
||||
@@ -40,6 +40,13 @@ static err_t tcp_server_on_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
||||
}
|
||||
|
||||
if (p == NULL) {
|
||||
tcp_arg(pcb, NULL);
|
||||
tcp_recv(pcb, NULL);
|
||||
tcp_sent(pcb, NULL);
|
||||
tcp_err(pcb, NULL);
|
||||
if (tcp_close(pcb) != ERR_OK) {
|
||||
tcp_abort(pcb);
|
||||
}
|
||||
ctx->client_pcb = NULL;
|
||||
ctx->status.state = TCP_SERVER_STATE_LISTENING;
|
||||
return ERR_OK;
|
||||
|
||||
+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