cancel
Showing results for 
Search instead for 
Did you mean: 

DMA Memory To UART5

dclark9
Associate II
Posted on June 25, 2012 at 15:38

Hi,

I'm having an issue setting up a DMA to transfer data from a 2 element uint8_t array to UART5. The code works, but the UART only sends out the first byte and having tried lots of different things I don't understand what I need to do to make it push out the whole buffer. Code is as follows :-

uint8_t myBuffer[2] = {0x55, 0x55};
DMA_DeInit(MEZZANINE_DMA_TX);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&UART5->DR;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) myBuffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
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_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(MEZZANINE_DMA_TX, &DMA_InitStructure);
DMA_Cmd( MEZZANINE_DMA_TX, ENABLE );

Many thanks in advance for any responses, Dave

#dma #stm32-uart-usart
29 REPLIES 29
Posted on September 24, 2012 at 11:34

Hi all,

I like the example very much, I tried it and it works fine with USART5.

I need to modify it to run on stm32f2xx with USART2.

I changed the configuration to USART2 and I can send the data directly without DMA, but the DMA transfer does not work, so I suspect DMA_Configuration (the rest should be OK, because direct transfer runs ok).

My modified not working version is:

void DMA_Configuration(void)

{

  DMA_InitTypeDef  DMA_InitStructure;

  DMA_DeInit(DMA1_Stream7);

  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)&USART2->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_Stream7, &DMA_InitStructure);

  /* Enable the USART Tx DMA request */

  USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);

  /* Enable DMA Stream Transfer Complete interrupt */

  DMA_ITConfig(DMA1_Stream7, DMA_IT_TC, ENABLE);

  /* Enable the DMA RX Stream */

  DMA_Cmd(DMA1_Stream7, ENABLE);

}

Anyone has an idea what could be missing? Thanks.

Posted on September 24, 2012 at 19:20

Because USART2_TX uses DMA1_Stream6

Refer to Table 20 DMA1 Request Mapping in RM0090 (STM32F4 Reference Manual)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 24, 2012 at 21:21

USART2 TX DMA Example

// STM32 USART2 DMA TX (Tx PA.2, Rx PA.3) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* DMA1 clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; // PA.2 USART2_TX, PA.3 USART2_RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
}
/**************************************************************************************/
void USART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
}
/**************************************************************************************/
char Buffer[] = ''The quick brown fox jumps over the lazy dog

'';
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Stream6);
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)&USART2->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_Stream6, &DMA_InitStructure);
/* Enable the USART Tx DMA request */
USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
/* Enable DMA Stream Transfer Complete interrupt */
DMA_ITConfig(DMA1_Stream6, DMA_IT_TC, ENABLE);
/* Enable the DMA RX Stream */
DMA_Cmd(DMA1_Stream6, ENABLE);
}
/**************************************************************************************/
void DMA1_Stream6_IRQHandler(void)
{
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA1_Stream6, DMA_IT_TCIF6))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6);
}
}
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the Priority Group to 2 bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the USART2 RX DMA Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
USART2_Configuration();
DMA_Configuration();
while(1); // Don't want to exit
}
/**************************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**************************************************************************************/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 25, 2012 at 14:19

Thank you very much. It helped.

If I understand it well, I can not combine different channel on the same stream. Is it right? For example USART2_TX and DAC2 can not run with DMA simultaneously.

smuryginim
Associate II
Posted on November 01, 2012 at 06:26

Hi, everyone. I see here many examples of using UART with DMA, but, unfortuantly, i have a problem with them. I using stm32f207 and could see the result of transfering.

This is my code

