freeRTOS + LwIP crashing on STM32F746VGT6, but not on STM32F746G-DISCO
Hello,
I am using an STM32F746VGT6 with a LAN8742A PHY to implement a basic TCP server using freeRTOS + LwIP for text communications. I've attached the code below:
#include "bti_tcpecho.h"
#define TCP_SERVER_TASK_PRIORITY 10
BaseType_t bti_tcp_server_return;
TaskHandle_t tcp_server_task_handle;
static void tcpecho_thread(void *arg){
struct netconn *conn, *newconn;
err_t err;
err_t accept_err;
err_t recv_err;
LWIP_UNUSED_ARG(arg);
////
char echo_msg[4] = "echo";
u16_t echo_len = 4;
conn = netconn_new(NETCONN_TCP);
if(conn != NULL){
err = netconn_bind(conn, NULL, 7);
}
if(err == ERR_OK){
netconn_listen(conn);
while(1){
accept_err = netconn_accept(conn, &newconn);
if(accept_err == ERR_OK){
struct netbuf *buf;
void *data;
u16_t len;
while((recv_err = netconn_recv(newconn, &buf)) == ERR_OK){
do{
netbuf_data(buf, &data, &len);
netconn_write(newconn, data, len, NETCONN_COPY);
netconn_write(newconn, echo_msg, echo_len, NETCONN_COPY);
}
while(netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
netconn_close(newconn);
netconn_delete(newconn);
}
}
}
else{
netconn_delete(newconn);
}
}
void tcpecho_init(void){
sys_thread_new("tcpecho_thread", tcpecho_thread, NULL, DEFAULT_THREAD_STACKSIZE, TCP_SERVER_TASK_PRIORITY);
}
This seems to run fine on my board, until I changed lines 17 and 18 to some string longer than "echo". For example, the following code will cause the MCU to hard fault right away on startup (even before any client tries to connect):
char echo_msg[8] = "echo1234";
u16_t echo_len = 8;
The program seems to crash at some memset() in startup. Here are two examples of the crashes:




Here is the defaultTask:
void StartDefaultTask(void const * argument)
{
/* init code for LWIP */
MX_LWIP_Init();
/* USER CODE BEGIN 5 */
tcpecho_init();
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END 5 */
}
I tried flashing this exact same code onto a STM32F746G-DISCO, and it works perfectly, regardless of the string contained in echo_msg. The MPU configuration is the same for both:

All the settings for freeRTOS and LwIP are set to default, except for the defaultTask stack size, which I set to 512 words.
Here is the partial board schematic:

