LPC4357 - DMA for UART1

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

LPC4357 - DMA for UART1

601 Views
ssudhir
Contributor II

Hi,

We are using LPC4357. We are connecting USART1 to an embedded ethernet module. We would like to set up DMA for that connection.  Right now, we have set up DMA for receive path (that is when ethernet module receives a packet, we use DMA). When we setup transfer size as 10, we get a DMA interrupt after 10 bytes. Right now, we are using a test software and we send more than 10 bytes. However, the packet size varies.  We would like to get DMA interrupt after receiving the entire packet. Any idea?

Thanks

0 Kudos
4 Replies

489 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, SS,

As you know that the uart has two type of flow control, one is software flow control, it sends XON or XOFF commands based on the receiver status, another is hardware flow control, it uses RTS/CTS signals to implement the flow control.

I think it is impossible to implement software flow control when you use DMA to transfer data, you can consider hardware flow control mode.

BR

Xiangjun Rong

0 Kudos

489 Views
ssudhir
Contributor II

Setting DMA controller as the flow controller.

The packet header contains the size of the packet which is 2 bytes. During initialization set up transfer size as 2 and then in DMA interrupt handler we set transfer size as the packet size. We are able to receive on test packet. However, is it the right method to receive unknown packet size. Is there more elegant method?

void Set_TransferSize(LPC_GPDMA_T *pGPDMA,uint8_t ch,uint8_t size)
{

GPDMA_CH_T *pDMAch;
uint32_t ctrlword;


// Get Channel pointer
pDMAch = (GPDMA_CH_T *) &(pGPDMA->CH[ch]);
//set transfer size
pDMAch->CONTROL = (pDMAch->CONTROL & 0xFFFFF000) | size;
Chip_GPDMA_ChannelCmd(pGPDMA, ch, ENABLE);

}

void DMA_IRQHandler(void)
{
uint8_t dmaChannelNum;
uint16_t count;

if (isDMATx) {
dmaChannelNum = dmaChannelNumTx;
}
else {
dmaChannelNum = dmaChannelNumRx;
}
if (first_flag == true)
{
if (Chip_GPDMA_Interrupt(LPC_GPDMA, dmaChannelNum) == SUCCESS) {
channelTC++;
//count = receiveBuffer[0];
count = (receiveBuffer[1] <<8) | receiveBuffer[0];
Set_TransferSize(LPC_GPDMA, dmaChannelNumRx,count);
//bns tried to set the new size this way , I do get interrupt but it is a lot of code in an interrupt route so tryign to dset just size
/*Chip_GPDMA_Transfer(LPC_GPDMA, dmaChannelNumRx,
_GPDMA_CONN_UART_Rx,
(uint32_t) &receiveBuffer[2],
GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA,
count);*/


}
else {
channelTCErr++;
}
first_flag = false;
}
else
{
if (Chip_GPDMA_Interrupt(LPC_GPDMA, dmaChannelNum) == SUCCESS) {
channelTC++;
count = receiveBuffer[0];
//count = (receiveBuffer[1] <<8) | receiveBuffer[0];


}
else {
channelTCErr++;
}
first_flag = true;

}
}

0 Kudos

489 Views
ssudhir
Contributor II

As expected, UART can't be flow controller. We programmed UART to be flow controller and never get DMA interrupt.

0 Kudos

489 Views
ssudhir
Contributor II

In Peripheral to Memory transfer, when the packet size is unknown, the peripheral needs to be the flow controller. Can UART act as flow controller?

0 Kudos