FreeRTOS_send stuck in hardfault (when calling listRemove_item) but it used to work perfectly [FIXED]

Hello,

I was writing this question but figured out the solution while writing it. But I think it could be nice to still keep this post up in case someone had the same issue as me. Also, the questions I ask in the question section are still relevant.
Basicaly, the FreeRTOS-send function would not complete and put me in a hardfault half the time. I fixed it by putting my TCP task at the highest priority.
Before, it was at the lowest priority because I started with the createTcpSocket exemple (TCP Networking Tutorial - Creating, Configuring and Binding TCP Client and Server Sockets) which sets the priority as idleTask (0) because the task should only run once but mine runs constantly as it does the socket creation, binding, conencting, sending and soon receiving.

Find below the post I was about to publish.

Summary:

  • Abstract
  • Environnement
  • Previous posts
  • What I want to do
  • What I have done
  • What my problem is
  • Trying to fix : debugging
  • Trying to fix : looking online
  • Questions
  • Code sample

##### ABSTRACT #####
My project used to work perfectly, I was sending TCP messages from an STM32 to a Rapsberry pi. One day I bring my profesionnal laptop home. The next day at work, the project that worked last day doesn’t work anymore. I debug it, when the function FreeRTOS_send is called, it calls the function listRemove_item which puts me in a hardfault.

##### ENVIRONMENT #####
Card : STM32H723ZG
PC : Computer with Windows 10
IDE : stm32cubeIDE
Compiler : GCC 9.2.0
FreeRTOS : 202212.01

##### PREVIOUS POSTS #####

##### WHAT I WANT TO DO #####
I want to send TCP messages from the STM32 (client) to the Raspberry pi (server) receiving them in python.

##### What I have done #####
A server in Python that receives the data (encoded in protobuf) and display them.

A client for the STM32 that contains 2 tasks:

  • The sensor task that fetch the data from the sensor, puts them in a global uint8_t array then resume the TCP task.
  • The TCP task that waits to get resumed, then fill in a buffer with the data of the uint8_t array, encodes this data in protobuf using nanopb, sends the encoded message through TCP using FreeRTOS_send function and finaly suspends itself.

##### What my problem is #####
One day I bring my profesionnal laptop home.
The next day at work, the project that worked last day doesn’t work anymore.
When I run it, initialisation seems good, I am able to connect to the server.
But when I try to send, I get stuck in a hardfault.
Sometimes it still works but it’s completely random it seems. Also, I resume the tasks every second and once I was able to send data for 4 loops but then got stuck.

##### TRYING TO FIX : DEBUGGING #####
When debugging, I figured the error occured during the send function:

Right before entering the send function everything seems fine, so I click on step into to get to the first line of the send function :

But when I step into, I don’t jump to the first line of the function but ends up in a hardfault :

I click on the PC to see what caused the hard fault and ends up on the line calling the funtion listREMOVE_ITEM :

Here is the prints I get when I get stuck in the send function (note that the lines starting by “GG” are the ones I added) :

GG : Init successful, starting scheduler. (main.c)
prvIPTask started
PHY ID 7C130
xPhyReset: phyBMCR_RESET 0 ready
+TCP: advertise: 01E1 config 3100
prvEthernetUpdateConfig: LS mask 00 Force 1
Autonego ready: 00000004: full duplex 100 mbit high status
Network buffers: 56 lowest 56
Link Status is high
prvInitialiseDHCP: start after 250 ticks
vDHCPProcess: discover
Network buffers: 56 lowest 55
RX descriptors 7/8
vDHCPProcess: offer a012364ip
vDHCPProcess: reply a012364ip
vDHCPProcess: offer a012364ip
vDHCPProcess: acked a012364ip


IP Address: 10.1.35.100
Subnet Mask: 255.255.255.0
Gateway Address: 10.1.35.254
DNS Client Address: 192.168.73.220


        GG : Entered vCreateTCPClientSocket with GG_CLIENT_TEST value of 2. (main.c)
FreeRTOS_connect: 585 to a012394ip:50053
ARP for a012394ip (using a012394ip): rc=0 00:00:00 00:00:00
Conn: current 19688d lowest 19688d
                                  out 1: 500 ms
