andylong0206 wrote on March 12, 2018:
Hi Sarena,
After much pulling hair out I’ve found the issue. In the demo project, the compiler optimization level is set to 1. My project is 0. If you change the demo project to 0, it will crash within a few minutes.
Now for the reason and the solution. During compilation you will see the following warnings:
…/…/…/…/lib/FreeRTOS-Plus-TCP/source/portable/NetworkInterface/pic32mzef/NetworkInterface_wifi.c: In function ‘xNetworkFrameReceived’:
…/…/…/…/lib/FreeRTOS-Plus-TCP/source/portable/NetworkInterface/pic32mzef/NetworkInterface_wifi.c:174:15: warning: ‘pxNetworkBuffer’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if( pxNetworkBuffer != 0 )
^
and
…/…/…/common/logging/aws_logging_task_dynamic_buffers.c: In function ‘vLoggingPrintf’:
…/…/…/common/logging/aws_logging_task_dynamic_buffers.c:188:29: warning: ‘xLength’ may be used uninitialized in this function [-Wmaybe-uninitialized]
The first being the critical warning and the cause.
Changing the code in NetworkInterface_wifi.c from:
void xNetworkFrameReceived( uint32_t len,
uint8_t const * const frame )
{
bool pktSuccess, pktLost;
NetworkBufferDescriptor_t * pxNetworkBuffer;
IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
pktSuccess = pktLost = false;
...
To:
void xNetworkFrameReceived( uint32_t len,
uint8_t const * const frame )
{
bool pktSuccess, pktLost;
NetworkBufferDescriptor_t * pxNetworkBuffer = NULL;
IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
pktSuccess = pktLost = false;
...
Now NO warning and NO crash!!!
I believe not initializing variables, especially pointers is not good practice and can cause some weird issues at compiler optimization level as in this case. Different compilers handle this differently so for consistency initialization is the best way.
I hope this helps everyone.
Andy