Zynq Ultrascale+ with Freertos+TCP ends in tick tasks() if the size of the received message is to big

Hello everybody,

I have a Zynq Ultrascale + with a Freertos + TCP. I exchange messages with a PC via an ethernet interface. As a rule, the maximum data size does not exceed 512 bytes and it works without any problems. I try to send a 131090 byte message from the PC to the Zynq. For that I have increased the MSG_Generic_Maxsize in TCPMsgServer.h from 1024 to 150000 bytes. The journey ends in tasks.c() and remains there in a continuous loop until the connection is broken.

Here you can see the task in detail:

/* See if this tick has made a timeout expire. Tasks are stored in
the queue in the order of their wake time - meaning once one task
has been found whose block time has not expired there is no need to
look any further down the list. */

	if( xConstTickCount >= xNextTaskUnblockTime )
		for( ;; )
			if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )
				/* The delayed list is empty.  Set xNextTaskUnblockTime
				to the maximum possible value so it is extremely
				unlikely that the
				if( xTickCount >= xNextTaskUnblockTime ) test will pass
				next time through. */
				xNextTaskUnblockTime = portMAX_DELAY; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
				/* The delayed list is not empty, get the value of the
				item at the head of the delayed list.  This is the time
				at which the task at the head of the delayed list must
				be removed from the Blocked state. */
				pxTCB = listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */
				xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ) );

				if( xConstTickCount < xItemValue )
					/* It is not time to unblock this item yet, but the
					item value is the time at which the task at the head
					of the blocked list must be removed from the Blocked
					state -	so record the item value in
					xNextTaskUnblockTime. */
					xNextTaskUnblockTime = xItemValue;
					break; /*lint !e9011 Code structure here is deedmed easier to understand with multiple breaks. */

				/* It is time to remove the item from the Blocked state. */
				( void ) uxListRemove( &( pxTCB->xStateListItem ) );

				/* Is the task waiting on an event also?  If so remove
				it from the event list. */
				if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )
					( void ) uxListRemove( &( pxTCB->xEventListItem ) );

				/* Place the unblocked task into the appropriate ready
				list. */
				prvAddTaskToReadyList( pxTCB );

				/* A task being unblocked cannot cause an immediate
				context switch if preemption is turned off. */
				#if (  configUSE_PREEMPTION == 1 )
					/* Preemption is on, but a context switch should
					only be performed if the unblocked task has a
					priority that is equal to or higher than the
					currently executing task. */
					if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )
						xSwitchRequired = pdTRUE;
				#endif /* configUSE_PREEMPTION */

I debugged the whole thing to find the place where the error occurs.
In TCPMsgServer.c the Message receives. Than it goes down to the function ,FreeRTOS_recv()".
Then it switch to FreeRTOS_Sockets.c and goes down to function ,rxStreamBufferGet()". After that it switch to FreeRTOS_Stream_Buffer.c down to the first memcpy() function.
After this function the program is in the loop tasks.c descriped above.

I have changed the Tick per second from 100 to 10 but nothing happend.

Thank you very much and greetings,

Can you please post your FreeRTOSIPConfig.h file too.

If the issue shows itself when you call memcpy then it could be related to an older issue described in the " Important note for GCC (and possibly other compiler) users" section of this page: https://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html

You can try and provide your own version of memcpy(), but it is surprisingly hard to get GCC to use it as it recognises the pattern of a memcpy() function and replaces it with its own version. You can help avoid that by including the -fno-builtin compiler option.

Thanks for the feedback.
Here is the code for FreeRTOSIPConfig.h.



/* Prototype for the function used to print out.  In this case it prints to the
console before the network is connected then a UDP port after the network has
connected. */
extern void xil_printf( const char *pcFormatString, ... );

/* Set to 1 to print out debug messages.  If ipconfigHAS_DEBUG_PRINTF is set to
1 then FreeRTOS_debug_printf should be defined to the function used to print
out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF	1
#if( ipconfigHAS_DEBUG_PRINTF == 1 )
	#define FreeRTOS_debug_printf(X)	xil_printf X

/* Set to 1 to print out non debugging messages, for example the output of the
FreeRTOS_netstat() command, and ping replies.  If ipconfigHAS_PRINTF is set to 1
then FreeRTOS_printf should be set to the function used to print out the
messages. */
#define ipconfigHAS_PRINTF			1
#if( ipconfigHAS_PRINTF == 1 )
	#define FreeRTOS_printf(X)			xil_printf X

