alager12345 wrote on Tuesday, March 05, 2019:
I’m using BufferAllocation_1.c in an LPC1788 project. After some random time, I get an assert error in pxDuplicateNetworkBufferWithDescriptor()
. It looks like sometimes pxGetNetworkBufferWithDescriptor()
will return a valid buffer but the pointer inside that points to pucEthernetBuffer
is NULL
. This case is not checked, and so the memcpy asserts a hard fault.
I’ve turned on some debugging which shows the gets and puts, and it can be seen that the pucEthernetBuffer
is NULL on multiple occasions, but it’s only the last one where the code assersted.
BUF_GET[15]: 000000001000ac68 (0000000020004c58)
BUF_GET[16]: 000000001000ac94 (0000000020005258)
BUF_GET[17]: 000000001000acc0 (0000000020004058)
BUF_PUT[14]: 000000001000ac3c (0000000020004058) (now 28)
BUF_PUT[15]: 000000001000ac68 (0000000020004658) (now 29)
BUF_PUT[16]: 000000001000ac94 (0000000020004c58) (now 30)
BUF_PUT[17]: 000000001000acc0 (0000000020005258) (now 31)
BUF_GET[18]: 000000001000acec (0000000020004658)
BUF_PUT[18]: 000000001000acec (0000000000000000) (now 31)
BUF_GET[21]: 000000001000ad70 (0000000020004c58)
BUF_GET[23]: 000000001000adc8 (0000000020005258)
BUF_PUT[21]: 000000001000ad70 (0000000020004658) (now 30)
BUF_PUT[23]: 000000001000adc8 (0000000020004c58) (now 31)
BUF_GET[19]: 000000001000ad18 (0000000020004058)
BUF_PUT[19]: 000000001000ad18 (0000000020005258) (now 31)
BUF_GET[20]: 000000001000ad44 (0000000020004658)
BUF_PUT[20]: 000000001000ad44 (0000000020004058) (now 31)
BUF_GET[27]: 000000001000ae78 (0000000020004c58)
TCP: No active socket on port 443 (a030052ip:52509)
BUF_GET[22]: 000000001000ad9c (0000000020004058)
BUF_PUT[25]: 000000001000ae20 (0000000000000000) (now 29)
BUF_PUT[27]: 000000001000ae78 (0000000020004658) (now 30)
TCP: No active socket on port 443 (a030052ip:52510)
BUF_GET[24]: 000000001000adf4 (0000000000000000)
In case it is related, here is my xNetworkInterfaceOutput()
function
BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer , BaseType_t xReleaseAfterSend )
{
BaseType_t xReturn = pdFAIL;
int32_t x;
/* Attempt to obtain access to a Tx buffer. */
for( x = 0; x < niMAX_TX_ATTEMPTS; x++ )
{
if( EMAC_CheckTransmitIndex() == TRUE )
{
/* Will the data fit in the Tx buffer? */
if( pxNetworkBuffer->xDataLength < EMAC_ETH_MAX_FLEN ) /*_RB_ The size needs to come from FreeRTOSIPConfig.h. */
{
/* copy the buffer to the Tx DMA descriptor. */
EMAC_PACKETBUF_Type TXBuffer;
TXBuffer.ulDataLen = pxNetworkBuffer->xDataLength;
TXBuffer.pbDataBuf = (uint32_t *)pxNetworkBuffer->pucEthernetBuffer;
EMAC_WritePacketBuffer( &TXBuffer );
EMAC_UpdateTxProduceIndex();
/* The EMAC now owns the buffer. */
pxNetworkBuffer->pucEthernetBuffer = NULL;
iptraceNETWORK_INTERFACE_TRANSMIT();
/* The Tx has been initiated. */
xReturn = pdPASS;
}
break;
}
else
{
vTaskDelay( niTX_BUFFER_FREE_WAIT );
}
}
/* Finished with the network buffer. */
if( xReleaseAfterSend != pdFALSE )
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
return xReturn;
}