cancel
Showing results for 
Search instead for 
Did you mean: 

UART Tx DMA variable length

hosweetim
Associate II
Posted on November 25, 2015 at 03:39

I am currently using STM32F4 Discovery board, and i configure UART 2 into DMA mode for sending data.

i am able to send data with a fixed length to UART 2 using DMA.

But, i want to send data with a variable length.

Example

1:

Buffer = ''hello world!''

2: Buffer = ''is this working again?''

3: Buffer = ''i want to use dma tx mode''

I could do that by reconfiguring the DMA_Init, each before I send the data as shown below

DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Buffer;

DMA_InitStructure.DMA_BufferSize = (uint16_t)strlen(Buffer);

DMA_Init(DMA1_Stream5, &DMA_InitStructure);

Is this the right way to do it?

But, i read from the document, whenever I init the DMA, it will take sometime and there is a possibility that I could corrupt the previous DMA transfer.

May i know how to a proper way?

1 REPLY 1
Posted on November 25, 2015 at 14:41

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/Failing%20to%20set%20up%20USART%20DMA%20TX&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=57]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Java%2FFailing%20to%20set%20up%20USART%20DMA%20TX&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21¤tviews=57

The method for the F4 would be very similar, the code is probably overly verbose for clarity, but should give you are starting point. I may have built an F4 version of this, but this is the one that dropped out of a quick search.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..