prvSocketSetMSS: 536 bytes for a012394ip:50053
Connect[a012394ip:50053]: next timeout 1: 3000 ms
MSS change 536 -> 1460
GG : IsSocketConnected returned true.
GG : Connected. (main.c)

Thermi :416
[092, 091, 092, 094, 095, 092, 093, 095],
[092, 094, 093, 092, 093, 095, 095, 095],
[091, 094, 093, 093, 095, 093, 095, 095],
[093, 092, 092, 093, 096, 094, 093, 094],
[091, 093, 092, 093, 095, 094, 096, 094],
[095, 096, 096, 094, 095, 093, 093, 094],
[094, 094, 098, 092, 093, 095, 093, 098],
[092, 095, 096, 092, 094, 092, 094, 094]


Thermi :416
[092, 093, 094, 093, 094, 094, 096, 096],
[092, 093, 093, 094, 093, 095, 096, 093],
[092, 094, 092, 093, 093, 093, 096, 095],
[093, 095, 093, 094, 094, 094, 093, 094],
[093, 092, 092, 092, 095, 094, 095, 093],
[094, 094, 095, 094, 095, 093, 094, 095],
[093, 094, 098, 091, 092, 094, 092, 096],
[091, 093, 094, 092, 091, 092, 093, 094]


GG : Starting send. (main.c)

Here is the prints I get when I am able to send the datas for the first 5 times but then get stuck the next second when I try to send the newly fetched datas :

GG : Init successful, starting scheduler. (main.c)
prvIPTask started
PHY ID 7C130
xPhyReset: phyBMCR_RESET 0 ready
+TCP: advertise: 01E1 config 3100
prvEthernetUpdateConfig: LS mask 00 Force 1
Autonego ready: 00000004: full duplex 100 mbit high status
Network buffers: 56 lowest 56
Link Status is high
prvInitialiseDHCP: start after 250 ticks
vDHCPProcess: discover
Network buffers: 56 lowest 55
RX descriptors 7/8
vDHCPProcess: offer a012364ip
vDHCPProcess: reply a012364ip
vDHCPProcess: offer a012364ip
vDHCPProcess: acked a012364ip


IP Address: 10.1.35.100
Subnet Mask: 255.255.255.0
Gateway Address: 10.1.35.254
DNS Client Address: 192.168.73.220


        GG : Entered vCreateTCPClientSocket with GG_CLIENT_TEST value of 2. (main.c)
FreeRTOS_connect: 585 to a012394ip:50053
ARP for a012394ip (using a012394ip): rc=0 00:00:00 00:00:00
Conn: current 19688d lowest 19688d
                                  out 1: 500 ms
prvSocketSetMSS: 536 bytes for a012394ip:50053
Connect[a012394ip:50053]: next timeout 1: 3000 ms
MSS change 536 -> 1460
GG : IsSocketConnected returned true.
GG : Connected. (main.c)

Thermi :421
[093, 094, 093, 094, 095, 094, 095, 094],
[093, 095, 093, 094, 093, 094, 094, 096],
[093, 095, 093, 094, 093, 093, 094, 096],
[094, 094, 094, 094, 095, 096, 096, 095],
[094, 091, 092, 094, 096, 094, 095, 094],
[094, 096, 095, 095, 094, 093, 093, 095],
[093, 095, 100, 094, 094, 096, 092, 098],
[091, 094, 096, 091, 093, 093, 092, 095]


Thermi :421
[092, 094, 093, 093, 093, 093, 094, 092],
[095, 093, 094, 094, 094, 094, 093, 094],
[092, 093, 093, 094, 095, 096, 094, 096],
[094, 093, 094, 095, 095, 095, 095, 094],
[093, 093, 092, 094, 095, 094, 095, 093],
[094, 095, 096, 094, 095, 093, 095, 094],
[094, 096, 097, 092, 094, 095, 094, 096],
[091, 096, 096, 094, 093, 093, 097, 093]


GG : Starting send. (main.c)

