I have integrated FreeRTOS PlusTCP 10.2.0 with Atmel Cortex SAM4E Xplained Pro board.
I made a simple test program to send 400 bytes via UDP every 10ms (FreeRTOS tick rate is 1ms).
After some time (random) I got a cpu hard fault.
Debuging the problem, it seems to be related to network traffic and the release of the network buffers.
Monitoring how many times pvPortMalloc / vPortFree is being called, it seems the hard fault is asserted after pvPortMalloc is called more often than vPortFree.
For example, in this test program, during normal operation, debuging the difference between how many times pvPortMalloc and vPortFree were called I got the value of 16, but when the hard fault is asserted this difference increases for 17 or a higher value.
I can`t trace the root cause of the hard fault according to https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html, even trying the “Handling Imprecise Faults” method.
I have read many issues in this forum related to hard fault and high network traffic but could not solve the problem after trying to replicate some suggestions.
I have tried many different values for the #defines below but the hard fault continues, for example:
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 10
#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 10 )
#define ipconfigUSE_TCP_WIN ( 0 )
#define ipconfigNETWORK_MTU 586
#define ipconfigUSE_LINKED_RX_MESSAGES 1
#define ipconfigIGNORE_UNKNOWN_PACKETS ( 1 )
I am using BufferAllocation2 scheme with heap4.c with SAM4E internal SRAM (128KB) and with the following definitions:
#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 256 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 0x8000 ) )
The source code is on https://drive.google.com/open?id=1cUsO-uTJ5eKB4igAG8iQGBKVWVfvK34q
I will really really appreciate any suggestion about how to deal and solve this problem.
Thank you very much in advance!