RX on UART over DMA missing one byte

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RX on UART over DMA missing one byte

643 Views
AsafTv
Contributor II

i use MK64FN1M0xxx12 device.

i use SDK SDK_2.9.0_MK64FN1M0xxx12

i configura the uart as follow:

const uart_config_t UART0_config = {
.baudRate_Bps = 921600UL,
.parityMode = kUART_ParityDisabled,
.stopBitCount = kUART_OneStopBit,
.txFifoWatermark = 0U,
.rxFifoWatermark = 1U,
.idleType = kUART_IdleTypeStopBit,
.enableTx = true,
.enableRx = true,
.enableRxRTS = true,
.enableTxCTS = true,
};

void UART0_init(void) {
UART_Deinit( UART0_PERIPHERAL );


UART_Init(UART0_PERIPHERAL, &UART0_config, UART0_CLOCK_SOURCE);
/* Set the source kDmaRequestMux0UART0Rx request in the DMAMUX */
DMAMUX_SetSource(UART0_RX_DMAMUX_BASEADDR, UART0_RX_DMA_CHANNEL, UART0_RX_DMA_REQUEST);
/* Enable the channel 1 in the DMAMUX */
DMAMUX_EnableChannel(UART0_RX_DMAMUX_BASEADDR, UART0_RX_DMA_CHANNEL);
/* Set the source kDmaRequestMux0UART0Tx request in the DMAMUX */
DMAMUX_SetSource(UART0_TX_DMAMUX_BASEADDR, UART0_TX_DMA_CHANNEL, UART0_TX_DMA_REQUEST);
/* Enable the channel 2 in the DMAMUX */
DMAMUX_EnableChannel(UART0_TX_DMAMUX_BASEADDR, UART0_TX_DMA_CHANNEL);
/* Create the eDMA UART0_RX_Handle handle */EDMA_CreateHandle(&UART0_RX_Handle, UART0_RX_DMA_BASEADDR, UART0_RX_DMA_CHANNEL);
/* Create the eDMA UART0_TX_Handle handle */
EDMA_CreateHandle(&UART0_TX_Handle, UART0_TX_DMA_BASEADDR, UART0_TX_DMA_CHANNEL);
/* Create the UART eDMA handle */
UART_TransferCreateHandleEDMA(UART0_PERIPHERAL, &UART0_UART_eDMA_Handle, BlueTooth_DMA_UART_ISR, NULL, &UART0_TX_Handle, &UART0_RX_Handle);
(void)DisableIRQ(UART0_RX_TX_IRQn);
}

 

i start the receiving:

void BlueTooth_StartRxMessage(void){
memset( &BlueTooth_Rx, 0, sizeof(BlueTooth_Rx_t) ) ;
bluetooth_rx_transfer.data = BlueTooth_Rx.Q[BlueTooth_Rx.InIndex].Buf ;
bluetooth_rx_transfer.dataSize = MAX_BT_MSG_SIZE ;
UART_ReceiveEDMA( UART0, &UART0_UART_eDMA_Handle, &bluetooth_rx_transfer ) ;
}

 

i test the DMA counter each 1msec:

void BlueTooth_TimeMessage( void ){
if( UART0_UART_eDMA_Handle.callback == NULL )return;

uint32 status = UART_GetStatusFlags(UART0);
UART_ClearStatusFlags(UART0, status);
//if( (status & kUART_IdleLineFlag) == 0)return;

uint32 RxLength = 0 ;
if( UART_TransferGetReceiveCountEDMA( UART0, &UART0_UART_eDMA_Handle, &RxLength ) == kStatus_NoTransferInProgress )RxLength = (uint32)BlueTooth_Rx.RxLength;

if( (BlueTooth_Rx.RxLength != RxLength) && (BlueTooth_Rx.RxLength < MAX_BT_MSG_SIZE) ){
BlueTooth_Rx.RxLength = RxLength ;
BlueTooth_Rx.Time = MAX_RX_TIMEOUT;
}
//else if( UART0->S1 & UART_S1_IDLE_MASK )BlueTooth_Rx.Time = MAX_RX_TIMEOUT;
else if( BlueTooth_Rx.Time ){
if( !(--BlueTooth_Rx.Time) )BlueTooth_BufferFull( );
}
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}

void BlueTooth_BufferFull( void ){
//EnterCritical( );
UART_TransferAbortReceiveEDMA(UART0, &UART0_UART_eDMA_Handle);

uint8 index = BlueTooth_Rx.InIndex ;
if( ++index >= MAX_Q_SIZE)index = 0 ;

if( !BlueTooth_Rx.Q[index].Length ){
BlueTooth_Rx.Q[BlueTooth_Rx.InIndex].Length = BlueTooth_Rx.RxLength ;
BlueTooth_Rx.Time = 0 ;
BlueTooth_Rx.RxLength = 0 ;
BlueTooth_Rx.InIndex = index ;
}

bluetooth_rx_transfer.data = BlueTooth_Rx.Q[BlueTooth_Rx.InIndex].Buf ;
bluetooth_rx_transfer.dataSize = MAX_BT_MSG_SIZE ;
UART_ReceiveEDMA( UART0, &UART0_UART_eDMA_Handle, &bluetooth_rx_transfer ) ;
//ExitCritical();
}

some times i get one byte missing in the midale of the string.

i see the data using sniffer on the UART line and the data is correct.

what im doing wrong?

 

0 Kudos
1 Reply

628 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @AsafTv,

I have some question about this:

Does the any of the UART status flags is being triggered?

I saw that you are sending the information at 921600UL, have you tried lowering the speed to check if this problems disappear?

Is this a custom board or the FRDM?

Best Regards,

Alexis Andalon

0 Kudos