Thermi :420
[091, 093, 093, 094, 094, 092, 093, 093],
[092, 092, 091, 093, 092, 095, 093, 093],
[090, 092, 093, 092, 094, 095, 093, 094],
[095, 094, 094, 094, 093, 095, 096, 093],
[093, 093, 093, 092, 095, 093, 094, 095],
[096, 095, 095, 094, 096, 091, 094, 092],
[091, 093, 098, 092, 093, 093, 091, 095],
[090, 093, 095, 092, 094, 094, 092, 092]


GG : Starting send. (main.c)

Thermi :420
[091, 094, 094, 095, 094, 094, 094, 095],
[094, 093, 094, 094, 092, 095, 095, 094],
[093, 094, 093, 093, 094, 094, 096, 096],
[095, 094, 094, 093, 096, 095, 096, 093],
[094, 093, 092, 094, 095, 094, 095, 094],
[094, 095, 096, 096, 095, 092, 094, 095],
[094, 095, 099, 093, 094, 095, 091, 095],
[093, 094, 095, 093, 094, 095, 095, 095]


GG : Starting send. (main.c)

Thermi :420
[093, 093, 091, 094, 095, 095, 097, 096],
[094, 094, 095, 094, 095, 094, 095, 095],
[091, 093, 093, 093, 094, 094, 096, 098],
[093, 095, 094, 094, 097, 095, 095, 096],
[094, 093, 092, 095, 095, 094, 094, 094],
[093, 094, 097, 095, 095, 093, 095, 096],
[094, 094, 099, 092, 094, 095, 093, 097],
[093, 096, 096, 093, 093, 096, 091, 094]


GG : Starting send. (main.c)

Thermi :420
[091, 094, 092, 092, 095, 093, 096, 095],
[092, 095, 093, 094, 094, 095, 095, 095],
[090, 094, 094, 092, 094, 094, 095, 096],
[094, 094, 093, 094, 095, 095, 093, 095],
[094, 095, 094, 094, 095, 094, 096, 094],
[095, 096, 094, 096, 094, 093, 094, 095],
[094, 093, 098, 092, 093, 095, 092, 096],
[093, 095, 094, 094, 092, 094, 091, 094]


GG : Starting send. (main.c)

Thermi :420
[123, 124, 117, 101, 101, 098, 099, 097],
[123, 124, 108, 099, 097, 099, 096, 098],
[125, 120, 102, 098, 097, 097, 099, 099],
[124, 116, 100, 100, 097, 098, 098, 098],
[124, 115, 100, 097, 098, 095, 096, 095],
[125, 118, 100, 098, 097, 096, 095, 096],
[124, 120, 106, 097, 096, 096, 096, 099],
[112, 118, 103, 098, 096, 097, 096, 095]


GG : Starting send. (main.c)

##### TRYING TO FIX : LOOKING ONLINE #####
I have tried to google my issue.