/* The following is an expert option. Use it on 64-bit platforms only.
Avery pucEthernetBuffer starts with 14 invisible bytes. They contain a
back-pointer to the owning 'NetworkBufferDescriptor_t'. */

#define ipconfigBUFFER_PADDING	( 12U + ipconfigPACKET_FILLER_SIZE )

/* Enabled sanity checks to call bIsValidNetworkDescriptor(). */
//#define ipconfigTCP_IP_SANITY    1

#define ipconfigUSE_CALLBACKS		1

/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
on).  Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */

/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM		( 1 )
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM		( 1 )

/* Several API's will block until the result is known, or the action has been
performed, for example FreeRTOS_send() and FreeRTOS_recv().  The timeouts can be
set per socket, using setsockopt().  If not set, the times below will be
used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME	( 5000 )
#define	ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME	( 5000 )

/* Include support for LLMNR: Link-local Multicast Name Resolution
(non-Microsoft) */
#define ipconfigUSE_LLMNR					( 0 )

/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
#define ipconfigUSE_NBNS					( 0 )

/* Include support for DNS caching.  For TCP, having a small DNS cache is very
useful.  When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
and also DNS may use small timeouts.  If a DNS reply comes in after the DNS
socket has been destroyed, the result will be stored into the cache.  The next
call to FreeRTOS_gethostbyname() will return immediately, without even creating
a socket. */
#define ipconfigUSE_DNS_CACHE				( 1 )
#define ipconfigDNS_CACHE_NAME_LENGTH		( 16 )
#define ipconfigDNS_CACHE_ENTRIES			( 4 )
#define ipconfigDNS_REQUEST_ATTEMPTS		( 2 )

/* The IP stack executes it its own task (although any application task can make
use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
sets the priority of the task that executes the IP stack.  The priority is a
standard FreeRTOS task priority so can take any value from 0 (the lowest
priority) to (configMAX_PRIORITIES - 1) (the highest priority).
configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
the priority assigned to the task executing the IP stack relative to the
priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY			( configMAX_PRIORITIES - 2 )

/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
task.  This setting is less important when the FreeRTOS Win32 simulator is used
as the Win32 simulator only stores a fixed amount of information on the task
stack.  FreeRTOS includes optional stack overflow detection, see:
http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
#define ipconfigIP_TASK_STACK_SIZE_WORDS	( configMINIMAL_STACK_SIZE * 5 )

/* ipconfigRAND32() is called by the IP stack to generate random numbers for
things such as a DHCP transaction number or initial sequence number.  Random
number generation is performed via this macro to allow applications to use their
own random number generation method.  For example, it might be possible to
generate a random number by sampling noise on an analogue input. */
extern UBaseType_t uxRand();
#define ipconfigRAND32()	uxRand()

/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
network event hook at the appropriate times.  If ipconfigUSE_NETWORK_EVENT_HOOK
is not set to 1 then the network event hook will never be called.  See
#define ipconfigUSE_NETWORK_EVENT_HOOK 1

/* Sockets have a send block time attribute.  If FreeRTOS_sendto() is called but
a network buffer cannot be obtained then the calling task is held in the Blocked
state (so other tasks can continue to executed) until either a network buffer
becomes available or the send block time expires.  If the send block time expires
then the send operation is aborted.  The maximum allowable send block time is
capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS.  Capping the
maximum allowable send block time prevents prevents a deadlock occurring when
all the network buffers are in use and the tasks that process (and subsequently
free) the network buffers are themselves blocked waiting for a network buffer.
ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks.  A time in
milliseconds can be converted to a time in ticks by dividing the time in
milliseconds by portTICK_PERIOD_MS. */
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000 / portTICK_PERIOD_MS )

/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
address, netmask, DNS server address and gateway address from a DHCP server.  If
ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address.  The
stack will revert to using the static IP address even when ipconfigUSE_DHCP is
set to 1 if a valid configuration cannot be obtained from a DHCP server for any
reason.  The static configuration used is that passed into the stack by the
FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP	( 0 )

/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
increasing time intervals until either a reply is received from a DHCP server
and accepted, or the interval between transmissions reaches
ipconfigMAXIMUM_DISCOVER_TX_PERIOD.  The IP stack will revert to using the
static IP address passed as a parameter to FreeRTOS_IPInit() if the
re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD		( 120000 / portTICK_PERIOD_MS )

