feat: save stable CH390 bridge baseline
This commit is contained in:
+299
-213
@@ -4,16 +4,6 @@
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -34,7 +24,6 @@
|
||||
#include "CH390_Interface.h"
|
||||
#include "SEGGER_RTT.h"
|
||||
#include "config.h"
|
||||
#include "flash_param.h"
|
||||
#include "ethernetif.h"
|
||||
#include "ch390_runtime.h"
|
||||
#include "lwip/init.h"
|
||||
@@ -44,71 +33,22 @@
|
||||
#include "uart_trans.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
/* LED 指示灯 */
|
||||
#define LED_PIN GPIO_PIN_13
|
||||
#define LED_PORT GPIOC
|
||||
#define APP_ROUTE_BUFFER_SIZE 256u
|
||||
#define STACK_GUARD_WORD 0xA5A5A5A5u
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
static volatile uint16_t g_led_blink_ticks = 0;
|
||||
static uint8_t g_clock_fallback_to_hsi = 0u;
|
||||
volatile uint8_t g_uart1_rx_probe_byte = 0u;
|
||||
|
||||
typedef struct {
|
||||
uint8_t data[256];
|
||||
uint16_t len;
|
||||
} tcp_bridge_buffer_t;
|
||||
|
||||
static tcp_bridge_buffer_t g_server_to_client;
|
||||
static tcp_bridge_buffer_t g_client_to_server;
|
||||
|
||||
static void App_ForwardTcpPair(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if ((g_server_to_client.len == 0u) && tcp_server_is_connected()) {
|
||||
rc = tcp_server_recv(g_server_to_client.data, sizeof(g_server_to_client.data), 0u);
|
||||
if (rc > 0) {
|
||||
g_server_to_client.len = (uint16_t)rc;
|
||||
}
|
||||
}
|
||||
|
||||
if ((g_server_to_client.len != 0u) && tcp_client_is_connected()) {
|
||||
rc = tcp_client_send(g_server_to_client.data, g_server_to_client.len);
|
||||
if (rc == (int)g_server_to_client.len) {
|
||||
g_server_to_client.len = 0u;
|
||||
}
|
||||
}
|
||||
|
||||
if ((g_client_to_server.len == 0u) && tcp_client_is_connected()) {
|
||||
rc = tcp_client_recv(g_client_to_server.data, sizeof(g_client_to_server.data), 0u);
|
||||
if (rc > 0) {
|
||||
g_client_to_server.len = (uint16_t)rc;
|
||||
}
|
||||
}
|
||||
|
||||
if ((g_client_to_server.len != 0u) && tcp_server_is_connected()) {
|
||||
rc = tcp_server_send(g_client_to_server.data, g_client_to_server.len);
|
||||
if (rc == (int)g_client_to_server.len) {
|
||||
g_client_to_server.len = 0u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t g_stack_guard_reported = 0u;
|
||||
static uint8_t g_mux_response_frame[272];
|
||||
static uint8_t g_links_started = 0u;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -120,20 +60,42 @@ static void BootDiag_ReportCh390(void);
|
||||
static void App_PollUart1ConfigRx(void);
|
||||
static void App_Init(void);
|
||||
static void App_Poll(void);
|
||||
static void App_ConfigureLinks(const device_config_t *cfg);
|
||||
static void App_RouteRawUartTraffic(void);
|
||||
static void App_RouteMuxUartTraffic(void);
|
||||
static void App_RouteTcpTraffic(void);
|
||||
static void StackGuard_Init(void);
|
||||
static void StackGuard_Check(void);
|
||||
static void App_SendToUart(uint8_t uart_index, uint8_t src_id, uint8_t dst_mask, const uint8_t *data, uint16_t len);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
extern uint32_t Stack_Mem[];
|
||||
|
||||
/**
|
||||
* @brief LED 初始化(点亮表示系统启动)
|
||||
*/
|
||||
static void LED_Init(void)
|
||||
{
|
||||
/* LED 灭(PC13 高电平灭,低电平亮) */
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
static void StackGuard_Init(void)
|
||||
{
|
||||
Stack_Mem[0] = STACK_GUARD_WORD;
|
||||
g_stack_guard_reported = 0u;
|
||||
}
|
||||
|
||||
static void StackGuard_Check(void)
|
||||
{
|
||||
if (Stack_Mem[0] != STACK_GUARD_WORD) {
|
||||
if (g_stack_guard_reported == 0u) {
|
||||
g_stack_guard_reported = 1u;
|
||||
SEGGER_RTT_WriteString(0, "ERROR: Main stack guard overwritten\r\n");
|
||||
}
|
||||
__disable_irq();
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
||||
static void LED_StartBlink(void)
|
||||
{
|
||||
if (HAL_TIM_Base_Start_IT(&htim4) != HAL_OK) {
|
||||
@@ -141,9 +103,6 @@ static void LED_StartBlink(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LED 闪烁(用于指示系统运行状态)
|
||||
*/
|
||||
void LED_Toggle(void)
|
||||
{
|
||||
HAL_GPIO_TogglePin(LED_PORT, LED_PIN);
|
||||
@@ -177,13 +136,11 @@ static void BootDiag_ReportCh390(void)
|
||||
diag.link_up,
|
||||
mac_hw[0], mac_hw[1], mac_hw[2], mac_hw[3], mac_hw[4], mac_hw[5]);
|
||||
SEGGER_RTT_printf(0,
|
||||
"NET cfg IP=%u.%u.%u.%u MASK=%u.%u.%u.%u GW=%u.%u.%u.%u SrvPort=%u Cli=%u.%u.%u.%u:%u\r\n",
|
||||
cfg->ip[0], cfg->ip[1], cfg->ip[2], cfg->ip[3],
|
||||
cfg->mask[0], cfg->mask[1], cfg->mask[2], cfg->mask[3],
|
||||
cfg->gw[0], cfg->gw[1], cfg->gw[2], cfg->gw[3],
|
||||
cfg->server_port,
|
||||
cfg->remote_ip[0], cfg->remote_ip[1], cfg->remote_ip[2], cfg->remote_ip[3],
|
||||
cfg->remote_port);
|
||||
"NET cfg IP=%u.%u.%u.%u MASK=%u.%u.%u.%u GW=%u.%u.%u.%u MUX=%u\r\n",
|
||||
cfg->net.ip[0], cfg->net.ip[1], cfg->net.ip[2], cfg->net.ip[3],
|
||||
cfg->net.mask[0], cfg->net.mask[1], cfg->net.mask[2], cfg->net.mask[3],
|
||||
cfg->net.gw[0], cfg->net.gw[1], cfg->net.gw[2], cfg->net.gw[3],
|
||||
cfg->mux_mode);
|
||||
}
|
||||
|
||||
static void App_PollUart1ConfigRx(void)
|
||||
@@ -194,97 +151,302 @@ static void App_PollUart1ConfigRx(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void App_ConfigureLinks(const device_config_t *cfg)
|
||||
{
|
||||
tcp_server_instance_config_t server_cfg;
|
||||
tcp_client_instance_config_t client_cfg;
|
||||
|
||||
(void)tcp_server_init_all();
|
||||
(void)tcp_client_init_all();
|
||||
|
||||
server_cfg.enabled = (cfg->links[CONFIG_LINK_S1].enabled != 0u);
|
||||
server_cfg.port = cfg->links[CONFIG_LINK_S1].local_port;
|
||||
(void)tcp_server_config(0u, &server_cfg);
|
||||
|
||||
server_cfg.enabled = (cfg->links[CONFIG_LINK_S2].enabled != 0u);
|
||||
server_cfg.port = cfg->links[CONFIG_LINK_S2].local_port;
|
||||
(void)tcp_server_config(1u, &server_cfg);
|
||||
|
||||
memcpy(client_cfg.remote_ip, cfg->links[CONFIG_LINK_C1].remote_ip, sizeof(client_cfg.remote_ip));
|
||||
client_cfg.local_port = cfg->links[CONFIG_LINK_C1].local_port;
|
||||
client_cfg.remote_port = cfg->links[CONFIG_LINK_C1].remote_port;
|
||||
client_cfg.reconnect_interval_ms = TCP_CLIENT_RECONNECT_DELAY_MS;
|
||||
client_cfg.enabled = (cfg->links[CONFIG_LINK_C1].enabled != 0u);
|
||||
client_cfg.auto_reconnect = true;
|
||||
(void)tcp_client_config(0u, &client_cfg);
|
||||
|
||||
memcpy(client_cfg.remote_ip, cfg->links[CONFIG_LINK_C2].remote_ip, sizeof(client_cfg.remote_ip));
|
||||
client_cfg.local_port = cfg->links[CONFIG_LINK_C2].local_port;
|
||||
client_cfg.remote_port = cfg->links[CONFIG_LINK_C2].remote_port;
|
||||
client_cfg.enabled = (cfg->links[CONFIG_LINK_C2].enabled != 0u);
|
||||
(void)tcp_client_config(1u, &client_cfg);
|
||||
}
|
||||
|
||||
static void App_StartLinksIfNeeded(void)
|
||||
{
|
||||
if ((g_links_started != 0u) || !netif_is_link_up(&ch390_netif)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < TCP_SERVER_INSTANCE_COUNT; ++i) {
|
||||
(void)tcp_server_start(i);
|
||||
}
|
||||
for (uint8_t i = 0; i < TCP_CLIENT_INSTANCE_COUNT; ++i) {
|
||||
(void)tcp_client_connect(i);
|
||||
}
|
||||
|
||||
g_links_started = 1u;
|
||||
SEGGER_RTT_WriteString(0, "NET links started after link-up\r\n");
|
||||
}
|
||||
|
||||
static void App_StopLinksIfNeeded(void)
|
||||
{
|
||||
if (netif_is_link_up(&ch390_netif)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_links_started != 0u) {
|
||||
for (uint8_t i = 0; i < TCP_CLIENT_INSTANCE_COUNT; ++i) {
|
||||
(void)tcp_client_disconnect(i);
|
||||
}
|
||||
for (uint8_t i = 0; i < TCP_SERVER_INSTANCE_COUNT; ++i) {
|
||||
(void)tcp_server_stop(i);
|
||||
}
|
||||
SEGGER_RTT_WriteString(0, "NET links stopped after link-down\r\n");
|
||||
}
|
||||
|
||||
g_links_started = 0u;
|
||||
}
|
||||
|
||||
static void App_Init(void)
|
||||
{
|
||||
device_config_t *cfg_mut;
|
||||
const device_config_t *cfg;
|
||||
ip4_addr_t ipaddr;
|
||||
ip4_addr_t netmask;
|
||||
ip4_addr_t gateway;
|
||||
uart_config_t uart_cfg;
|
||||
tcp_server_config_t server_cfg;
|
||||
tcp_client_config_t client_cfg;
|
||||
|
||||
config_init();
|
||||
cfg_mut = config_get_mutable();
|
||||
cfg_mut->dhcp_enable = 0u;
|
||||
cfg_mut->ip[0] = 192u;
|
||||
cfg_mut->ip[1] = 168u;
|
||||
cfg_mut->ip[2] = 31u;
|
||||
cfg_mut->ip[3] = 100u;
|
||||
cfg_mut->mask[0] = 255u;
|
||||
cfg_mut->mask[1] = 255u;
|
||||
cfg_mut->mask[2] = 255u;
|
||||
cfg_mut->mask[3] = 0u;
|
||||
cfg_mut->gw[0] = 192u;
|
||||
cfg_mut->gw[1] = 168u;
|
||||
cfg_mut->gw[2] = 31u;
|
||||
cfg_mut->gw[3] = 1u;
|
||||
cfg_mut->server_port = 8080u;
|
||||
cfg_mut->remote_port = 8081u;
|
||||
(void)config_init();
|
||||
cfg = config_get();
|
||||
|
||||
uart_trans_init();
|
||||
|
||||
uart_cfg.baudrate = cfg->uart2_baudrate;
|
||||
uart_cfg.data_bits = cfg->uart2_databits;
|
||||
uart_cfg.stop_bits = cfg->uart2_stopbits;
|
||||
uart_cfg.parity = cfg->uart2_parity;
|
||||
uart_trans_config(UART_CHANNEL_SERVER, &uart_cfg);
|
||||
|
||||
uart_cfg.baudrate = cfg->uart3_baudrate;
|
||||
uart_cfg.data_bits = cfg->uart3_databits;
|
||||
uart_cfg.stop_bits = cfg->uart3_stopbits;
|
||||
uart_cfg.parity = cfg->uart3_parity;
|
||||
uart_trans_config(UART_CHANNEL_CLIENT, &uart_cfg);
|
||||
|
||||
uart_trans_start(UART_CHANNEL_SERVER);
|
||||
uart_trans_start(UART_CHANNEL_CLIENT);
|
||||
(void)uart_trans_init();
|
||||
uart_cfg.baudrate = cfg->uart_baudrate[0];
|
||||
(void)uart_trans_config(UART_CHANNEL_U0, &uart_cfg);
|
||||
uart_cfg.baudrate = cfg->uart_baudrate[1];
|
||||
(void)uart_trans_config(UART_CHANNEL_U1, &uart_cfg);
|
||||
(void)uart_trans_start(UART_CHANNEL_U0);
|
||||
(void)uart_trans_start(UART_CHANNEL_U1);
|
||||
|
||||
SEGGER_RTT_Init();
|
||||
StackGuard_Init();
|
||||
SEGGER_RTT_WriteString(0, "\r\nTCP2UART boot\r\n");
|
||||
if (g_clock_fallback_to_hsi != 0u) {
|
||||
SEGGER_RTT_WriteString(0, "WARN: HSE start failed, fallback to HSI PLL\r\n");
|
||||
}
|
||||
|
||||
lwip_init();
|
||||
IP4_ADDR(&ipaddr, cfg->ip[0], cfg->ip[1], cfg->ip[2], cfg->ip[3]);
|
||||
IP4_ADDR(&netmask, cfg->mask[0], cfg->mask[1], cfg->mask[2], cfg->mask[3]);
|
||||
IP4_ADDR(&gateway, cfg->gw[0], cfg->gw[1], cfg->gw[2], cfg->gw[3]);
|
||||
IP4_ADDR(&ipaddr, cfg->net.ip[0], cfg->net.ip[1], cfg->net.ip[2], cfg->net.ip[3]);
|
||||
IP4_ADDR(&netmask, cfg->net.mask[0], cfg->net.mask[1], cfg->net.mask[2], cfg->net.mask[3]);
|
||||
IP4_ADDR(&gateway, cfg->net.gw[0], cfg->net.gw[1], cfg->net.gw[2], cfg->net.gw[3]);
|
||||
lwip_netif_init(&ipaddr, &netmask, &gateway);
|
||||
App_ConfigureLinks(cfg);
|
||||
BootDiag_ReportCh390();
|
||||
|
||||
server_cfg.port = cfg->server_port;
|
||||
server_cfg.auto_reconnect = true;
|
||||
(void)tcp_server_init(&server_cfg);
|
||||
(void)tcp_server_start();
|
||||
|
||||
memcpy(client_cfg.server_ip, cfg->remote_ip, sizeof(client_cfg.server_ip));
|
||||
client_cfg.local_port = 8081u;
|
||||
client_cfg.server_port = cfg->remote_port;
|
||||
client_cfg.auto_reconnect = true;
|
||||
client_cfg.reconnect_interval_ms = cfg->reconnect_interval;
|
||||
(void)tcp_client_init(&client_cfg);
|
||||
(void)tcp_client_connect();
|
||||
|
||||
SEGGER_RTT_WriteString(0, "TCP bridge enabled\r\n");
|
||||
|
||||
/* Arm UART1 RX interrupt path so config commands can enter via USART1. */
|
||||
if (HAL_UART_Receive_IT(&huart1, (uint8_t *)&g_uart1_rx_probe_byte, 1u) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
static void App_SendToUart(uint8_t uart_index, uint8_t src_id, uint8_t dst_mask, const uint8_t *data, uint16_t len)
|
||||
{
|
||||
const device_config_t *cfg = config_get();
|
||||
uart_channel_t channel = (uart_index == LINK_UART_U1) ? UART_CHANNEL_U1 : UART_CHANNEL_U0;
|
||||
|
||||
if (cfg->mux_mode == MUX_MODE_FRAME) {
|
||||
uint8_t frame[APP_ROUTE_BUFFER_SIZE + 6u];
|
||||
uint16_t frame_len = 0u;
|
||||
if (uart_mux_encode_frame(src_id, dst_mask, data, len, frame, &frame_len, sizeof(frame))) {
|
||||
(void)uart_trans_write(channel, frame, frame_len);
|
||||
}
|
||||
} else {
|
||||
(void)uart_trans_write(channel, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
static void App_RouteTcpTraffic(void)
|
||||
{
|
||||
const device_config_t *cfg = config_get();
|
||||
uint8_t buffer[APP_ROUTE_BUFFER_SIZE];
|
||||
|
||||
for (uint8_t i = 0; i < TCP_SERVER_INSTANCE_COUNT; ++i) {
|
||||
int rc = tcp_server_recv(i, buffer, sizeof(buffer));
|
||||
if (rc > 0) {
|
||||
uint8_t link_index = (i == 0u) ? CONFIG_LINK_S1 : CONFIG_LINK_S2;
|
||||
App_SendToUart(cfg->links[link_index].uart,
|
||||
config_link_index_to_endpoint(link_index),
|
||||
config_uart_index_to_endpoint(cfg->links[link_index].uart),
|
||||
buffer,
|
||||
(uint16_t)rc);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < TCP_CLIENT_INSTANCE_COUNT; ++i) {
|
||||
int rc = tcp_client_recv(i, buffer, sizeof(buffer));
|
||||
if (rc > 0) {
|
||||
uint8_t link_index = (i == 0u) ? CONFIG_LINK_C1 : CONFIG_LINK_C2;
|
||||
App_SendToUart(cfg->links[link_index].uart,
|
||||
config_link_index_to_endpoint(link_index),
|
||||
config_uart_index_to_endpoint(cfg->links[link_index].uart),
|
||||
buffer,
|
||||
(uint16_t)rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void App_RouteRawUartTraffic(void)
|
||||
{
|
||||
const device_config_t *cfg = config_get();
|
||||
uint8_t buffer[APP_ROUTE_BUFFER_SIZE];
|
||||
uint16_t len;
|
||||
|
||||
len = uart_trans_read(UART_CHANNEL_U0, buffer, sizeof(buffer));
|
||||
if (len > 0u) {
|
||||
for (uint8_t i = 0; i < CONFIG_LINK_COUNT; ++i) {
|
||||
if (cfg->links[i].enabled == 0u || cfg->links[i].uart != LINK_UART_U0) {
|
||||
continue;
|
||||
}
|
||||
if (i == CONFIG_LINK_S1) {
|
||||
(void)tcp_server_send(0u, buffer, len);
|
||||
} else if (i == CONFIG_LINK_S2) {
|
||||
(void)tcp_server_send(1u, buffer, len);
|
||||
} else if (i == CONFIG_LINK_C1) {
|
||||
(void)tcp_client_send(0u, buffer, len);
|
||||
} else if (i == CONFIG_LINK_C2) {
|
||||
(void)tcp_client_send(1u, buffer, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
len = uart_trans_read(UART_CHANNEL_U1, buffer, sizeof(buffer));
|
||||
if (len > 0u) {
|
||||
for (uint8_t i = 0; i < CONFIG_LINK_COUNT; ++i) {
|
||||
if (cfg->links[i].enabled == 0u || cfg->links[i].uart != LINK_UART_U1) {
|
||||
continue;
|
||||
}
|
||||
if (i == CONFIG_LINK_S1) {
|
||||
(void)tcp_server_send(0u, buffer, len);
|
||||
} else if (i == CONFIG_LINK_S2) {
|
||||
(void)tcp_server_send(1u, buffer, len);
|
||||
} else if (i == CONFIG_LINK_C1) {
|
||||
(void)tcp_client_send(0u, buffer, len);
|
||||
} else if (i == CONFIG_LINK_C2) {
|
||||
(void)tcp_client_send(1u, buffer, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void App_RouteMuxUartTraffic(void)
|
||||
{
|
||||
uart_mux_frame_t frame;
|
||||
const device_config_t *cfg = config_get();
|
||||
|
||||
while (uart_mux_try_extract_frame(UART_CHANNEL_U0, &frame)) {
|
||||
if (frame.dst_mask == 0u) {
|
||||
at_result_t result;
|
||||
char *response_text = (char *)&g_mux_response_frame[5];
|
||||
if (config_build_response_frame(frame.payload, frame.payload_len, response_text, (uint16_t)(sizeof(g_mux_response_frame) - 6u), &result)) {
|
||||
uint16_t response_len = (uint16_t)strlen(response_text);
|
||||
uint16_t frame_len = 0u;
|
||||
if (uart_mux_encode_frame(config_uart_index_to_endpoint(LINK_UART_U0), 0u, (const uint8_t *)response_text, response_len, g_mux_response_frame, &frame_len, sizeof(g_mux_response_frame))) {
|
||||
(void)uart_trans_write(UART_CHANNEL_U0, g_mux_response_frame, frame_len);
|
||||
}
|
||||
if (result == AT_NEED_REBOOT) {
|
||||
static const char hint[] = "Note: Use AT+SAVE then AT+RESET to apply changes\r\n";
|
||||
response_len = (uint16_t)strlen(hint);
|
||||
if (uart_mux_encode_frame(config_uart_index_to_endpoint(LINK_UART_U0), 0u, (const uint8_t *)hint, response_len, g_mux_response_frame, &frame_len, sizeof(g_mux_response_frame))) {
|
||||
(void)uart_trans_write(UART_CHANNEL_U0, g_mux_response_frame, frame_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((frame.dst_mask & ENDPOINT_S1) != 0u) {
|
||||
(void)tcp_server_send(0u, frame.payload, frame.payload_len);
|
||||
}
|
||||
if ((frame.dst_mask & ENDPOINT_S2) != 0u) {
|
||||
(void)tcp_server_send(1u, frame.payload, frame.payload_len);
|
||||
}
|
||||
if ((frame.dst_mask & ENDPOINT_C1) != 0u) {
|
||||
(void)tcp_client_send(0u, frame.payload, frame.payload_len);
|
||||
}
|
||||
if ((frame.dst_mask & ENDPOINT_C2) != 0u) {
|
||||
(void)tcp_client_send(1u, frame.payload, frame.payload_len);
|
||||
}
|
||||
if ((frame.dst_mask & ENDPOINT_UART3) != 0u && cfg->links[CONFIG_LINK_S2].uart == LINK_UART_U1) {
|
||||
App_SendToUart(LINK_UART_U1, frame.src_id, ENDPOINT_UART3, frame.payload, frame.payload_len);
|
||||
}
|
||||
}
|
||||
|
||||
while (uart_mux_try_extract_frame(UART_CHANNEL_U1, &frame)) {
|
||||
if (frame.dst_mask == 0u) {
|
||||
at_result_t result;
|
||||
char *response_text = (char *)&g_mux_response_frame[5];
|
||||
if (config_build_response_frame(frame.payload, frame.payload_len, response_text, (uint16_t)(sizeof(g_mux_response_frame) - 6u), &result)) {
|
||||
uint16_t response_len = (uint16_t)strlen(response_text);
|
||||
uint16_t frame_len = 0u;
|
||||
if (uart_mux_encode_frame(config_uart_index_to_endpoint(LINK_UART_U1), 0u, (const uint8_t *)response_text, response_len, g_mux_response_frame, &frame_len, sizeof(g_mux_response_frame))) {
|
||||
(void)uart_trans_write(UART_CHANNEL_U1, g_mux_response_frame, frame_len);
|
||||
}
|
||||
if (result == AT_NEED_REBOOT) {
|
||||
static const char hint[] = "Note: Use AT+SAVE then AT+RESET to apply changes\r\n";
|
||||
response_len = (uint16_t)strlen(hint);
|
||||
if (uart_mux_encode_frame(config_uart_index_to_endpoint(LINK_UART_U1), 0u, (const uint8_t *)hint, response_len, g_mux_response_frame, &frame_len, sizeof(g_mux_response_frame))) {
|
||||
(void)uart_trans_write(UART_CHANNEL_U1, g_mux_response_frame, frame_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((frame.dst_mask & ENDPOINT_S1) != 0u) {
|
||||
(void)tcp_server_send(0u, frame.payload, frame.payload_len);
|
||||
}
|
||||
if ((frame.dst_mask & ENDPOINT_S2) != 0u) {
|
||||
(void)tcp_server_send(1u, frame.payload, frame.payload_len);
|
||||
}
|
||||
if ((frame.dst_mask & ENDPOINT_C1) != 0u) {
|
||||
(void)tcp_client_send(0u, frame.payload, frame.payload_len);
|
||||
}
|
||||
if ((frame.dst_mask & ENDPOINT_C2) != 0u) {
|
||||
(void)tcp_client_send(1u, frame.payload, frame.payload_len);
|
||||
}
|
||||
if ((frame.dst_mask & ENDPOINT_UART2) != 0u) {
|
||||
App_SendToUart(LINK_UART_U0, frame.src_id, ENDPOINT_UART2, frame.payload, frame.payload_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void App_Poll(void)
|
||||
{
|
||||
ethernetif_poll();
|
||||
ethernetif_check_link();
|
||||
sys_check_timeouts();
|
||||
App_StopLinksIfNeeded();
|
||||
App_StartLinksIfNeeded();
|
||||
tcp_client_poll();
|
||||
App_ForwardTcpPair();
|
||||
uart_trans_poll();
|
||||
App_PollUart1ConfigRx();
|
||||
StackGuard_Check();
|
||||
config_poll();
|
||||
App_RouteTcpTraffic();
|
||||
|
||||
if (config_get()->mux_mode == MUX_MODE_FRAME) {
|
||||
App_RouteMuxUartTraffic();
|
||||
} else {
|
||||
App_RouteRawUartTraffic();
|
||||
}
|
||||
|
||||
if (config_is_reset_requested()) {
|
||||
config_clear_reset_requested();
|
||||
@@ -295,81 +457,36 @@ static void App_Poll(void)
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* 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();
|
||||
MX_SPI1_Init();
|
||||
MX_TIM4_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* LED 初始化 */
|
||||
LED_Init();
|
||||
LED_StartBlink();
|
||||
|
||||
App_Init();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
App_Poll();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
g_clock_fallback_to_hsi = 0u;
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
||||
@@ -379,11 +496,6 @@ void SystemClock_Config(void)
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||
/*
|
||||
* Some bring-up boards fail to start the external crystal cleanly.
|
||||
* Fall back to HSI-based PLL so the firmware can still boot and expose
|
||||
* RTT / debugger evidence instead of trapping during clock init.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
@@ -397,8 +509,6 @@ void SystemClock_Config(void)
|
||||
g_clock_fallback_to_hsi = 1u;
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
@@ -412,11 +522,6 @@ void SystemClock_Config(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/**
|
||||
* @brief 重定向 printf 到 UART1(调试输出)
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
int _write(int file, char *ptr, int len)
|
||||
{
|
||||
@@ -444,35 +549,16 @@ void Debug_TrapWithRttHint(const char *tag)
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
Debug_TrapWithRttHint("Error_Handler");
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
(void)file;
|
||||
(void)line;
|
||||
Debug_TrapWithRttHint("assert_failed");
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
#endif
|
||||
|
||||
+11
-237
@@ -4,62 +4,15 @@
|
||||
* @file stm32f1xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "stm32f1xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "ethernetif.h"
|
||||
#include "ch390_runtime.h"
|
||||
#include "SEGGER_RTT.h"
|
||||
#include "uart_trans.h"
|
||||
#include "config.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
extern TIM_HandleTypeDef htim4;
|
||||
extern DMA_HandleTypeDef hdma_usart1_rx;
|
||||
@@ -71,332 +24,153 @@ extern DMA_HandleTypeDef hdma_usart3_tx;
|
||||
extern UART_HandleTypeDef huart1;
|
||||
extern UART_HandleTypeDef huart2;
|
||||
extern UART_HandleTypeDef huart3;
|
||||
/* USER CODE BEGIN EV */
|
||||
extern volatile uint8_t g_uart1_rx_probe_byte;
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
Debug_TrapWithRttHint("NMI_Handler");
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
Debug_TrapWithRttHint("HardFault_Handler");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
Debug_TrapWithRttHint("MemManage_Handler");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
Debug_TrapWithRttHint("BusFault_Handler");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
Debug_TrapWithRttHint("UsageFault_Handler");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32F1xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file (startup_stm32f1xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel2 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel2_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_usart3_tx);
|
||||
/* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel3 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel3_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel3_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_usart3_rx);
|
||||
/* USER CODE BEGIN DMA1_Channel3_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel3_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel4 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel4_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel4_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel4_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_usart1_tx);
|
||||
/* USER CODE BEGIN DMA1_Channel4_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel4_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel5 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel5_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel5_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel5_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_usart1_rx);
|
||||
/* USER CODE BEGIN DMA1_Channel5_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel5_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel6 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel6_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel6_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel6_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_usart2_rx);
|
||||
/* USER CODE BEGIN DMA1_Channel6_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel6_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel7 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel7_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel7_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel7_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_usart2_tx);
|
||||
/* USER CODE BEGIN DMA1_Channel7_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel7_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM4 global interrupt.
|
||||
*/
|
||||
void TIM4_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM4_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM4_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim4);
|
||||
/* USER CODE BEGIN TIM4_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM4_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SPI1 global interrupt.
|
||||
*/
|
||||
void SPI1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_IRQn 0 */
|
||||
|
||||
/* USER CODE END SPI1_IRQn 0 */
|
||||
HAL_SPI_IRQHandler(&hspi1);
|
||||
/* USER CODE BEGIN SPI1_IRQn 1 */
|
||||
|
||||
/* USER CODE END SPI1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART1 global interrupt.
|
||||
*/
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART1_IRQn 0 */
|
||||
/* USER CODE END USART1_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart1);
|
||||
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART2 global interrupt.
|
||||
*/
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_IRQn 0 */
|
||||
/* Handle IDLE interrupt for Server transparent transmission */
|
||||
if (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE))
|
||||
{
|
||||
__HAL_UART_CLEAR_IDLEFLAG(&huart2);
|
||||
uart_trans_idle_handler(UART_CHANNEL_SERVER);
|
||||
uart_trans_idle_handler(UART_CHANNEL_U0);
|
||||
}
|
||||
/* USER CODE END USART2_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart2);
|
||||
/* USER CODE BEGIN USART2_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART3 global interrupt.
|
||||
*/
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART3_IRQn 0 */
|
||||
/* Handle IDLE interrupt for Client transparent transmission */
|
||||
if (__HAL_UART_GET_FLAG(&huart3, UART_FLAG_IDLE))
|
||||
{
|
||||
__HAL_UART_CLEAR_IDLEFLAG(&huart3);
|
||||
uart_trans_idle_handler(UART_CHANNEL_CLIENT);
|
||||
uart_trans_idle_handler(UART_CHANNEL_U1);
|
||||
}
|
||||
/* USER CODE END USART3_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart3);
|
||||
/* USER CODE BEGIN USART3_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART3_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
extern volatile uint8_t g_uart1_rx_probe_byte;
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI0 interrupt (CH390D INT pin).
|
||||
*/
|
||||
void EXTI0_IRQHandler(void)
|
||||
{
|
||||
/* Clear interrupt flag */
|
||||
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_0))
|
||||
{
|
||||
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
|
||||
|
||||
/* Defer CH390 processing to main loop */
|
||||
ethernetif_set_irq_pending();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HAL UART TX Complete callback
|
||||
*/
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
if (huart == &huart2)
|
||||
{
|
||||
uart_trans_tx_cplt_handler(UART_CHANNEL_SERVER);
|
||||
uart_trans_tx_cplt_handler(UART_CHANNEL_U0);
|
||||
}
|
||||
else if (huart == &huart3)
|
||||
{
|
||||
uart_trans_tx_cplt_handler(UART_CHANNEL_CLIENT);
|
||||
uart_trans_tx_cplt_handler(UART_CHANNEL_U1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HAL UART RX Complete callback
|
||||
*/
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
if (huart == &huart1)
|
||||
{
|
||||
config_uart_rx_byte(g_uart1_rx_probe_byte);
|
||||
HAL_UART_Receive_IT(&huart1, (uint8_t *)&g_uart1_rx_probe_byte, 1u);
|
||||
(void)HAL_UART_Receive_IT(&huart1, (uint8_t *)&g_uart1_rx_probe_byte, 1u);
|
||||
}
|
||||
else if (huart == &huart2)
|
||||
{
|
||||
uart_trans_rx_cplt_handler(UART_CHANNEL_SERVER);
|
||||
uart_trans_rx_cplt_handler(UART_CHANNEL_U0);
|
||||
}
|
||||
else if (huart == &huart3)
|
||||
{
|
||||
uart_trans_rx_cplt_handler(UART_CHANNEL_CLIENT);
|
||||
uart_trans_rx_cplt_handler(UART_CHANNEL_U1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HAL UART RX Half Complete callback
|
||||
*/
|
||||
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
if (huart == &huart2)
|
||||
{
|
||||
uart_trans_rx_half_cplt_handler(UART_CHANNEL_SERVER);
|
||||
uart_trans_rx_half_cplt_handler(UART_CHANNEL_U0);
|
||||
}
|
||||
else if (huart == &huart3)
|
||||
{
|
||||
uart_trans_rx_half_cplt_handler(UART_CHANNEL_CLIENT);
|
||||
uart_trans_rx_half_cplt_handler(UART_CHANNEL_U1);
|
||||
}
|
||||
}
|
||||
/* USER CODE END 1 */
|
||||
|
||||
Reference in New Issue
Block a user