cancel
Showing results for 
Search instead for 
Did you mean: 

uart dma

tomslas
Associate II
Posted on September 18, 2007 at 06:03

uart dma

4 REPLIES 4
tomslas
Associate II
Posted on May 17, 2011 at 09:46

This's my simple program. Program don't send text by UART0

Where's my bug: :-[

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

* File Name : main.c

* Author : Test

* Date First Issued : 05/18/2006 : Version 1.0

* Description : Main program body

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

/* Includes ------------------------------------------------------------------*/

#include ''91x_lib.h''

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

#define TxBufferSize (countof(TxBuffer) - 1)

#define RxBufferSize 0xFF

/* Private macro -------------------------------------------------------------*/

#define countof(a) (sizeof(a) / sizeof(*(a)))

/* Private variables ---------------------------------------------------------*/

DMA_InitTypeDef DMA_InitStruct;

UART_InitTypeDef UART_InitStructure;

u8 TxBuffer[] = ''UART Example1: UART - This is example text\n\r'';

u8 RxBuffer[RxBufferSize];

u8 NbrOfDataToTransfer = TxBufferSize;

u8 TxCounter = 0;

u8 RxCounter = 0;

/* Private function prototypes -----------------------------------------------*/

void SCU_Configuration(void);

void GPIO_Configuration(void);

void Uart0_Write(u8 *string, u32 size) {

// wait the end of previous tx

while(UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOEmpty) == RESET);

UART_ITConfig(UART0, UART_IT_Transmit, DISABLE);

DMA_ChannelCmd (DMA_Channel1, DISABLE);//Enable the DMA channel

DMA_Channel1->SRC = (u32)string;

DMA_Channel1->CC &= 0xFFFFF000;

DMA_Channel1->CC |= size & 0x0FFF;

DMA_ChannelCmd (DMA_Channel1, ENABLE);//Enable the DMA channel

}

void Uart0_INIT() {

/* UART0 configuration -------------------------------------------------------*/

/* UART0 configured as follow:

- Word Length = 7 Bits

- Two Stop Bit

- No parity

- BaudRate = 115200 baud

- Hardware flow control disabled

- Receive and transmit enabled

- Receive and transmit FIFOs are enabled

- Transmit and Receive FIFOs levels have 8 bytes depth

*/

UART_InitStructure.UART_WordLength = UART_WordLength_8D;

UART_InitStructure.UART_StopBits = UART_StopBits_2;

UART_InitStructure.UART_Parity = UART_Parity_No ;

UART_InitStructure.UART_BaudRate = 115200;

UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;

UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;

UART_InitStructure.UART_FIFO = UART_FIFO_Enable;

UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

UART_DeInit(UART0);

UART_Init(UART0, &UART_InitStructure);

UART_ITConfig(UART0, UART_IT_Receive, ENABLE);

}

void DMA1_INIT() {

SCU_AHBPeriphClockConfig(__DMA,ENABLE); /* Enable the clock for DMA*/

/* No next linked list item*/

DMA_InitStruct.DMA_Channel_LLstItm= 0;

/* Source address of the DMA transfer */

DMA_InitStruct.DMA_Channel_SrcAdd=(u32)(&TxBuffer[0]);

/* Destination address of DMA the transfer is UART Data reg*/

DMA_InitStruct.DMA_Channel_DesAdd=(u32)(&UART0->DR);

/* Source data width is Byte */

DMA_InitStruct.DMA_Channel_SrcWidth= DMA_SrcWidth_Byte;

/* Destination bus width is Byte */

DMA_InitStruct.DMA_Channel_DesWidth= DMA_DesWidth_Byte;

/* DMAC is The flow controller*/

DMA_InitStruct.DMA_Channel_FlowCntrl=DMA_FlowCntrl1_DMA;

/*The DMAC is triggered by the SSP_DMA_Transmit request.*/

DMA_InitStruct.DMA_Channel_Des= DMA_DES_UART0_TX;

/*Transfer size of 12 data */

DMA_InitStruct.DMA_Channel_TrsfSize = TxBufferSize;

/* Update the DMA channel0 registers with DMA_InitStruct values */

DMA_Init(DMA_Channel1,&DMA_InitStruct);

/* Enable Source increment */

DMA_ChannelSRCIncConfig (DMA_Channel1, ENABLE);

/*Enable the Terminal Count interrupt*/

DMA_ITConfig(DMA_Channel1, ENABLE);

DMA_ITMaskConfig(DMA_Channel1, DMA_ITMask_ITC, ENABLE);

/*Enable the DMA channel0*/

DMA_ChannelCmd (DMA_Channel1,ENABLE);

}

/* Private functions ---------------------------------------------------------*/

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

* Function Name : main

* Description : Main program

* Input : None

* Output : None

* Return : None

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

int main()

{

#ifdef DEBUG

debug();

#endif

/* Configure the system clocks */

SCU_Configuration();

/* Configure the GPIO ports */

GPIO_Configuration();

Uart0_INIT();

UART_DMACmd(UART0, UART_DMAReq_Tx, ENABLE);

DMA1_INIT();

VIC_Config(UART0_ITLine, VIC_IRQ, 1);

VIC_ITCmd(UART0_ITLine, ENABLE);

// Enable the Interrupt controller to manage IRQ channel

UART_Cmd(UART0, ENABLE);

Uart0_Write( &TxBuffer[0], TxBufferSize);

while (1);

}

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

* Function Name : SCU_Configuration

* Description : Configures the system clocks.

* Input : None

* Output : None

* Return : None

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

void SCU_Configuration(void)

{

/* Enable the clock for DMA*/

SCU_AHBPeriphClockConfig(__DMA,ENABLE);

SCU_AHBPeriphClockConfig(__VIC, ENABLE);

/* Enable the UART0 Clock */

SCU_APBPeriphClockConfig(__UART0, ENABLE);

/* Enable the GPIO3 Clock */

SCU_APBPeriphClockConfig(__GPIO3, ENABLE);

/* Enable the GPIO5 Clock */

SCU_APBPeriphClockConfig(__GPIO5, ENABLE);

}

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

* Function Name : GPIO_Configuration

* Description : Configures the different GPIO ports.

* Input : None

* Output : None

* Return : None

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

void GPIO_Configuration(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_DeInit(GPIO5);

/*Gonfigure UART0_Rx pin GPIO5.1*/

GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIO_Init (GPIO5, &GPIO_InitStructure);

GPIO_DeInit(GPIO3);

/*Gonfigure UART0_Tx pin GPIO3.4*/

GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ;

GPIO_Init (GPIO3, &GPIO_InitStructure);

}

tomslas
Associate II
Posted on May 17, 2011 at 09:46

OK.

All's OK. I'm find my bug. :D

sarao
Associate II
Posted on May 17, 2011 at 09:46

It would be helpful if you could post your fix.

Thanks.

tomslas
Associate II
Posted on May 17, 2011 at 09:46

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6iZ&d=%2Fa%2F0X0000000btu%2FGiNnzX75t96.M7PHicjU9aXBl6ru.r3dr4nBdYBH4OM&asPdf=false