/* The ARP cache is a table that maps IP addresses to MAC addresses.  The IP
stack can only send a UDP message to a remove IP address if it knowns the MAC
address associated with the IP address, or the MAC address of the router used to
contact the remote IP address.  When a UDP message is received from a remote IP
address the MAC address and IP address are added to the ARP cache.  When a UDP
message is sent to a remote IP address that does not already appear in the ARP
cache then the UDP message is replaced by a ARP message that solicits the
required MAC address information.  ipconfigARP_CACHE_ENTRIES defines the maximum
number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES		6

/* ARP requests that do not result in an ARP response will be re-transmitted a
maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )

/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
table being created or refreshed and the entry being removed because it is stale.
New ARP requests are sent for ARP cache entries that are nearing their maximum
age.  ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE			150

/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
routines, which are relatively large.  To save code space the full
FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
alternative called FreeRTOS_inet_addr_quick() is provided.  FreeRTOS_inet_addr()
takes an IP in decimal dot format (for example, "") as its parameter.
FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
(for example, 192, 168, 0, 1) as its parameters.  If
ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
FreeRTOS_indet_addr_quick() are available.  If ipconfigINCLUDE_FULL_INET_ADDR is
not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR	1

/* A FreeRTOS queue is used to send events from application tasks to the IP
stack.  ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
be queued for processing at any one time.  The event queue must be a minimum of
5 greater than the total number of network buffers. */

/* The address of a socket is the combination of its IP address and its port
number.  FreeRTOS_bind() is used to manually allocate a port number to a socket
(to 'bind' the socket to a port), but manual binding is not normally necessary
for client sockets (those sockets that initiate outgoing connections rather than
wait for incoming connections on a known port number).  If
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
stack automatically binding the socket to a port number from the range
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
on a socket that has not yet been bound will result in the send operation being
aborted. */

/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE		128
#define ipconfigTCP_TIME_TO_LIVE		255 /* also defined in FreeRTOSIPConfigDefaults.h */

/* USE_TCP: Use TCP and all its features */
#define ipconfigUSE_TCP				( 1 )

/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN			( 1 )

/* The MTU is the maximum number of bytes the payload of a network frame can
contain.  For normal Ethernet V2 frames the maximum MTU is 1500.  Setting a
lower value can save RAM, depending on the buffer management scheme used.  If
ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
be divisible by 8. */
//#define ipconfigNETWORK_MTU		1526U
#define ipconfigNETWORK_MTU		1526U

/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver.  DNS is used
through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS			1

/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS				1

/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS				0