#ifndef DEBUG_UART
#define GPIO_Pin_USART_RX GPIO_PinSource10 /* Pin 10 selected */
#define GPIO_Pin_USART_TX GPIO_PinSource9 /* Pin 9 selected */
#define GPIO_Pin_USART_RX1 GPIO_Pin_10 /* Pin 10 selected */
#define GPIO_Pin_USART_TX1 GPIO_Pin_9 /* Pin 9 selected */
#define PORT_USART GPIOA
#define GPIO_AF_USART GPIO_AF_USART1
#define USART USART1
#define USART_IRQn USART1_IRQn
#else //for test on OLIMEX207
#define GPIO_Pin_USART_RX GPIO_PinSource9 /* Pin 9 selected */
#define GPIO_Pin_USART_TX GPIO_PinSource8 /* Pin 8 selected */
#define GPIO_Pin_USART_RX1 GPIO_Pin_9 /* Pin 9 selected */
#define GPIO_Pin_USART_TX1 GPIO_Pin_8 /* Pin 8 selected */
#define PORT_USART GPIOD
#define GPIO_AF_USART GPIO_AF_USART3
#define USART USART3
#define USART_IRQn USART3_IRQn
#endif
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* UART3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE );
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/*LEDs clock enable*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOD, ENABLE);
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* DMA1 clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
}
/*******************************************************************************/
void vSerialPortInit(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_DeInit(USART);
/* Configure USART Rx (PA10) as input floating */
//for test using PD9_RX
GPIO_PinAFConfig(PORT_USART, GPIO_Pin_USART_RX , GPIO_AF_USART);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_USART_RX1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init( PORT_USART, &GPIO_InitStructure );
/* Configure USART Tx (PA9) as alternate function push-pull */
//for test using PD8_TX
GPIO_PinAFConfig(PORT_USART, GPIO_Pin_USART_TX , GPIO_AF_USART);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_USART_TX1;
GPIO_Init( PORT_USART, &GPIO_InitStructure );
USART_InitStructure.USART_BaudRate = 230400;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init( USART, &USART_InitStructure );
}
char Buffer[] = ''The quick brown fox jumps over the lazy dog

'';
/*******************************************************************************/
void DMA_rec(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Stream1);
/* DMA1 Stream1 channel4 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_4; //for USART3_RX
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Buffer;
DMA_InitStructure.DMA_BufferSize = (uint32_t)sizeof(Buffer);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART3->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_Normal;
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_Stream1, &DMA_InitStructure);
/* Enable the USART Rx DMA request */
USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
/* Enable DMA Stream Half Transfer and Transfer Complete interrupt */
DMA_ITConfig(DMA1_Stream1, DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA1_Stream1, DMA_IT_HT, ENABLE);
/* Enable the DMA RX Stream */
DMA_Cmd(DMA1_Stream1, ENABLE);
}
/*******************************************************************************/
void DMA_Transmitt(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* Enable DMA1 clock ********************************************************/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
DMA_DeInit(DMA1_Stream3);
/* DMA1 Stream3 channel4 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_4; //for USART3_TX Channel_4, Stream3
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Buffer;
DMA_InitStructure.DMA_BufferSize = (uint32_t)sizeof(Buffer);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART3->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_Normal;
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_Stream3, &DMA_InitStructure);
/* Enable the USART DMA requests */
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
/* Enable DMA1_Stream3 Transfer complete interrupt */
DMA_ITConfig(DMA1_Stream3, DMA_IT_TC, ENABLE);
/* Enable the DMA TX Stream, USART will start sending the command code (2bytes) */
DMA_Cmd(DMA1_Stream3, ENABLE);
}
/*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the Priority Group to 2 bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the UART3 TX DMA Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the UART3 RX DMA Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************/
void DMA1_Stream1_IRQHandler(void)
{
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA1_Stream1, DMA_IT_TCIF1))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream1, DMA_IT_TCIF1);
USART_SendData(USART3, 'C');
}
/* Test on DMA Stream Half Transfer interrupt */
if (DMA_GetITStatus(DMA1_Stream1, DMA_IT_HTIF1))
{
/* Clear DMA Stream Half Transfer interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream1, DMA_IT_HTIF1);
USART_SendData(USART3, 'H');
}
}
void DMA1_Stream3_IRQHandler(void)
{
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA1_Stream3, DMA_IT_TCIF3))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream3, DMA_IT_TCIF3);
}
}
int main()
{ 
RCC_Configuration();
Led_Init();
NVIC_Configuration();
vSerialPortInit();
DMA_Transmitt();
DMA_rec();
GPIO_WriteBit(GPIOF, GPIO_Pin_9, Bit_SET); // using led
while(1)
{
};
}

I'm using olimex board for testing this programm and putty terminal. USART seems to work normal with interrupts. Any help will be appreciated a lot.
smuryginim
Associate II
Posted on November 01, 2012 at 07:13

Execuse me, but how i can see the numbers, which i read throw the DMA.

I 've done something like that, but this doesn't work

static unsigned char RBuffer[10];
void DMA_rec(unsigned char * RBuffer, int size)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Stream1);
/* DMA1 Stream1 channel4 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_4; //for USART3_RX
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint8_t)RBuffer;
DMA_InitStructure.DMA_BufferSize = size;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART3->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_Normal;
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_Stream1, &DMA_InitStructure);
/* Enable the USART Rx DMA request */
USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
/* Enable DMA Stream Half Transfer and Transfer Complete interrupt */
DMA_ITConfig(DMA1_Stream1, DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA1_Stream1, DMA_IT_HT, ENABLE);
/* Enable the DMA RX Stream */
DMA_Cmd(DMA1_Stream1, ENABLE);
}
void DMA1_Stream1_IRQHandler(void)
{
int i=0;
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA1_Stream1, DMA_IT_TCIF1))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream1, DMA_IT_TCIF1);
}
}
//////========================MAIN=========================\\\\\\\\\\\\\\\
int main()
{ 
// __enable_irq(); 
prvSetupHardware();
RCC_Configuration();
Led_Init();
NVIC_Configuration();
vSerialPortInit();
DMA_Transmitt();
DMA_rec(RBuffer, 10);
GPIO_WriteBit(GPIOF, GPIO_Pin_9, Bit_SET); //led using
while(1)
{
};
}

