2014-06-05 03:52 PM
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''//prototypesvoid 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}; //checkint 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);}
2014-06-05 06:02 PM
USARTx->DR is a peripheral register that has a different sense depend on whether you read it, or write it, it's not like a memory cell
There is no point doing DMA for ONE character. As you are only doing 8-bit values via serial you should use the BYTE transfer. In Circular mode the transfer keeps restarting, Normal mode means you have to reconfigure/reinitialize the transfer. PC10 is slightly conflicted, but for output it should work. The pins output CMOS levels, these are not suitable for direct RS232 connectivity. This is a quick blind port of other DMA Tx examples// STM32 UART4 DMA TX (Tx PC.10, Rx PC.11) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* UART4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
/* GPIOC clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, 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_10 | GPIO_Pin_11; // PC.10 UART4_TX, potential clash SCLK CS43L22
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(GPIOC, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
}
/**************************************************************************************/
void UART4_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(UART4, &USART_InitStructure);
USART_Cmd(UART4, ENABLE);
}
/**************************************************************************************/
char Buffer[] = ''The quick brown fox jumps over the lazy dog
'';
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);
}
/**************************************************************************************/
void DMA1_Stream4_IRQHandler(void)
{
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA1_Stream4, DMA_IT_TCIF4))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream4, DMA_IT_TCIF4);
}
}
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the Priority Group to 2 bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the UART4 RX DMA Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream4_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();
UART4_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
/**************************************************************************************/