Some people say it is due to a stackoverflow (Crash to hard fault handler after sending data to queue that is blocked on - #3 by makas005) but he doesn’t explain how he fixed his issue.

I tried to enable vApplicationStackOverflowHook with “#define configCHECK_FOR_STACK_OVERFLOW 1” in the config file but then I need to implement the function itself which is mentionned here (FreeRTOS - stacks and stack overflow checking) yet I am not sure chat I am supposed to do.
I also tried to increase the allocated stack size for that task but without success.

This person also had issues setting up that hook Help me to make this link error "vApplicationStackOverflowHook - FreeRTOS but the answer doesn’t help me understand what I am expected to do.

Fianly, this post seems to be very clsoe to what I am experiencing : uxListRemove gives a hardfault: IMPRECISERR however I am not able to answer to the concerned brought by Gaurav “Where is RxBuffer defined?” and “Could this be overflowing” on post #6.

##### Extra informations #####
I tried creating a new workspace.
At home, I did not run the project, I just connected to the wifi and had a video call.
Sometimes, the print telling me that I started the function send doesn’t print, sometimes it doesnt’ print completely.
The sensor task has higher priority than the TCP task but I tried to switch priorities level without change in behav… Nevermind, it fixed the issue even though I wonder if that the cleanest way of doing that.

##### Question #####
What is causing this random behavior?
What actions could I take to try to resolve my issue?
How to implement the stackoverflow hook?

##### Code sample #####
Most important functions of the main.c :

/* Standard includes. */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <ctype.h>

/* cubeMX/HAL includes */
#include "main.h"
#include "string.h"

/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "queue.h"
#include "semphr.h"

/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkBufferManagement.h"
#include "NetworkInterface.h"
#include "phyHandling.h"
#if( ipconfigMULTI_INTERFACE != 0 )
	#include "FreeRTOS_Routing.h"
	#include "FreeRTOS_ND.h"
#endif

/* nanopb includes */
#include "pb.h"
#include "pb_common.h"
#include "pb_encode.h"
#include "pb_decode.h"
#include "protoArray484Nanopb41.pb.h"			//the proto generated file

/* Macro to check if socket is bound, copy pasted from FreeRTOS_Socket.c */
#define socketSOCKET_IS_BOUND( pxSocket )            ( listLIST_ITEM_CONTAINER( &( pxSocket )->xBoundSocketListItem ) != NULL )

#define usUsedStackSize 128
#define BUFFER_SIZE 512

/* cube mx generated handler */
ETH_HandleTypeDef heth;
UART_HandleTypeDef huart3;
ETH_TxPacketConfig TxConfig;
I2C_HandleTypeDef hi2c2;

/* i2c address of the sensor */
static const uint8_t sensorAddress = 0x69 << 1; //address of the sensor

/* The MAC address array is not declared const as the MAC address will
normally be read from an EEPROM and not hard coded (in real deployed applications).*/
static uint8_t ucMACAddress[ 6 ] = { 0x00, 0x80, 0xE1, 0x00, 0x00, 0x00 };

/* Define the network addressing.  These parameters will be used if either
ipconfigUDE_DHCP is 0 or if ipconfigUSE_DHCP is 1 but DHCP auto configuration failed. */
static const uint8_t ucIPAddress[ 4 ];
static const uint8_t ucNetMask[ 4 ];
static const uint8_t ucGatewayAddress[ 4 ];

/* The following is the address of the DNS client. */
static const uint8_t ucDNSClientAddress[ 4 ] = { 192, 168, 73, 220 };

/* Random Number Generator variable. */
static RNG_HandleTypeDef hrng;

/* cube MX generated function definitions */
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_USB_OTG_HS_USB_Init(void);
static void MX_RNG_Init(void);
static void MX_I2C2_Init(void);

/* TCP function definition */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent );
BaseType_t xApplicationGetRandomNumber( uint32_t *pulValue );
void prvClientConnectToServer(Socket_t *xSocket);
void prvClientSendData(Socket_t* xSocket);
void vTCPSend(void);

/* TCP task function definitions (the ones that do tcp thing */
static void vCreateTCPClientSocket(void *pvParameters);

/* Byte functions for sensor*/
uint8_t byteFetchSingleRegisterData (uint16_t startRegister, uint8_t* buffer);
void byteFetchSensorData (uint16_t startRegister, uint8_t* array, uint8_t* buffer);
void byteDataMinus60(uint8_t* array);
void bytePrintArray(uint8_t* array, int n, int m, uint8_t* buffer);
void bytePrintArrayValue(uint8_t* array, int n, int m, uint8_t* buffer);
void byteInterpolateXTimes(uint8_t* dataIn, int n, int m, int ratio, uint8_t* dataOut);
uint16_t fetchDoubleRegisterData (uint16_t startRegister, uint8_t* buffer);

/* Handle task */
TaskHandle_t xSensorDataHandle;
TaskHandle_t xCreateSocketHandle;

/* Declaration function */
void vSensorDataTask(void *pvParameters);

/* Global variable */
uint8_t byteInterpo[484] = {[0 ... 483] = 3};	// Valid only for gcc based compilers

