AnsweredAssumed Answered

STM32F4 Discovery UART DMA TX Problem

Question asked by yao.randy.001 on Jun 6, 2014
Latest reply on Jun 6, 2014 by Clive One
Hey ST Forum,

I'm using the ST32F4-Discovery Board, and ran into some problems while testing UART4_TX in DMA Mode. When I look at oscilloscope, the TX line is pulled down, then gradually goes back to 3V. I think my Peripheral and base addresses are set wrong (bold below). Please give me any ideas:

//6.5.14 UART DMA TRY
//PC10 UART4_TX
//Non-functional 6.5.14 - check line 66, 68
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_dma.h"


//prototypes
void RCC_Config(void);
void GPIO_Config(void);
void UART4_Config(void);
void DMA_Config(void);


//global variables
#define UART4_TX_AD 0x000000;
uint16_t hi[] = {1,2,3}; //check


int main(void)
{
     RCC_Config();
     GPIO_Config();
     UART4_Config();
     DMA_Config();


    while(1)
    {
    }
}


void RCC_Config(void)
{
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_GPIOC, ENABLE);
}


void GPIO_Config(void)
{
     GPIO_InitTypeDef gpio;


     gpio.GPIO_Pin = GPIO_Pin_10;
     gpio.GPIO_Mode = GPIO_Mode_AF;
     gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
     gpio.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_Init(GPIOC,&gpio);


     GPIO_PinAFConfig(GPIOC,GPIO_PinSource10,GPIO_AF_UART4); //TX
}


void UART4_Config(void)
{//19.2kbaud, 8 bits, one stop, no parity
     USART_InitTypeDef usart;
     usart.USART_BaudRate = 19200;
     usart.USART_WordLength = USART_WordLength_8b;
     usart.USART_StopBits = USART_StopBits_1;
     usart.USART_Parity = USART_Parity_No;
     usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
     usart.USART_Mode = USART_Mode_Tx;
     USART_Init(UART4,&usart);
}


void DMA_Config(void){//dma stream 4 channel 4, uart4_tx
     DMA_InitTypeDef dma;
     dma.DMA_Channel = DMA_Channel_4;
     dma.DMA_DIR = DMA_DIR_MemoryToPeripheral;
     dma.DMA_Memory0BaseAddr = (uint32_t)&hi;
     dma.DMA_BufferSize = 1; //?
     dma.DMA_PeripheralBaseAddr = (uint32_t)&UART4->DR; //Is this uart4 receive or transmit data register?
     dma.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
     dma.DMA_MemoryInc = DMA_MemoryInc_Enable;
     dma.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //don't know
     dma.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
     dma.DMA_Mode = DMA_Mode_Circular; //??? Circular vs Normal mode?
     dma.DMA_Priority = DMA_Priority_Medium;
     dma.DMA_FIFOMode = DMA_FIFOMode_Disable;
     dma.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
     dma.DMA_MemoryBurst = DMA_MemoryBurst_Single;
     dma.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
     DMA_Init(DMA1_Stream4,&dma);
     DMA_Cmd(DMA1_Stream4,ENABLE);


     USART_DMACmd(UART4,USART_DMAReq_Tx,ENABLE);
}

Outcomes