cancel
Showing results for 
Search instead for 
Did you mean: 

UART DMA

Posted on August 18, 2006 at 10:36

UART DMA

3 REPLIES 3
Posted on May 17, 2011 at 09:31

Hi,

I modified the SPP DMA example in order to

work with the UART

Everything is ok when I send strings from SRAM :p ,

the string stored in FLASH is not sent :-? .

Follow a piece of code with the uart inits

Any suggestion?

Stefano

------- Attach ------

void Uart0_Init()

{

DMA_InitTypeDef DMA_InitStruct;

/* UART0 configuration -------------------------------------------------------*/

/* UART0 configured as follow:

- Word Length = 8 Bits

- One Stop Bit

- No parity

- BaudRate = 115200 baud

- Hardware flow control enabled (RTS and CTS signals)

- Receive and transmit enabled

- Receive and transmit FIFOs are enabled

- Transmit and Receive FIFOs levels have 8 bytes depth

*/

UART_InitStructure.UART_WordLength = UART_WordLength_8D;

UART_InitStructure.UART_StopBits = UART_StopBits_1;

UART_InitStructure.UART_Parity = UART_Parity_No ;

UART_InitStructure.UART_BaudRate = 115200;

UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;

UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;

UART_InitStructure.UART_FIFO = UART_FIFO_Enable;

UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

UART_DeInit(UART0);

UART_Init(UART0, &UART_InitStructure);

/* Enable the UART Receive interrupt: this interrupt is generated when the UART0 receive FIFO hold two data */

UART_ITConfig(UART0, UART_IT_Receive, ENABLE);

UART_DMACmd(UART0, UART_DMAReq_Tx, ENABLE);

/***************************DMA configuration**********************************/

DMA_SyncConfig(DMA_UART0_TX_Mask, ENABLE);

DMA_StructInit(&DMA_InitStruct);

DMA_InitStruct.DMA_Channel_LLstItm=0;

DMA_InitStruct.DMA_Channel_SrcAdd=(u32)(TxBuffer);

DMA_InitStruct.DMA_Channel_DesAdd=(u32)((&UART0->DR));

DMA_InitStruct.DMA_Channel_SrcWidth= DMA_SrcWidth_Byte;

DMA_InitStruct.DMA_Channel_DesWidth= DMA_DesWidth_Byte;

DMA_InitStruct.DMA_Channel_FlowCntrl= DMA_FlowCntrl1_DMA ;

DMA_InitStruct.DMA_Channel_Des = DMA_DES_UART0_TX;

DMA_InitStruct.DMA_Channel_TrsfSize = TXBUFFERSIZE;

DMA_ChannelSRCIncConfig (DMA_Channel1, ENABLE);

DMA_Init(DMA_Channel1,&DMA_InitStruct);

// DMA_ChannelCmd (DMA_Channel0,ENABLE);

/* Configure and enable the interrupt controller */

/*Enable VIC clock*/

VIC_Config(UART0_ITLine, VIC_IRQ, 1);

VIC_ITCmd(UART0_ITLine, ENABLE);

UART_Cmd(UART0, ENABLE);

}

void Uart0_Write(char *string, u32 size)

{

// wait the end of previous tx

while(UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOEmpty)==RESET);

UART_ITConfig(UART0, UART_IT_Transmit, DISABLE);

DMA_ChannelCmd (DMA_Channel1,DISABLE);//Enable the DMA channel

DMA_Channel1->SRC = (u32)string;

DMA_Channel1->CC &= 0xFFFFF000;

DMA_Channel1->CC |= size & 0x0FFF;

DMA_ChannelCmd (DMA_Channel1,ENABLE);//Enable the DMA channel

}

....

in the main the loop...

while(1)

{

char a[]={'a', 'b', '\r', '\n'};

Uart0_Write(a,4);

Uart0_Write(''Hello Dad I love you\r\n'', 22);

}

------- end Attach --

anis
Associate II
Posted on May 17, 2011 at 09:31

Hi Stefano,

It is not possible to do DMA transfers from flash memory, in fact DMA has acess only to AHB bus and there is no link between DMA and Flash (which is connected to ARM9 core on TCM interface).

Best regards,

STARM

Posted on May 17, 2011 at 09:31

Hi STARM,

thanks for the advice!

I have another question about the UART

I'd like to transmit data the dma but at the same

time I'd like to receive data using the IRQ (see the init code of previous post).

Now I found that the rx irq is not asserted if I have the DMA enable for tx.

Any suggestion?

Have I to manage the rx with DMA IRQ ?