cancel
Showing results for 
Search instead for 
Did you mean: 

MxCube STM32 UART DMA transmit

marko239955_st
Associate II
Posted on December 28, 2015 at 00:05

I have this older example, it has a Buffer[] and it is supposed to transfer to DMA:

/**************************************************************************************/

char Buffer[] = ''The quick brown fox jumps over the lazy dog\r\n'';

void DMA_Configuration(void)

{

DMA_InitTypeDef DMA_InitStructure;

DMA_DeInit(DMA1_Stream4);

DMA_InitStructure.DMA_Channel = DMA_Channel_4;

DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; // Transmit

DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Buffer;

DMA_InitStructure.DMA_BufferSize = (uint16_t)sizeof(Buffer) - 1;

DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&UART4->DR;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;

DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;

DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

DMA_Init(DMA1_Stream4, &DMA_InitStructure);

/* Enable the USART Tx DMA request */

USART_DMACmd(UART4, USART_DMAReq_Tx, ENABLE);

/* Enable DMA Stream Transfer Complete interrupt */

DMA_ITConfig(DMA1_Stream4, DMA_IT_TC, ENABLE);

/* Enable the DMA Tx Stream */

DMA_Cmd(DMA1_Stream4, ENABLE);

}

/************************************************************************

Now MxCube created this:

/* Peripheral DMA init*/ hdma_usart1_tx.Instance = DMA1_Channel4;

hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;

hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;

hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;

hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_usart1_tx.Init.Mode = DMA_CIRCULAR;

hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;

HAL_DMA_Init(&hdma_usart1_tx);

__HAL_LINKDMA(huart,hdmatx,hdma_usart1_tx); Clearly there is no Buffer[], how can I add it in MxCube as it processes all automaticly, and what is _HAL_LINKDMA?

2 REPLIES 2
Singh.Harjit
Senior II
Posted on December 28, 2015 at 04:37

Look for HAL_UART_Transmit_DMA() and call it with buffer and the other parameters it wants.

Here is a link to a really good document on how to use STM32Cube:

http://empa.com/dokumanlar/STM32F4-Labs.pdf

Posted on December 30, 2015 at 13:20

Hi bursic.marko,

As mentioned by HarjitS, you have to add into user code section the appropriate functions for transmission (obviously with declaring appropriate parameters like buffer). You can refer to some examples as  this one \STM32Cube_FW_F4_V1.10.0\Projects\STM32F429I-Discovery\Examples\UART\UART_TwoBoards_ComDMA\MDK-ARM.

Besides __HAL_LINKDMA() is a macro that ''Associate the initialized DMA handle to the ADC DMA handle'' or ''Associate the initialized DMA handle to the CRYP DMA handle''. More details are available in 

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00105879.pdf?s_searchtype=keyword

.

Hope this help you

-Shahrzad-