/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
(and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION				1

/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
that are not in Ethernet II format will be dropped.  This option is included for
potential future IP stack developments. */

/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
responsibility of the Ethernet interface to filter out packets that are of no
interest.  If the Ethernet interface does not implement this functionality, then
set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
perform the filtering instead (it is much less efficient for the stack to do it
because the packet will already have been passed into the stack).  If the
Ethernet driver does all the necessary filtering in hardware then software
filtering can be removed by using a value other than 1 or 0. */

/* Advanced only: in order to access 32-bit fields in the IP packets with
32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits.
This has to do with the contents of the IP-packets: all 32-bit fields are
32-bit-aligned, plus 16-bit(!) */
#define ipconfigPACKET_FILLER_SIZE 2

/* Define the size of the pool of TCP window descriptors.  On the average, each
TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
outstanding packets (for Rx and Tx).  When using up to 10 TP sockets
simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT		240

/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
maximum size.  Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH			( 150 * ipconfigTCP_MSS  )

/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH			( 150 * ipconfigTCP_MSS  )

/* When using call-back handlers, the driver may check if the handler points to
real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL )

/* Include support for TCP hang protection.  All sockets in a connecting or
disconnecting stage will timeout after a period of non-activity. */
#define ipconfigTCP_HANG_PROTECTION			( 1 )
#define ipconfigTCP_HANG_PROTECTION_TIME	( 30 )

/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE				( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL		( 20 ) /* in seconds */

#define portINLINE __inline

#define ipconfigNIC_N_TX_DESC ( 100 )
#define ipconfigNIC_N_RX_DESC ( 1000 )

/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
are available to the IP stack.  The total number of network buffers is limited
to ensure the total amount of RAM that can be consumed by the IP stack is capped
to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS		( ipconfigNIC_N_RX_DESC + ipconfigNIC_N_TX_DESC + 40U )

#define ipconfigZERO_COPY_RX_DRIVER		1
#define ipconfigZERO_COPY_TX_DRIVER		1

//#define ipconfigNIC_LINKSPEED100						1
#define ipconfigULTRASCALE						1

#define ipconfigIPERF_VERSION					3

#define ipconfigIPERF_STACK_SIZE_IPERF_TASK		680

#define ipconfigIPERF_HAS_UDP					0
#define ipconfigIPERF_DOES_ECHO_UDP				0

//#define ipconfigIPERF_TX_WINSIZE                ( 10 )
//#define ipconfigIPERF_TX_BUFSIZE                ( 20 * ipconfigTCP_MSS )
//#define ipconfigIPERF_RX_WINSIZE                ( 10 )
//#define ipconfigIPERF_RX_BUFSIZE                ( 20 * ipconfigTCP_MSS )

//#define ipconfigIPERF_TX_WINSIZE                ( 16 )
//#define ipconfigIPERF_TX_BUFSIZE                ( 32 * ipconfigTCP_MSS )
//#define ipconfigIPERF_RX_WINSIZE                ( 16 )
//#define ipconfigIPERF_RX_BUFSIZE                ( 32 * ipconfigTCP_MSS )
///* The iperf module declares a character buffer to store its send data. */
//#define ipconfigIPERF_RECV_BUFFER_SIZE			( 64 * ipconfigTCP_MSS )

#define ipconfigHTTP_TX_BUFSIZE				( 256 * 1024 )
#define ipconfigHTTP_TX_WINSIZE				( 8 )
#define ipconfigHTTP_RX_BUFSIZE				( 256 * 1024 )
#define ipconfigHTTP_RX_WINSIZE				( 12 )

#define ipconfigIPERF_TX_BUFSIZE                ( 4*24 * ipconfigTCP_MSS )
#define ipconfigIPERF_TX_WINSIZE                ( 4*12 )
#define ipconfigIPERF_RX_BUFSIZE                ( 4*24 * ipconfigTCP_MSS )
#define ipconfigIPERF_RX_WINSIZE                ( 4*12 )
/* The iperf module declares a character buffer to store its send data. */
#define ipconfigIPERF_RECV_BUFFER_SIZE               ( 4* 2 * 24 * ipconfigTCP_MSS )

/****** UDP logging settings. *************************************************/

/* If set to 1 then each message sent via the UDP logging facility will end
with \r\n.  If set to 0 then each message sent via the UDP logging facility will
end with \n. */
#define configUDP_LOGGING_NEEDS_CR_LF  ( 0 )

/* Sets the maximum length for a string sent via the UDP logging facility. */
#define configUDP_LOGGING_STRING_LENGTH	( 200 )

/* The UDP logging facility buffers messages until the UDP logging task is able
to transmit them.  configUDP_LOGGING_MAX_MESSAGES_IN_BUFFER sets the maximum
number of messages that can be buffered at any one time. */

/* The UDP logging facility creates a task to send buffered messages to the UDP
port.  configUDP_LOGGING_TASK_STACK_SIZE sets the task's stack size. */
#define	configUDP_LOGGING_TASK_STACK_SIZE  	( 512 )

/* The UDP logging facility creates a task to send buffered messages to the UDP
port.  configUDP_LOGGING_TASK_PRIORITY sets the task's priority.  It is
suggested to give the task a low priority to ensure it does not adversely effect
the performance of other TCP/IP stack activity. */
#define configUDP_LOGGING_TASK_PRIORITY   	( tskIDLE_PRIORITY  + 2 )

/* The UDP port to which the UDP logging facility sends messages. */
#define configUDP_LOGGING_PORT_REMOTE		2403

/* The local UDP port to which commands can be sent. */
#define configUDP_LOGGING_PORT_LOCAL		2402



Thanks for help,

Update i have include the -fno-builtin in the compiler option, it shows no effects.

Johannes, if you think that memcpy() is causing problems, you might try this version of memcpy.
Some versions of memcpy() use wide registers from an FPU. I my case that led to a crash.
A second problem I had with Ultrascale was with an ellipsis function for printing:

int lUDPLoggingPrintf( const char *pcFormatString, ... );

It would copy 300 bytes from the stack to FPU registers!

And PS, the full compiler option that I often use is: -fno-builtin-memcpy -fno-builtin-memset
In some cases, my compiler did a 32-bit copy to an unaligned address, thus causing a crash.

Hey Johannes, back to your original question.

I have increased the MSG_Generic_Maxsize in TCPMsgServer.h from 1024 to 150000 bytes

Can I find a copy of that software somewhere?

The journey ends in tasks.c()

That doesn’t say much. When all tasks are blocked, a break will always show the idle task doing almost nothing.

I have changed the Tick per second from 100 to 10 but nothing happend.

As you have a very fast CPU, I recommend to set configTICK_RATE_HZ at 1000.

But maybe you can show the TCP code that you use? And if it has private details, you can also send it privately.