cancel
Showing results for 
Search instead for 
Did you mean: 

DMA to USART1 TX

allamac74
Associate
Posted on May 27, 2013 at 13:17

Hi, i'm using smt32F303 discovery board, I send / receive data on USART1 without problem if I use interrupt mode, so I think that hardware is good.

I want send a data buffer lenght ~ 8000 bytes using dma mode. Before I config GPIO , USART, and  DMA , but on my hyperterminal receive only 4 chars , which is the problem?

this is my code:

unsigned char tx_buffer[8208];

void InitUSART1(void)

{

GPIO_InitTypeDef      GPIO_InitStructure;

NVIC_InitTypeDef   NVIC_InitStructure;

USART_InitTypeDef USART_InitStructure;

// TX out mode

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

// RX in mode

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

GPIO_Init(GPIOC, &GPIO_InitStructure);

/* Connect PXx to USARTx_Tx */

  GPIO_PinAFConfig(GPIOC,GPIO_PinSource4,GPIO_AF_7);

GPIO_PinAFConfig(GPIOC,GPIO_PinSource5,GPIO_AF_7);

/* Interrupt config */

  EXTI_InitStructure.EXTI_Line = EXTI_Line25; //usart1

  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

  EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set EXTI0 Interrupt to the lowest priority */

  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x07;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x07;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

USART_InitStructure.USART_BaudRate = 57600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

/* USART configuration */

USART_Init(USART1, &USART_InitStructure);

/* interrupt */

USART_ITConfig(USART1,USART_IT_RXNE, ENABLE);

/* Enable USART */

USART_Cmd( USART1, ENABLE);

/* Enable DMA tx USART */

USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);

}

 void SendBufferTx(void)

{

DMA_InitTypeDef   DMA_InitStructure;

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

DMA_DeInit(DMA1_Channel4);

DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART1->TDR;

DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&tx_buffer;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;

  DMA_InitStructure.DMA_BufferSize = sizeof(tx_buffer);

  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_Circular;

DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;

  DMA_InitStructure.DMA_Priority = DMA_Priority_High;

  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

  DMA_Init(DMA1_Channel4, &DMA_InitStructure);

DMA_Cmd(DMA1_Channel4, ENABLE);

}

3 REPLIES 3
zzdz2
Associate II
Posted on May 27, 2013 at 13:35

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;

 

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

I don't think you need peripheral inc enabled, only memory inc.

Posted on May 27, 2013 at 13:52

As knik points out the incrementing of the peripheral address (USARTx->DR) is wrong.

This also doesn't do what you expect

DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&tx_buffer;

Suggest the valid C would be tx_buffer or &tx_buffer[0]
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
allamac74
Associate
Posted on May 27, 2013 at 16:17

Thank you for your precious help, now the gaming working properly