How i can see the result of reading?
Posted on November 01, 2012 at 14:41

Execuse me, but how i can see the numbers, which i read throw the DMA. I 've done something like that, but this doesn't work. How i can see the result of reading?

 

Well you'd typically send it to an output device, like a screen or serial port. From a debugger you could break point after reception, and view the memory buffer.

If you enable the HT DMA interrupt source, you need to be prepared to service it, otherwise failure will occur.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
smuryginim
Associate II
Posted on November 06, 2012 at 15:31

Thank for your reply.

I tried to see RBuffer. But it doesn't have any data.

When i send the data through terminal to my STM board, they appears in USART DR(Data register) and counter of DMA count bytes and is decremented, then occurs the DMA Interrupt. I tried to Transmitt the data to my terminal from Rbuffer, but there only 0x00 digits.

The others data is sended by DMA_Transmitt all right!

Maybe i made some mistake in sending address of recieve buffer to DMA register? I tried to use &, but it gives no successs. Where can be a mistake?
Posted on November 06, 2012 at 16:33

This thread seems to have veered from the original topic.

If I wanted to demonstrate USART3 TX and RX DMA on an STM32F2 or STM32F4 I might do it like this :

// STM32 USART3 DMA TX/RX (Tx PD.8, Rx PD.9) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/* DMA1 clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; // PD.8 USART3_TX, PD.9 USART3_RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
}
/**************************************************************************************/
void USART3_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
}
/**************************************************************************************/
// Output as a loop, received data overwrites, and subsequently outputs during next cycle
char Buffer[] = ''The quick brown fox jumps over the lazy dog

'';
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
// USART3_TX DMA Channel 4, DMA1, Stream3
DMA_DeInit(DMA1_Stream3);
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)&USART3->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_Stream3, &DMA_InitStructure);
/* Enable the USART Tx DMA request */
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
/* Enable DMA Stream Transfer Complete interrupt */
DMA_ITConfig(DMA1_Stream3, DMA_IT_TC, ENABLE);
/* Enable the DMA TX Stream */
DMA_Cmd(DMA1_Stream3, ENABLE);
// USART3_RX DMA Channel 4, DMA1, Stream1
DMA_DeInit(DMA1_Stream1);
DMA_InitStructure.DMA_Channel = DMA_Channel_4;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; // Receive
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Buffer;
DMA_InitStructure.DMA_BufferSize = (uint16_t)sizeof(Buffer) - 1;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART3->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_Stream1, &DMA_InitStructure);
/* Enable the USART Rx DMA request */
USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
/* Enable DMA Stream Transfer Complete interrupt */
DMA_ITConfig(DMA1_Stream1, DMA_IT_TC, ENABLE);
/* Enable the DMA RX Stream */
DMA_Cmd(DMA1_Stream1, ENABLE);
}
/**************************************************************************************/
void DMA1_Stream3_IRQHandler(void) // USART3_TX
{
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA1_Stream3, DMA_IT_TCIF3))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream3, DMA_IT_TCIF3);
}
}
/**************************************************************************************/
void DMA1_Stream1_IRQHandler(void) // USART3_RX
{
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA1_Stream1, DMA_IT_TCIF1))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream1, DMA_IT_TCIF1);
}
}
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the Priority Group to 2 bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the USART3 TX DMA Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the USART3 RX DMA Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
USART3_Configuration();
DMA_Configuration();
while(1); // Don't want to exit
}
/**************************************************************************************/

A more realistic implementation of RX DMA would take significantly more work, especially if you want to deal with sporadic reception in a timely manner. This is beyond the scope of my participation here.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
smuryginim
Associate II
Posted on November 08, 2012 at 05:45

Hi Clive!!! Thank you for you reply and usefull examples. I found my error. It was in C. Now receiving through DMA works perfect!

And do anybody have an experiance on Transmitting DMA with RTOS?