int main(void)
{
	/* cube mx init */
	HAL_Init();
	SystemClock_Config();
	MX_GPIO_Init();
	MX_USART3_UART_Init();
	MX_USB_OTG_HS_USB_Init();
	MX_I2C2_Init();
  
    /*Rng init*/
	MX_RNG_Init();

	/* TCP init */
	FreeRTOS_IPInit(ucIPAddress,
	                ucNetMask,
	                ucGatewayAddress,
	                ucDNSClientAddress,
	                ucMACAddress );

	/* task creation */
	NVIC_EnableIRQ(ETH_IRQn);
	NVIC_SetPriority(ETH_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
	/* sensor task */
	xTaskCreate(vSensorDataTask, "Sensor task", 128, NULL, 1, &xSensorDataHandle);

	/* starting rtos scheduler */
	FreeRTOS_printf( ( "\033[2J") );	/* Clean putty */
	FreeRTOS_printf( ( "\r\nGG : Init successful, starting scheduler. (main.c)\r\n") );

	vTaskStartScheduler();
}


/* User task definition */
void vSensorDataTask(void *pvParameters)
{
	uint8_t buffer[20];
	uint16_t thermistorVal;
	uint8_t byteData[64];
	//uint8_t* byteInterpo;
	//byteInterpo = (uint8_t *) pvParameters;
	TickType_t xLastWakeTime;

	vTaskSuspend(xSensorDataHandle);

	for (int i=0; i<1000; ++i)
	{
		xLastWakeTime = xTaskGetTickCount(); /* source : freertos.org/vtaskdelayuntil.html */

		//Print thermistor value
		/*
		thermistorVal = fetchDoubleRegisterData (0x0E, buffer);
		sprintf((char*)buffer, "\nThermi :%u\r\n",  thermistorVal);
		HAL_UART_Transmit(&huart3, buffer, strlen((char*)buffer), HAL_MAX_DELAY);
		*/

		//print byte array
		byteFetchSensorData(0x80, byteData, buffer);
		//bytePrintArrayValue(byteData, 8, 8, buffer);
		byteInterpolateXTimes(byteData, 8, 8, 3, byteInterpo);

		/* Resume TCP task to send byte array */
		vTaskResume(xCreateSocketHandle);

		/* Delay */
		vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(100));
	}
	for(;;);
}

static void vCreateTCPClientSocket(void *pvParameters)
{
	/* Variables */
	Socket_t xSocket;																	/* The server socket */
	struct freertos_sockaddr xRemoteAddress, xClient;									/* Address of client and remote server */
	socklen_t xSize = sizeof( xClient );												/* The size of a sockaddr, used in bind function */
	BaseType_t xAlreadyTransmitted = 0, xBytesSent = 0;									/* The size already sent */
	size_t xLenToSend;																	/* The lenght to sent for each packet */
	uint8_t nanopbBuffer[600] = {[0 ... 599] = 0};										/* Buffer to encode in protoc using nanopb */
	protoMsg nanopbMessage = protoMsg_init_zero;										/* The nanopb structure for the message */
	int cnt = 0;

	FreeRTOS_printf(("\tGG : Entered vCreateTCPClientSocket with GG_CLIENT_TEST value of 2. (main.c)\r\n"));

	for(;;)
	{
		/* Set the IP address and port of the remote socket to which this client socket will transmit. */
		xRemoteAddress.sin_port = FreeRTOS_htons(50053);
		xRemoteAddress.sin_addr = FreeRTOS_inet_addr_quick(10, 1, 35, 148);

		/* Create a socket. */
		xSocket = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP);
		configASSERT(xSocket != FREERTOS_INVALID_SOCKET);

		/* Binding (not necessary) */
		xClient.sin_port = FreeRTOS_htons(585);	// en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
		FreeRTOS_bind(xSocket, &xClient, xSize);

		//Connect to the remote socket.  The socket has not previously been bound to a local port number so will get automatically bound.
		if( FreeRTOS_connect(xSocket, &xRemoteAddress, sizeof(xRemoteAddress)) == 0)
		{
			FreeRTOS_printf(("GG : Connected. (main.c)\r\n"));
			vTaskResume(xSensorDataHandle);

			for(;;)
			{
				vTaskSuspend(xCreateSocketHandle);
				pb_ostream_t stream = pb_ostream_from_buffer(nanopbBuffer, sizeof(nanopbBuffer));	/* nanopb stream */

				/* Update with new values and encode using nanopb */
				for(int i=0; i<484; ++i){	/* Fill data */
					nanopbMessage.pixel[i] = byteInterpo[i];}
				pb_encode(&stream, protoMsg_fields, &nanopbMessage);	/* Encode in proto using nanopb */

				/* Reset variables for the send function */
				xAlreadyTransmitted = 0;
				xBytesSent = 0;

				/* Sending data */
				FreeRTOS_printf(("\nGG : Starting send %d. (main.c)\r\n", cnt));
				while(xAlreadyTransmitted < stream.bytes_written) 				/* Keep sending until the entire buffer has been sent. */
				{
					xLenToSend = stream.bytes_written - xAlreadyTransmitted; 	/* How many bytes are left to send? */

					xBytesSent = FreeRTOS_send(xSocket, &(nanopbBuffer[xAlreadyTransmitted]), xLenToSend, 0);

					if(xBytesSent >= 0) xAlreadyTransmitted += xBytesSent;
					else break;
				}
				FreeRTOS_printf(("GG : Finished send. (main.c)\r\n"));
				++cnt;
			}
		}
		else FreeRTOS_printf(("GG : Couldn't connect. (main.c)\r\n"));

		/* Initiate graceful shutdown. */
		FreeRTOS_printf(("\nGG : Disconnecting. (main.c)\r\n"));
		FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR );

		/* Wait for the socket to disconnect gracefully before closing the socket. */
		/*
		while(FreeRTOS_recv(xSocket, nanopbBuffer, stream.bytes_written, 0) >= 0)
		{
			vTaskDelay(pdMS_TO_TICKS(250)); // Wait for shutdown to complete.
			// Note - real applications should implement a timeout here, not just loop forever.
		}
		*/

		/* The socket has shut down and is safe to close. */
		FreeRTOS_closesocket(xSocket);
	} //end for(;;)
}

