cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 TCP-IP fault (FreeRTOS LwIP)

MKise
Associate

Hi all!

I'm trying to use LwIP stack on STM32H743XI.

I am installing a TCP-IP server. I use CubeMX for initialization. The ethernetif.c file is slightly edited to temporarily disable the d-cache in one of the I / O functions, as shown in one issue, this is an h-series problem.

In the beginning, I configure the MPU, initialize the stack by calling the MX_LWIP_Init () command.

Next, I create a connection by calling the netconn_new () command and

bind the structure to port # 502 with the netconn_bind () command.

Next, I specify the connection to listen for incoming connection requests with the netconn_listen () command.

Further, if a connection arrives, I create a new task in which I call netconn_accept () to block until we receive an incoming connection request.

Further, if netconn_accept () returned the value "ERR_OK", then I call netconn_recv () to accept the data.

If recv returns the value "ERR_OK", I enter the critical section,

call netbuf_data () to process the data and somehow process it,

destroy the received buffer with the netbuf_delete () command and

exit the critical section, then

return to the netconn_recv () function.

This works for a while, always different in time. It may fail quickly, maybe after 40 minutes. Reception is two messages with a length of 12 bytes each time per second. The causes of crashes can be different, but most often it is a hang when switching FreeRTOS tasks. There are also MemManageFault and HardFault. Sometimes a message arrives with the first 8 bytes zero (this is an abnormal situation, the request source (client) sends the correct data, I checked using WireShark).

I am using Keil uVision, the standard compiler of version 5. FreeRTOS v10.0.1, LwIP v2.0.3, CubeMX 5.3.0, service pack 1.4.0. I tried to install the latest version of LwIP, it did not help.

FreeRTOS works correctly if you do not open a TCP-IP connection. Ping works stably for a long time. The stack does not overflow, I checked it by displaying debugging information. vApplicationStackOverflowHook () is not called, but is in the code.

I ask for any help.

Thank!

err_t err, recv_err;
struct netconn *conn;
struct netbuf *inbuf;
struct netconn *newconn; 
 
// receive incoming param
struct_sock *arg_sock;
arg_sock = (struct_sock*) argument;
conn = arg_sock->conn;
	
	
u16_t buflen;
static char* buf;	
 
for(;;)
  {    
       err = netconn_accept(conn, &newconn);
       if (err == ERR_OK) {
       while (1) {
           recv_err = netconn_recv(newconn, &inbuf);
           if (recv_err == ERR_OK) { 
		taskENTER_CRITICAL ();
                netbuf_data(inbuf, (void**)&buf, &buflen); 
					...
                                        ...
					...		
                netbuf_delete(inbuf);
		taskEXIT_CRITICAL();
        } else {
          netbuf_delete(inbuf); 
          netconn_close(newconn); 
	  netconn_delete(newconn);
          break;
        }
      }
    }
    else
    {
      osDelay(100);
    }
  }

MPU init:

void MPU_Config(void)
{
  MPU_Region_InitTypeDef MPU_InitStruct = {0};
 
  /* Disables the MPU */
  HAL_MPU_Disable();
  /** Initializes and configures the Region and the memory to be protected 
  */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  MPU_InitStruct.BaseAddress = 0x30040000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_16KB;
  MPU_InitStruct.SubRegionDisable = 0x0;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
  MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
 
  HAL_MPU_ConfigRegion(&MPU_InitStruct);
  /** Initializes and configures the Region and the memory to be protected 
  */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER1;
  MPU_InitStruct.BaseAddress = 0x30044000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_16KB;
  MPU_InitStruct.SubRegionDisable = 0x0;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
 
  HAL_MPU_ConfigRegion(&MPU_InitStruct);
  /** Initializes and configures the Region and the memory to be protected 
  */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER2;
  MPU_InitStruct.BaseAddress = 0x30040000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_256B;
  MPU_InitStruct.SubRegionDisable = 0x0;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
 
  HAL_MPU_ConfigRegion(&MPU_InitStruct);
  /* Enables the MPU */
  HAL_MPU_Enable(MPU_HFNMI_PRIVDEF);
 
}

0 REPLIES 0