This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC26X2R1: ICall_free() for UART_write()

Part Number: LAUNCHXL-CC26X2R1

Hi 

We configured the UART to callback mode, and our question is where is the correct place to release the UART TX buffer?

1. Release directly

static void uartTxSend()
{
    uint8_t *pData = NULL;
    pData = ICall_malloc(256);

    if(pData == NULL)
    {
        // Ensure the allocation succeeded
        return (FAILURE);
    }
    
    UART_write(uartHandle, pData, 256);
    ICall_free(pData);
}

2. Release in callback function 

static void uartWriteCallback(UART_Handle handle, void *txBuf, size_t size)
{
    ICall_free(txBuf);
}   

Thanks.

BR

Trevor

  • Hi Trevor,

    You must not free the buffer before the UART driver has sent out the data.

    The UART_write() function does not copy the content of the buffer passed as argument. The UART_write() function uses the address passed and writes it into the hardware.

    In summary, your second option is the right one.

    Best regards,