void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
  static BaseType_t xTasksAlreadyCreated = pdFALSE;
  uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSClientAddress;
  char cBuffer[ 16 ];

    /* Both eNetworkUp and eNetworkDown events can be processed here. */
    if( eNetworkEvent == eNetworkUp )
    {
        /* Create the tasks that use the TCP/IP stack if they have not already
        been created. */
        if( xTasksAlreadyCreated == pdFALSE )
        {
            /*
             * For convenience, tasks that use FreeRTOS-Plus-TCP can be created here
             * to ensure they are not created before the network is usable.
             */
        	xTaskCreate(vCreateTCPClientSocket,
        	            "clientSocket",
        	            usUsedStackSize,	/* double stack size because I ran into hard fault that could be related to stackoverflow */
        	            NULL,
        	            /*tskIDLE_PRIORITY*/ 4,
						&xCreateSocketHandle);

            xTasksAlreadyCreated = pdTRUE;
            //xIPTaskInitialised = pdTRUE;
        }

        FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSClientAddress );

        FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
        FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );

        FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
        FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) );

        FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
        FreeRTOS_printf( ( "Gateway Address: %s\r\n", cBuffer ) );

        FreeRTOS_inet_ntoa( ulDNSClientAddress, cBuffer );
        FreeRTOS_printf( ( "DNS Client Address: %s\r\n\r\n\r\n", cBuffer ) );
    }
}

FreeRTOSConfig.h :

/*
 * FreeRTOS V202212.01
 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * https://www.FreeRTOS.org
 * https://github.com/FreeRTOS
 *
 */


/* The following #error directive is to remind users that a batch file must be
 * executed prior to this project being built.  The batch file *cannot* be
 * executed from within CCS4!  Once it has been executed, re-open or refresh
 * the CCS4 project and remove the #error line below.
 */
//#error Ensure CreateProjectDirectoryStructure.bat has been executed before building.  See comment immediately above.


#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * These definitions should be adjusted for your particular hardware and
 * application requirements.
 *
 * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
 * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
 *
 * See http://www.freertos.org/a00110.html
 *----------------------------------------------------------*/

