Hi Team,
I am working on AM263x using MCU+ SDK version mcu_plus_sdk_am263x_09_02_00_55.
I am using UART in callback mode with DMA enabled.
Requirement
My receive length is dynamic:
-
First, I receive 4 bytes (header).
-
The 2nd and 3rd bytes determine the payload length.
-
Based on that, I update
UART_Transaction.count. -
Then I call
UART_read()again to receive the remaining payload. -
After payload reception completes, I restart reception for the next 4-byte header.
The incoming data stream is continuous from the external device.
Issue Observed
The receive buffer fills correctly up to 64 bytes.
After 64 bytes:
-
The 65th byte onwards appears corrupted.
-
Data looks like it is restarting from index 0 or overwritten.
-
Behavior suggests possible FIFO overflow (UART FIFO size appears to be 64 bytes).
To temporarily recover, I manually flush the UART FIFO by reading the RHR register when LSR indicates data ready, but I am not sure if this is the correct approach when using the UART driver with DMA.
this is my code
static uint8_t gRadioComReceivebuffer[UART_COM_BUFSIZE]
__attribute__((aligned(CacheP_CACHELINE_ALIGNMENT))) = {0U};
static uint8_t gRadioCOMCopyDMA[1024] = {0U};
#define UART_COM_BUFSIZE (1024)
static void SL_SetRadioCOMByteCount(uint16_t bCount)
{
RMC_RxTrans.buf = gRadioComReceivebuffer;
RMC_RxTrans.count = bCount;
}
static void RADIO_MODEM_RX_CALLBACK(UART_Handle handle,
UART_Transaction *trans)
{
printf("received count = %d\n", trans->count);
RMCRxBuf.rxCompleteFlag = 1U;
}
Processing function:
static void CopyReceiveData(void)
{
if (RMCRxBuf.rxCompleteFlag == 1U)
{
RMCRxBuf.rxCompleteFlag = 0U;
CacheP_inv((void *)gRadioComReceivebuffer,
RadioRXDMALen,
CacheP_TYPE_ALL);
if (RadioRXDMALen == 4U)
{
for(uint8_t i = 0; i < 4; i++)
{
gRadioCOMCopyDMA[i] = gRadioComReceivebuffer[i];
}
RadioRXDMALen =
((gRadioCOMCopyDMA[2] << 8) |
(gRadioCOMCopyDMA[3])) + 5U;
SL_SetRadioCOMByteCount(RadioRXDMALen);
UART_read(gUartHandle[RADIO_COMM_PORT], &RMC_RxTrans);
}
else
{
for(uint16_t i = 0; i < RadioRXDMALen; i++)
{
gRadioCOMCopyDMA[i + 4U] =
gRadioComReceivebuffer[i];
}
RadioRXDMALen = 4U;
SL_SetRadioCOMByteCount(RadioRXDMALen);
UART_read(gUartHandle[RADIO_COMM_PORT], &RMC_RxTrans);
VadateDMAmodel1(radioCOMRxByteCount);
radioCOMRxByteCount = 0U;
}
}
}
uart configuration:
.baudRate = 57600,
.dataLength = UART_LEN_8,
.stopBits = UART_STOPBITS_1,
.parityType = UART_PARITY_NONE,
.readMode = UART_TRANSFER_MODE_CALLBACK,
.readReturnMode = UART_READ_RETURN_MODE_PARTIAL,
.writeMode = UART_TRANSFER_MODE_CALLBACK,
.readCallbackFxn = RADIO_MODEM_RX_CALLBACK,
.writeCallbackFxn = RADIO_MODEM_TX_CALLBACK,
.hwFlowControl = FALSE,//TRUE,
.hwFlowControlThr = UART_RXTRIGLVL_16,
.transferMode = UART_CONFIG_MODE_DMA,
.skipIntrReg = FALSE,
.uartDmaIndex = 1,
.intrNum = 39U,
.intrPriority = 8U,
.operMode = UART_OPER_MODE_16X,
.rxTrigLvl = UART_RXTRIGLVL_1,
.txTrigLvl = UART_TXTRIGLVL_1,
.rxEvtNum = 0U,
.txEvtNum = 0U