7 Commits

26 changed files with 219 additions and 1506 deletions
+7
View File
@@ -0,0 +1,7 @@
{
"keil": {
"project": "MDK-ARM/TCP2UART.uvprojx",
"target": "TCP2UART",
"log_dir": ".embeddedskills/build"
}
}
+3
View File
@@ -28,11 +28,14 @@ MDK-ARM/DebugConfig/
MDK-ARM/TCP2UART/ MDK-ARM/TCP2UART/
build_keil.log build_keil.log
MDK-ARM/build.log MDK-ARM/build.log
MDK-ARM/build_capture.txt
MDK-ARM/build_output.txt MDK-ARM/build_output.txt
MDK-ARM/keil-build-viewer.log MDK-ARM/keil-build-viewer.log
MDK-ARM/keil-build-viewer-record.txt MDK-ARM/keil-build-viewer-record.txt
MDK-ARM/keil-build-viewer.exe MDK-ARM/keil-build-viewer.exe
MDK-ARM/EventRecorderStub.scvd MDK-ARM/EventRecorderStub.scvd
.embeddedskills/build/
.embeddedskills/state.json
build_current.log build_current.log
uv4_stdout.txt uv4_stdout.txt
+8 -8
View File
@@ -23,6 +23,8 @@ static device_config_t g_config;
static volatile bool g_reset_requested; static volatile bool g_reset_requested;
static volatile bool g_uart1_tx_busy; static volatile bool g_uart1_tx_busy;
static uint8_t g_uart1_rx_buffer[CONFIG_RX_BUFFER_SIZE]; static uint8_t g_uart1_rx_buffer[CONFIG_RX_BUFFER_SIZE];
static char g_config_cmd_buffer[CONFIG_CMD_MAX_LEN];
static char g_config_response_buffer[CONFIG_TX_BUFFER_SIZE];
static uint32_t config_calc_crc(const device_config_t *cfg) static uint32_t config_calc_crc(const device_config_t *cfg)
{ {
@@ -632,8 +634,6 @@ static void config_respond_to_uart(route_msg_t *msg, const char *response)
void ConfigTask(void *argument) void ConfigTask(void *argument)
{ {
route_msg_t *msg; route_msg_t *msg;
char cmd[CONFIG_CMD_MAX_LEN];
char response[CONFIG_TX_BUFFER_SIZE];
at_result_t result; at_result_t result;
(void)argument; (void)argument;
@@ -646,14 +646,14 @@ void ConfigTask(void *argument)
continue; continue;
} }
if (msg->len >= sizeof(cmd)) { if (msg->len >= sizeof(g_config_cmd_buffer)) {
msg->len = sizeof(cmd) - 1u; msg->len = sizeof(g_config_cmd_buffer) - 1u;
} }
memcpy(cmd, msg->data, msg->len); memcpy(g_config_cmd_buffer, msg->data, msg->len);
cmd[msg->len] = '\0'; g_config_cmd_buffer[msg->len] = '\0';
result = config_process_at_cmd(cmd, response, sizeof(response)); result = config_process_at_cmd(g_config_cmd_buffer, g_config_response_buffer, sizeof(g_config_response_buffer));
config_respond_to_uart(msg, response); config_respond_to_uart(msg, g_config_response_buffer);
if (result == AT_NEED_REBOOT) { if (result == AT_NEED_REBOOT) {
config_respond_to_uart(msg, "Note: Use AT+SAVE then AT+RESET to apply changes\r\n"); config_respond_to_uart(msg, "Note: Use AT+SAVE then AT+RESET to apply changes\r\n");
} }
+4 -5
View File
@@ -16,13 +16,12 @@
extern "C" { extern "C" {
#endif #endif
/* Flash configuration for STM32F103R8 (64KB Flash) */ /* Flash configuration for the current STM32F103RDT6 target (384KB Flash). */
#define FLASH_PARAM_PAGE_SIZE 1024 /* 1KB per page for STM32F103 */ #define FLASH_PARAM_PAGE_SIZE 1024 /* 1KB per page for STM32F103 */
#define FLASH_PARAM_START_ADDR 0x0800FC00 /* Last 1KB of 64KB Flash */ #define FLASH_PARAM_START_ADDR 0x0805FC00 /* Last 1KB page of 384KB Flash */
#define FLASH_PARAM_END_ADDR 0x08010000 /* End of Flash */ #define FLASH_PARAM_END_ADDR 0x08060000 /* End of 384KB Flash */
/* For STM32F103RC (256KB), use: 0x0803FC00 */ /* Historical reference: STM32F103RCT6 would use 0x0803FC00 as its last page. */
/* For STM32F103RB (128KB), use: 0x0801FC00 */
/** /**
* @brief Initialize Flash parameter storage * @brief Initialize Flash parameter storage
+31 -7
View File
@@ -9,8 +9,11 @@
#include "app_runtime.h" #include "app_runtime.h"
#include "config.h" #include "config.h"
#include "debug_log.h" #include "debug_log.h"
#include "ethernetif.h"
#include "route_msg.h" #include "route_msg.h"
#define TCP_CLIENT_CONNECT_TIMEOUT_MS 5000
static err_t tcp_client_worker(struct netconn *conn, uint8_t link_index) static err_t tcp_client_worker(struct netconn *conn, uint8_t link_index)
{ {
struct netbuf *buf; struct netbuf *buf;
@@ -62,20 +65,15 @@ static void tcp_client_task(uint8_t link_index)
err_t err; err_t err;
uint8_t first_connect_deferred; uint8_t first_connect_deferred;
netconn_thread_init();
first_connect_deferred = (link_index == CONFIG_LINK_C1) ? 1u : 0u; first_connect_deferred = (link_index == CONFIG_LINK_C1) ? 1u : 0u;
for (;;) { for (;;) {
while (g_netif_ready == pdFALSE) { while ((g_netif_ready == pdFALSE) || (ethernetif_link_is_up() == 0u)) {
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
} }
cfg = config_get(); cfg = config_get();
debug_log_printf("[CLI] idx=%u hwm=%lu en=%u lport=%u rport=%u\r\n",
(unsigned int)link_index,
(unsigned long)uxTaskGetStackHighWaterMark(NULL),
(unsigned int)cfg->links[link_index].enabled,
(unsigned int)cfg->links[link_index].local_port,
(unsigned int)cfg->links[link_index].remote_port);
if (cfg->links[link_index].enabled == 0u) { if (cfg->links[link_index].enabled == 0u) {
vTaskDelay(pdMS_TO_TICKS(500)); vTaskDelay(pdMS_TO_TICKS(500));
continue; continue;
@@ -99,6 +97,10 @@ static void tcp_client_task(uint8_t link_index)
if (cfg->links[link_index].local_port != 0u) { if (cfg->links[link_index].local_port != 0u) {
err = netconn_bind(conn, IP_ADDR_ANY, cfg->links[link_index].local_port); err = netconn_bind(conn, IP_ADDR_ANY, cfg->links[link_index].local_port);
if (err != ERR_OK) { if (err != ERR_OK) {
debug_log_printf("[CLI] idx=%u bind-fail err=%d lport=%u\r\n",
(unsigned int)link_index,
(int)err,
(unsigned int)cfg->links[link_index].local_port);
netconn_delete(conn); netconn_delete(conn);
vTaskDelay(pdMS_TO_TICKS(delay_ms)); vTaskDelay(pdMS_TO_TICKS(delay_ms));
continue; continue;
@@ -111,9 +113,31 @@ static void tcp_client_task(uint8_t link_index)
cfg->links[link_index].remote_ip[2], cfg->links[link_index].remote_ip[2],
cfg->links[link_index].remote_ip[3]); cfg->links[link_index].remote_ip[3]);
netconn_set_recvtimeout(conn, TCP_CLIENT_CONNECT_TIMEOUT_MS);
err = netconn_connect(conn, &remote_ip, cfg->links[link_index].remote_port); err = netconn_connect(conn, &remote_ip, cfg->links[link_index].remote_port);
if (err == ERR_OK) { if (err == ERR_OK) {
debug_log_printf("[CLI] idx=%u connect-ok\r\n", (unsigned int)link_index);
(void)tcp_client_worker(conn, link_index); (void)tcp_client_worker(conn, link_index);
} else {
if (err == ERR_TIMEOUT) {
debug_log_printf("[CLI] idx=%u connect-timeout ms=%u rip=%u.%u.%u.%u rport=%u\r\n",
(unsigned int)link_index,
(unsigned int)TCP_CLIENT_CONNECT_TIMEOUT_MS,
(unsigned int)cfg->links[link_index].remote_ip[0],
(unsigned int)cfg->links[link_index].remote_ip[1],
(unsigned int)cfg->links[link_index].remote_ip[2],
(unsigned int)cfg->links[link_index].remote_ip[3],
(unsigned int)cfg->links[link_index].remote_port);
} else {
debug_log_printf("[CLI] idx=%u connect-fail err=%d rip=%u.%u.%u.%u rport=%u\r\n",
(unsigned int)link_index,
(int)err,
(unsigned int)cfg->links[link_index].remote_ip[0],
(unsigned int)cfg->links[link_index].remote_ip[1],
(unsigned int)cfg->links[link_index].remote_ip[2],
(unsigned int)cfg->links[link_index].remote_ip[3],
(unsigned int)cfg->links[link_index].remote_port);
}
} }
netconn_close(conn); netconn_close(conn);
+2 -5
View File
@@ -58,17 +58,14 @@ static void tcp_server_task(uint8_t link_index)
struct netconn *listener; struct netconn *listener;
struct netconn *newconn; struct netconn *newconn;
netconn_thread_init();
for (;;) { for (;;) {
while (g_netif_ready == pdFALSE) { while (g_netif_ready == pdFALSE) {
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
} }
cfg = config_get(); cfg = config_get();
debug_log_printf("[SRV] idx=%u hwm=%lu en=%u port=%u\r\n",
(unsigned int)link_index,
(unsigned long)uxTaskGetStackHighWaterMark(NULL),
(unsigned int)cfg->links[link_index].enabled,
(unsigned int)cfg->links[link_index].local_port);
if (cfg->links[link_index].enabled == 0u) { if (cfg->links[link_index].enabled == 0u) {
vTaskDelay(pdMS_TO_TICKS(500)); vTaskDelay(pdMS_TO_TICKS(500));
continue; continue;
+4
View File
@@ -192,6 +192,7 @@ static void uart_send_tcp_msg_to_uarts(route_msg_t *msg)
static void uart_route_mux_frame(uart_channel_t source_channel, const uart_mux_frame_t *frame) static void uart_route_mux_frame(uart_channel_t source_channel, const uart_mux_frame_t *frame)
{ {
const device_config_t *cfg = config_get();
uint32_t i; uint32_t i;
uint8_t source_conn = (source_channel == UART_CHANNEL_U1) ? ROUTE_CONN_UART3 : ROUTE_CONN_UART2; uint8_t source_conn = (source_channel == UART_CHANNEL_U1) ? ROUTE_CONN_UART3 : ROUTE_CONN_UART2;
uint8_t out_frame[ROUTE_MSG_MAX_PAYLOAD + 6u]; uint8_t out_frame[ROUTE_MSG_MAX_PAYLOAD + 6u];
@@ -209,6 +210,9 @@ static void uart_route_mux_frame(uart_channel_t source_channel, const uart_mux_f
} }
for (i = 0; i < CONFIG_LINK_COUNT; ++i) { for (i = 0; i < CONFIG_LINK_COUNT; ++i) {
if (cfg->links[i].enabled == 0u) {
continue;
}
uint8_t endpoint = config_link_index_to_endpoint((uint8_t)i); uint8_t endpoint = config_link_index_to_endpoint((uint8_t)i);
if ((frame->dst_mask & endpoint) != 0u) { if ((frame->dst_mask & endpoint) != 0u) {
(void)route_send(xLinkTxQueues[i], frame->src_id, endpoint, source_conn, frame->payload, frame->payload_len, pdMS_TO_TICKS(10)); (void)route_send(xLinkTxQueues[i], frame->src_id, endpoint, source_conn, frame->payload, frame->payload_len, pdMS_TO_TICKS(10));
+11 -8
View File
@@ -44,6 +44,7 @@
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
/* Section where include file can be added */ /* Section where include file can be added */
#include "debug_log.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
/* Ensure definitions are only used by the compiler, and not by the assembler. */ /* Ensure definitions are only used by the compiler, and not by the assembler. */
@@ -65,7 +66,7 @@
#define configTICK_RATE_HZ ((TickType_t)1000) #define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 7 ) #define configMAX_PRIORITIES ( 7 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128) #define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)15360) #define configTOTAL_HEAP_SIZE ((size_t)21760)
#define configMAX_TASK_NAME_LEN ( 16 ) #define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1 #define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0 #define configUSE_16_BIT_TICKS 0
@@ -86,6 +87,8 @@
#define configTIMER_TASK_PRIORITY ( 2 ) #define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_QUEUE_LENGTH 10 #define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH 256 #define configTIMER_TASK_STACK_DEPTH 256
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_MALLOC_FAILED_HOOK 1
/* Set the following definitions to 1 to include the API function, or zero /* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */ to exclude the API function. */
@@ -137,7 +140,7 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
/* Normal assert() semantics without relying on the provision of an assert.h /* Normal assert() semantics without relying on the provision of an assert.h
header file. */ header file. */
/* USER CODE BEGIN 1 */ /* USER CODE BEGIN 1 */
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );} #define configASSERT( x ) do { if ((x) == 0) { debug_log_fault_context("config-assert", __FILE__, __LINE__); taskDISABLE_INTERRUPTS(); for( ;; ) { } } } while (0)
/* USER CODE END 1 */ /* USER CODE END 1 */
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
@@ -164,13 +167,13 @@ standard names. */
/* Application task stack sizes (in words) */ /* Application task stack sizes (in words) */
#define TASK_STACK_TCPIP 512 #define TASK_STACK_TCPIP 512
#define TASK_STACK_NET_POLL 384 #define TASK_STACK_NET_POLL 512
#define TASK_STACK_TCP_SERVER 384 #define TASK_STACK_TCP_SERVER 512
#define TASK_STACK_TCP_CLIENT 384 #define TASK_STACK_TCP_CLIENT 512
#define TASK_STACK_UART_RX 256 #define TASK_STACK_UART_RX 384
#define TASK_STACK_ROUTE 512 #define TASK_STACK_ROUTE 512
#define TASK_STACK_CONFIG 256 #define TASK_STACK_CONFIG 384
#define TASK_STACK_DEFAULT 128 #define TASK_STACK_DEFAULT 192
/* Route message pool for zero-copy inter-task communication */ /* Route message pool for zero-copy inter-task communication */
#define ROUTE_MSG_POOL_SIZE 8 #define ROUTE_MSG_POOL_SIZE 8
+1
View File
@@ -17,6 +17,7 @@ void debug_log_printf(const char *fmt, ...);
void debug_log_boot(const char *tag); void debug_log_boot(const char *tag);
void debug_log_fault(const char *tag); void debug_log_fault(const char *tag);
void debug_log_runtime_snapshot(void); void debug_log_runtime_snapshot(void);
void debug_log_fault_context(const char *tag, const char *file, int line);
#ifdef __cplusplus #ifdef __cplusplus
} }
+1 -1
View File
@@ -38,7 +38,7 @@ extern IWDG_HandleTypeDef hiwdg;
/* USER CODE END Private defines */ /* USER CODE END Private defines */
void MX_IWDG_Init(void); HAL_StatusTypeDef MX_IWDG_Init(void);
/* USER CODE BEGIN Prototypes */ /* USER CODE BEGIN Prototypes */
+14 -1
View File
@@ -45,7 +45,7 @@ void debug_log_write(const char *msg)
void debug_log_printf(const char *fmt, ...) void debug_log_printf(const char *fmt, ...)
{ {
char buffer[128]; char buffer[256];
va_list args; va_list args;
int len; int len;
@@ -75,6 +75,19 @@ void debug_log_fault(const char *tag)
debug_log_printf("[FAULT] %s\r\n", (tag != NULL) ? tag : "(null)"); 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) void debug_log_runtime_snapshot(void)
{ {
UBaseType_t default_hwm; UBaseType_t default_hwm;
+32 -21
View File
@@ -36,48 +36,70 @@ static TaskHandle_t xTcpSrvTaskS2Handle = NULL;
static TaskHandle_t xTcpCliTaskC1Handle = NULL; static TaskHandle_t xTcpCliTaskC1Handle = NULL;
static TaskHandle_t xTcpCliTaskC2Handle = NULL; static TaskHandle_t xTcpCliTaskC2Handle = NULL;
static TaskHandle_t xDefaultTaskHandle = NULL; static TaskHandle_t xDefaultTaskHandle = NULL;
static BaseType_t xNetworkTasksStarted = pdFALSE;
void app_start_network_tasks(void) void app_start_network_tasks(void)
{ {
#if !DIAG_TASK_ISOLATION #if !DIAG_TASK_ISOLATION
BaseType_t rc; BaseType_t rc;
const device_config_t *cfg;
if (xTcpSrvTaskS1Handle != NULL) { if (xNetworkTasksStarted != pdFALSE) {
debug_log_write("[NET] start-network-tasks already\r\n"); debug_log_write("[NET] start-network-tasks already\r\n");
return; return;
} }
cfg = config_get();
debug_log_printf("[NET] start-network-tasks enter free=%lu min=%lu\r\n", debug_log_printf("[NET] start-network-tasks enter free=%lu min=%lu\r\n",
(unsigned long)xPortGetFreeHeapSize(), (unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize()); (unsigned long)xPortGetMinimumEverFreeHeapSize());
if (cfg->links[CONFIG_LINK_S1].enabled != 0u) {
rc = xTaskCreate(TcpSrvTask_S1, "TcpSrvS1", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS1Handle); rc = xTaskCreate(TcpSrvTask_S1, "TcpSrvS1", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS1Handle);
debug_log_printf("[NET] create TcpSrvS1 rc=%ld free=%lu min=%lu\r\n", debug_log_printf("[NET] create TcpSrvS1 rc=%ld free=%lu min=%lu\r\n",
(long)rc, (long)rc,
(unsigned long)xPortGetFreeHeapSize(), (unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize()); (unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS); configASSERT(rc == pdPASS);
} else {
debug_log_write("[NET] skip TcpSrvS1 en=0\r\n");
}
if (cfg->links[CONFIG_LINK_S2].enabled != 0u) {
rc = xTaskCreate(TcpSrvTask_S2, "TcpSrvS2", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS2Handle); rc = xTaskCreate(TcpSrvTask_S2, "TcpSrvS2", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS2Handle);
debug_log_printf("[NET] create TcpSrvS2 rc=%ld free=%lu min=%lu\r\n", debug_log_printf("[NET] create TcpSrvS2 rc=%ld free=%lu min=%lu\r\n",
(long)rc, (long)rc,
(unsigned long)xPortGetFreeHeapSize(), (unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize()); (unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS); configASSERT(rc == pdPASS);
} else {
debug_log_write("[NET] skip TcpSrvS2 en=0\r\n");
}
if (cfg->links[CONFIG_LINK_C1].enabled != 0u) {
rc = xTaskCreate(TcpCliTask_C1, "TcpCliC1", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC1Handle); rc = xTaskCreate(TcpCliTask_C1, "TcpCliC1", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC1Handle);
debug_log_printf("[NET] create TcpCliC1 rc=%ld free=%lu min=%lu\r\n", debug_log_printf("[NET] create TcpCliC1 rc=%ld free=%lu min=%lu\r\n",
(long)rc, (long)rc,
(unsigned long)xPortGetFreeHeapSize(), (unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize()); (unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS); configASSERT(rc == pdPASS);
} else {
debug_log_write("[NET] skip TcpCliC1 en=0\r\n");
}
if (cfg->links[CONFIG_LINK_C2].enabled != 0u) {
rc = xTaskCreate(TcpCliTask_C2, "TcpCliC2", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC2Handle); rc = xTaskCreate(TcpCliTask_C2, "TcpCliC2", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC2Handle);
debug_log_printf("[NET] create TcpCliC2 rc=%ld free=%lu min=%lu\r\n", debug_log_printf("[NET] create TcpCliC2 rc=%ld free=%lu min=%lu\r\n",
(long)rc, (long)rc,
(unsigned long)xPortGetFreeHeapSize(), (unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize()); (unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS); configASSERT(rc == pdPASS);
} else {
debug_log_write("[NET] skip TcpCliC2 en=0\r\n");
}
xNetworkTasksStarted = pdTRUE;
debug_log_printf("[NET] start-network-tasks exit free=%lu min=%lu\r\n", debug_log_printf("[NET] start-network-tasks exit free=%lu min=%lu\r\n",
(unsigned long)xPortGetFreeHeapSize(), (unsigned long)xPortGetFreeHeapSize(),
@@ -87,33 +109,22 @@ void app_start_network_tasks(void)
static void StartDefaultTask(void *argument) static void StartDefaultTask(void *argument)
{ {
TickType_t last_snapshot = xTaskGetTickCount(); BaseType_t iwdg_ready = pdFALSE;
BaseType_t alive_logged = pdFALSE;
(void)argument; (void)argument;
debug_log_boot("default-task"); 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 (;;) { for (;;) {
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
if (iwdg_ready == pdTRUE) {
HAL_IWDG_Refresh(&hiwdg); HAL_IWDG_Refresh(&hiwdg);
if (alive_logged == pdFALSE) {
debug_log_write("[RTOS] alive\r\n");
alive_logged = pdTRUE;
}
if ((xTaskGetTickCount() - last_snapshot) >= pdMS_TO_TICKS(5000)) {
debug_log_printf("[RTOS] seq=%lu drops=%lu last=%lu free=%lu min=%lu self_hwm=%lu\r\n",
(unsigned long)g_rtt_log_seq,
(unsigned long)g_rtt_log_drop_count,
(unsigned long)g_rtt_log_last_drop_seq,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize(),
(unsigned long)uxTaskGetStackHighWaterMark(NULL));
if (xNetPollTaskHandle != NULL) {
debug_log_printf("[RTOS] net_phase=%lu net_hwm=%lu\r\n",
(unsigned long)g_netif_phase,
(unsigned long)uxTaskGetStackHighWaterMark(xNetPollTaskHandle));
}
last_snapshot = xTaskGetTickCount();
} }
vTaskDelay(pdMS_TO_TICKS(500)); vTaskDelay(pdMS_TO_TICKS(500));
} }
+3 -3
View File
@@ -27,7 +27,7 @@
IWDG_HandleTypeDef hiwdg; IWDG_HandleTypeDef hiwdg;
/* IWDG init function */ /* IWDG init function */
void MX_IWDG_Init(void) HAL_StatusTypeDef MX_IWDG_Init(void)
{ {
/* USER CODE BEGIN IWDG_Init 0 */ /* USER CODE BEGIN IWDG_Init 0 */
@@ -42,12 +42,12 @@ void MX_IWDG_Init(void)
hiwdg.Init.Reload = 4095; hiwdg.Init.Reload = 4095;
if (HAL_IWDG_Init(&hiwdg) != HAL_OK) if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
{ {
Error_Handler(); return HAL_ERROR;
} }
/* USER CODE BEGIN IWDG_Init 2 */ /* USER CODE BEGIN IWDG_Init 2 */
/* USER CODE END IWDG_Init 2 */ /* USER CODE END IWDG_Init 2 */
return HAL_OK;
} }
/* USER CODE BEGIN 1 */ /* USER CODE BEGIN 1 */
+23 -3
View File
@@ -142,7 +142,6 @@ int main(void)
/* Initialize all configured peripherals */ /* Initialize all configured peripherals */
MX_GPIO_Init(); MX_GPIO_Init();
MX_DMA_Init(); MX_DMA_Init();
MX_IWDG_Init();
MX_USART1_UART_Init(); MX_USART1_UART_Init();
MX_USART2_UART_Init(); MX_USART2_UART_Init();
MX_USART3_UART_Init(); MX_USART3_UART_Init();
@@ -231,7 +230,28 @@ void SystemClock_Config(void)
*/ */
void Debug_TrapWithRttHint(const char *tag) 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 */ /* USER CODE END 4 */
@@ -244,7 +264,7 @@ void Error_Handler(void)
{ {
/* USER CODE BEGIN Error_Handler_Debug */ /* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */ /* 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(); __disable_irq();
while (1) while (1)
{ {
+7 -1
View File
@@ -1395,7 +1395,13 @@ lwip_netconn_do_connect(void *m)
#if LWIP_TCPIP_CORE_LOCKING #if LWIP_TCPIP_CORE_LOCKING
LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT); LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT);
UNLOCK_TCPIP_CORE(); UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0); if (sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), msg->conn->recv_timeout) == SYS_ARCH_TIMEOUT) {
if (msg->conn->state == NETCONN_CONNECT) {
msg->conn->current_msg = NULL;
msg->conn->state = NETCONN_NONE;
msg->err = ERR_TIMEOUT;
}
}
LOCK_TCPIP_CORE(); LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT); LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT);
#endif /* LWIP_TCPIP_CORE_LOCKING */ #endif /* LWIP_TCPIP_CORE_LOCKING */
@@ -24,6 +24,7 @@ err_t ethernetif_init(struct netif *netif);
void ethernetif_input(struct netif *netif); void ethernetif_input(struct netif *netif);
void lwip_netif_init(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw); void lwip_netif_init(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw);
void ethernetif_check_link(void); void ethernetif_check_link(void);
uint8_t ethernetif_link_is_up(void);
void ethernetif_poll(void); void ethernetif_poll(void);
void print_netif(struct netif *netif); void print_netif(struct netif *netif);
+9 -2
View File
@@ -457,6 +457,8 @@ void ethernetif_diag_poll_status(void)
*/ */
static void ethernetif_update_link(uint8_t link_status) static void ethernetif_update_link(uint8_t link_status)
{ {
LOCK_TCPIP_CORE();
if (link_status) if (link_status)
{ {
if (!netif_is_link_up(&ch390_netif)) if (!netif_is_link_up(&ch390_netif))
@@ -464,9 +466,7 @@ static void ethernetif_update_link(uint8_t link_status)
netif_set_link_up(&ch390_netif); netif_set_link_up(&ch390_netif);
if ((s_garp_sent == 0u) && netif_is_up(&ch390_netif)) if ((s_garp_sent == 0u) && netif_is_up(&ch390_netif))
{ {
LOCK_TCPIP_CORE();
etharp_gratuitous(&ch390_netif); etharp_gratuitous(&ch390_netif);
UNLOCK_TCPIP_CORE();
s_garp_sent = 1u; s_garp_sent = 1u;
} }
} }
@@ -479,6 +479,8 @@ static void ethernetif_update_link(uint8_t link_status)
s_garp_sent = 0u; s_garp_sent = 0u;
} }
} }
UNLOCK_TCPIP_CORE();
} }
/** /**
@@ -561,3 +563,8 @@ void ethernetif_check_link(void)
ethernetif_update_link(link_status); ethernetif_update_link(link_status);
} }
uint8_t ethernetif_link_is_up(void)
{
return netif_is_link_up(&ch390_netif) ? 1u : 0u;
}
+6
View File
@@ -63,6 +63,12 @@ void ethernetif_diag_poll_status(void);
*/ */
void ethernetif_check_link(void); void ethernetif_check_link(void);
/**
* @brief Query whether physical Ethernet link is currently up
* @return 1 if link is up, 0 otherwise
*/
uint8_t ethernetif_link_is_up(void);
/** /**
* @brief Process all pending RX packets * @brief Process all pending RX packets
* @note Call this from the LwIP task when RX interrupt occurs * @note Call this from the LwIP task when RX interrupt occurs
+2 -2
View File
@@ -92,7 +92,7 @@ Revision: $Rev: 24316 $
#endif #endif
#ifndef BUFFER_SIZE_UP #ifndef BUFFER_SIZE_UP
#define BUFFER_SIZE_UP (512) // Size of the buffer for terminal output of target, up to host (Default: 1k) #define BUFFER_SIZE_UP (2048) // Size of the buffer for terminal output of target, up to host (Default: 1k)
#endif #endif
#ifndef BUFFER_SIZE_DOWN #ifndef BUFFER_SIZE_DOWN
@@ -100,7 +100,7 @@ Revision: $Rev: 24316 $
#endif #endif
#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE #ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64) #define SEGGER_RTT_PRINTF_BUFFER_SIZE (128u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
#endif #endif
#ifndef SEGGER_RTT_MODE_DEFAULT #ifndef SEGGER_RTT_MODE_DEFAULT
+3 -3
View File
@@ -113,8 +113,8 @@ USE_HAL_DRIVER,STM32F103xE
======================================== ========================================
确认 ROM 和 RAM 配置正确: 确认 ROM 和 RAM 配置正确:
- IROM1: 0x08000000, Size: 0x40000 (256KB) - IROM1: 0x08000000, Size: 0x60000 (384KB)
- IRAM1: 0x20000000, Size: 0xC000 (48KB) - IRAM1: 0x20000000, Size: 0x10000 (64KB)
======================================== ========================================
六、编译验证 六、编译验证
@@ -138,7 +138,7 @@ Debug 选项卡:
Utilities 选项卡: Utilities 选项卡:
- 选择正确的 Flash 算法 - 选择正确的 Flash 算法
- STM32F10x High-density Flash (256KB) - STM32F10x High-density Flash (384KB / 0x60000)
======================================== ========================================
快速添加方法(可选) 快速添加方法(可选)
File diff suppressed because it is too large Load Diff
+10 -10
View File
@@ -14,16 +14,16 @@
<uAC6>0</uAC6> <uAC6>0</uAC6>
<TargetOption> <TargetOption>
<TargetCommonOption> <TargetCommonOption>
<Device>STM32F103RC</Device> <Device>STM32F103RD</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.2.4.1</PackID> <PackID>Keil.STM32F1xx_DFP.2.4.1</PackID>
<PackURL>https://www.keil.com/pack/</PackURL> <PackURL>https://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x0000C000) IROM(0x08000000,0x00040000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu> <Cpu>IRAM(0x20000000,0x00010000) IROM(0x08000000,0x00060000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile> <StartupFile></StartupFile>
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_HD -FS08000000 -FL040000 -FP0($$Device:STM32F103RC$Flash\STM32F10x_HD.FLM))</FlashDriverDll> <FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_512 -FS08000000 -FL080000 -FP0($$Device:STM32F103RD$Flash\STM32F10x_512.FLM))</FlashDriverDll>
<DeviceId>0</DeviceId> <DeviceId>0</DeviceId>
<RegisterFile>$$Device:STM32F103RC$Device\Include\stm32f10x.h</RegisterFile> <RegisterFile>$$Device:STM32F103RD$Device\Include\stm32f10x.h</RegisterFile>
<MemoryEnv></MemoryEnv> <MemoryEnv></MemoryEnv>
<Cmp></Cmp> <Cmp></Cmp>
<Asm></Asm> <Asm></Asm>
@@ -33,7 +33,7 @@
<SLE66CMisc></SLE66CMisc> <SLE66CMisc></SLE66CMisc>
<SLE66AMisc></SLE66AMisc> <SLE66AMisc></SLE66AMisc>
<SLE66LinkerMisc></SLE66LinkerMisc> <SLE66LinkerMisc></SLE66LinkerMisc>
<SFDFile>$$Device:STM32F103RC$SVD\STM32F103xx.svd</SFDFile> <SFDFile>$$Device:STM32F103RD$SVD\STM32F103xx.svd</SFDFile>
<bCustSvd>0</bCustSvd> <bCustSvd>0</bCustSvd>
<UseEnv>0</UseEnv> <UseEnv>0</UseEnv>
<BinPath></BinPath> <BinPath></BinPath>
@@ -138,7 +138,7 @@
</Flash1> </Flash1>
<bUseTDR>1</bUseTDR> <bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2> <Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3>"" ()</Flash3> <Flash3></Flash3>
<Flash4></Flash4> <Flash4></Flash4>
<pFcarmOut></pFcarmOut> <pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp> <pFcarmGrp></pFcarmGrp>
@@ -247,12 +247,12 @@
<IRAM> <IRAM>
<Type>0</Type> <Type>0</Type>
<StartAddress>0x20000000</StartAddress> <StartAddress>0x20000000</StartAddress>
<Size>0xc000</Size> <Size>0x10000</Size>
</IRAM> </IRAM>
<IROM> <IROM>
<Type>1</Type> <Type>1</Type>
<StartAddress>0x8000000</StartAddress> <StartAddress>0x8000000</StartAddress>
<Size>0x40000</Size> <Size>0x60000</Size>
</IROM> </IROM>
<XRAM> <XRAM>
<Type>0</Type> <Type>0</Type>
@@ -277,7 +277,7 @@
<OCR_RVCT4> <OCR_RVCT4>
<Type>1</Type> <Type>1</Type>
<StartAddress>0x8000000</StartAddress> <StartAddress>0x8000000</StartAddress>
<Size>0x40000</Size> <Size>0x60000</Size>
</OCR_RVCT4> </OCR_RVCT4>
<OCR_RVCT5> <OCR_RVCT5>
<Type>1</Type> <Type>1</Type>
@@ -302,7 +302,7 @@
<OCR_RVCT9> <OCR_RVCT9>
<Type>0</Type> <Type>0</Type>
<StartAddress>0x20000000</StartAddress> <StartAddress>0x20000000</StartAddress>
<Size>0xc000</Size> <Size>0x10000</Size>
</OCR_RVCT9> </OCR_RVCT9>
<OCR_RVCT10> <OCR_RVCT10>
<Type>0</Type> <Type>0</Type>
-8
View File
@@ -1,8 +0,0 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'TCP2UART'
compiling tcp_client.c...
linking...
Program Size: Code=84560 RO-data=2496 RW-data=432 ZI-data=47056
FromELF: creating hex file...
"TCP2UART\TCP2UART.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:01
+1 -1
View File
@@ -39,7 +39,7 @@ __initial_sp
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h> ; </h>
Heap_Size EQU 0x200 Heap_Size EQU 0x400
AREA HEAP, NOINIT, READWRITE, ALIGN=3 AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base __heap_base
+8 -8
View File
@@ -70,11 +70,11 @@ FREERTOS.configCHECK_FOR_STACK_OVERFLOW=2
FREERTOS.configMAX_PRIORITIES=7 FREERTOS.configMAX_PRIORITIES=7
FREERTOS.configMINIMAL_STACK_SIZE=128 FREERTOS.configMINIMAL_STACK_SIZE=128
FREERTOS.configSUPPORT_DYNAMIC_ALLOCATION=1 FREERTOS.configSUPPORT_DYNAMIC_ALLOCATION=1
FREERTOS.configSUPPORT_STATIC_ALLOCATION=0 FREERTOS.configSUPPORT_STATIC_ALLOCATION=1
FREERTOS.configTICK_RATE_HZ=1000 FREERTOS.configTICK_RATE_HZ=1000
FREERTOS.configTOTAL_HEAP_SIZE=10240 FREERTOS.configTOTAL_HEAP_SIZE=15360
FREERTOS.configUSE_COUNTING_SEMAPHORES=1 FREERTOS.configUSE_COUNTING_SEMAPHORES=1
FREERTOS.configUSE_IDLE_HOOK=0 FREERTOS.configUSE_IDLE_HOOK=1
FREERTOS.configUSE_MALLOC_FAILED_HOOK=1 FREERTOS.configUSE_MALLOC_FAILED_HOOK=1
FREERTOS.configUSE_MUTEXES=1 FREERTOS.configUSE_MUTEXES=1
FREERTOS.configUSE_PREEMPTION=1 FREERTOS.configUSE_PREEMPTION=1
@@ -83,7 +83,7 @@ FREERTOS.configUSE_TICK_HOOK=0
File.Version=6 File.Version=6
GPIO.groupedBy=Group By Peripherals GPIO.groupedBy=Group By Peripherals
KeepUserPlacement=false KeepUserPlacement=false
Mcu.CPN=STM32F103RCT6 Mcu.CPN=STM32F103RDT6
Mcu.Family=STM32F1 Mcu.Family=STM32F1
Mcu.IP0=DMA Mcu.IP0=DMA
Mcu.IP1=FREERTOS Mcu.IP1=FREERTOS
@@ -123,7 +123,7 @@ Mcu.Pin20=VP_TIM4_VS_ClockSourceINT
Mcu.PinsNb=21 Mcu.PinsNb=21
Mcu.ThirdPartyNb=0 Mcu.ThirdPartyNb=0
Mcu.UserConstants= Mcu.UserConstants=
Mcu.UserName=STM32F103RCTx Mcu.UserName=STM32F103RDTx
MxCube.Version=6.16.1 MxCube.Version=6.16.1
MxDb.Version=DB.6.0.161 MxDb.Version=DB.6.0.161
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
@@ -182,7 +182,7 @@ PC13-TAMPER-RTC.Signal=GPIO_Output
PCC.Checker=false PCC.Checker=false
PCC.Line=STM32F103 PCC.Line=STM32F103
PCC.MCU=STM32F103R(C-D-E)Tx PCC.MCU=STM32F103R(C-D-E)Tx
PCC.PartNumber=STM32F103RCTx PCC.PartNumber=STM32F103RDTx
PCC.Series=STM32F1 PCC.Series=STM32F1
PCC.Temperature=25 PCC.Temperature=25
PCC.Vdd=3.3 PCC.Vdd=3.3
@@ -200,12 +200,12 @@ ProjectManager.CoupleFile=true
ProjectManager.CustomerFirmwarePackage= ProjectManager.CustomerFirmwarePackage=
ProjectManager.DefaultFWLocation=true ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=true ProjectManager.DeletePrevious=true
ProjectManager.DeviceId=STM32F103RCTx ProjectManager.DeviceId=STM32F103RDTx
ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.7 ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.7
ProjectManager.FreePins=false ProjectManager.FreePins=false
ProjectManager.FreePinsContext= ProjectManager.FreePinsContext=
ProjectManager.HalAssertFull=false ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200 ProjectManager.HeapSize=0x400
ProjectManager.KeepUserCode=true ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true ProjectManager.LastFirmware=true
ProjectManager.LibraryCopy=0 ProjectManager.LibraryCopy=0
+2 -2
View File
@@ -520,8 +520,8 @@ FreeRTOS 可管理的中断优先级必须 >= `configMAX_SYSCALL_INTERRUPT_PRIOR
| Flash | 256 KB | 384 KB | | Flash | 256 KB | 384 KB |
| SRAM | 48 KB | 64 KB | | SRAM | 48 KB | 64 KB |
| 引脚 | LQFP64 | LQFP64(完全兼容) | | 引脚 | LQFP64 | LQFP64(完全兼容) |
| 启动文件 | `startup_stm32f103xe.s` | `startup_stm32f103xd.s` | | 启动文件 | `startup_stm32f103xe.s` | `startup_stm32f103xe.s` |
| 宏定义 | `STM32F103xE` | `STM32F103xD` | | 宏定义 | `STM32F103xE` | `STM32F103xE` |
| Flash 算法 | `STM32F10x_HD` | `STM32F10x_HD`(相同) | | Flash 算法 | `STM32F10x_HD` | `STM32F10x_HD`(相同) |
| SRAM 大小 | `0xC000` | `0x10000` | | SRAM 大小 | `0xC000` | `0x10000` |
| Flash 大小 | `0x40000` | `0x60000` | | Flash 大小 | `0x40000` | `0x60000` |