#define configUSE_PREEMPTION					1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION	1
#define configUSE_QUEUE_SETS					1
#define configUSE_IDLE_HOOK						0
#define configUSE_TICK_HOOK						0
#define configCPU_CLOCK_HZ						( 550000000UL )
#define configTICK_RATE_HZ						( 1000 )
#define configMAX_PRIORITIES					( 5 )
#define configMINIMAL_STACK_SIZE				( ( unsigned short ) 512 )
#define configTOTAL_HEAP_SIZE					( ( size_t ) ( 60 * 1024 ) )
#define configMAX_TASK_NAME_LEN					( 10 )
#define configUSE_TRACE_FACILITY				1
#define configUSE_16_BIT_TICKS					0
#define configIDLE_SHOULD_YIELD					1
#define configUSE_MUTEXES						1
#define configQUEUE_REGISTRY_SIZE				8
#define configCHECK_FOR_STACK_OVERFLOW			0
#define configUSE_RECURSIVE_MUTEXES				1
#define configUSE_MALLOC_FAILED_HOOK			0
#define configUSE_APPLICATION_TASK_TAG			0
#define configUSE_COUNTING_SEMAPHORES			1

#define configUSE_TICKLESS_IDLE					0

/* Run time stats gathering definitions. */
#define configGENERATE_RUN_TIME_STATS			0

#define configUSE_STATS_FORMATTING_FUNCTIONS	1

/* Software timer definitions. */
#define configUSE_TIMERS				1
#define configTIMER_TASK_PRIORITY		( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH		5
#define configTIMER_TASK_STACK_DEPTH	( configMINIMAL_STACK_SIZE * 2 )

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet		1
#define INCLUDE_uxTaskPriorityGet		1
#define INCLUDE_vTaskDelete				1
#define INCLUDE_vTaskCleanUpResources	1
#define INCLUDE_vTaskSuspend			1
#define INCLUDE_vTaskDelayUntil			1
#define INCLUDE_vTaskDelay				1
#define INCLUDE_eTaskGetState			1
#define INCLUDE_xTimerPendFunctionCall	1

/* Use the system definition, if there is one */
#ifdef __NVIC_PRIO_BITS
	/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
	#define configPRIO_BITS       		__NVIC_PRIO_BITS
#else
	#define configPRIO_BITS       		4        /* 15 priority levels */
#endif

#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY			15
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY	4

/* The lowest priority. */
#define configKERNEL_INTERRUPT_PRIORITY 	( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Priority 5, or 95 as only the top four bits are implemented. */
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

#endif /* FREERTOS_CONFIG_H */

FreeRTOSIPConfig.h :

#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H

#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN

//	My own config
#define configUSE_TIME_SLICING						1	//allow 2 task tu run simultaneously if they have the same priority
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS      64	//a small number, idk how small...
#define ipconfigUSE_NETWORK_EVENT_HOOK 				1	// If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the network event hook at the appropriate times
#define ipconfigZERO_COPY_RX_DRIVER                 1
#define ipconfigZERO_COPY_TX_DRIVER                 1
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM		1
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM		1
#define ipconfigUSE_NETWORK_EVENT_HOOK 				1
#define ipconfigDNS_USE_CALLBACKS					1
#define ipconfigDNS_CACHE_NAME_LENGTH				20
#define ipconfigUSE_TCP								1	//if 0, use UDP by default
#define ipconfigTCP_KEEP_ALIVE						0	//If FreeRTOS-Plus-TCP does not receive a reply to a keep alive message then the connection will be broken
#define ipconfigTCP_HANG_PROTECTION					1	//will mark a socket as closed if there is no status change on the socket
#define ipconfigTCP_HANG_PROTECTION_TIME			60	//within the period of time specified in seconds
#define ipconfigUSE_TCP_WIN       					0	//If you have a tiny CPU with less than 64KB of RAM, do not use sliding Windows
//define below based on freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration_Examples.html
#define ipconfigTCP_TX_BUFFER_LENGTH   				( 2 * ipconfigTCP_MSS )
#define ipconfigTCP_RX_BUFFER_LENGTH   				( 2 * ipconfigTCP_MSS )
#define ipconfigNETWORK_MTU   						586
#define ipconfigTCP_MSS       						522
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND		1	// Should allow freertos to select a working port if no one is given

#define ipconfigHAS_PRINTF 1
#define FreeRTOS_debug_printf( x ) printf x
#define FreeRTOS_printf( x ) printf x
#endif /* FREERTOS_IP_CONFIG_H */
1 Like

Thank for taking time to create the detailed post.