cancel
Showing results for 
Search instead for 
Did you mean: 

UART4 on STM32F417

martinmartin9128
Associate
Posted on March 01, 2013 at 16:25

Hi Guys,

After reading the whole of Google and finding this thread (https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2F[STM32F4-Discovery]%20UART4%20Problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=4749) I'm with my hands in my hair 🙂

I can't get the UART4 to be working....

My Source code:

void Usart_Printf(void)

{

  usart_init();

 

  /* Output a message on Hyperterminal using printf function */

  printf(''\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r'');

}

void usart_init(void)

{

  /* 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

  */

      GPIO_InitTypeDef GPIO_InitStructure;

      USART_InitTypeDef USART_InitStructure;

      /* Enable GPIO clock */

      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

      /* Enable UART clock */

      RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);

      /* Connect PXx to USARTx_Tx*/

      GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);

      /* Connect PXx to USARTx_Rx*/

      GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);

      /* Configure USART Tx as alternate function  */

      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_Init(GPIOC, &GPIO_InitStructure);

      /* Configure USART Rx as alternate function  */

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

      GPIO_Init(GPIOC, &GPIO_InitStructure);

      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 configuration */

      USART_Init(UART4, &USART_InitStructure);

      /* Enable USART */

      USART_Cmd(UART4, ENABLE);

}

I think all the ports are OK (in the datasheet, 2 AF ports are mentioned for the UART4, (PA0,PA1 and PC10 and PC11), which I also don't get...

Can anyone help me?

Thanks guys (I guess Clive will answer this one? 😉 )
4 REPLIES 4
Posted on March 01, 2013 at 18:28

In what manner doesn't it work? Have you looked at the signals, confirmed timing and level expectations?

The code doesn't look problematic, so I think we need to widen our view of how it's attached to the outside world. The 3V CMOS outputs from the STM32 are not compatible with RS232 levels, so a converter of some manner is required.

The AF pin muxing matrix allows you to escape UART4 out of a couple of pins. You couple route them both to come out the A ports, or the C ports, or one on A, the other on C. It really depends on your pin utilization for this and other peripherals, and what works best for routing the PCB design.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 01, 2013 at 18:39

// STM32 UART4 (Tx PC.10, Rx PC.11) STM32F4 Discovery - sourcer32@gmail.com
// PC11 technically conflicts with SCLK on CS43L22
#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);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
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);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
UART4_Configuration();
while(1)
{
while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(UART4, 0x49); // Send 'I'
}
while(1); // Don't want to exit
}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 01, 2013 at 18:40

Ok, what tool chain are you using? And how do you expect it to associate UART4 with stdout via printf()/putchar()/puts(), etc?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
martinmartin9128
Associate
Posted on March 01, 2013 at 23:00

Hi Clive,

Thanks for the swift and extended replies! The answers: Toolchain used: arm-none-eabi-gcc-4_6 I connected the UART4 Rx and Tx to a FTDI232RL (CMOS to USB controller via virtual comport, chip should accept 3.3 volt IO) I havn't hooked up a scope yet, I wanted to let my code checked first. And I was under the impression that the printf() function was retargeted to the UART4, but now I'm not sure if that is the case...... I will test it with your

USART_SendData(UART4, 0x49); // Send 'I'

statement. Thanks for the help and insight 🙂