AnsweredAssumed Answered

STM32L152-EVAL USART baud rate is not correct except 9600

Question asked by jin.xin on Apr 2, 2013
Latest reply on Jun 21, 2013 by venkat.ram
I found it is not correct on STM32L152-EVAL USART baud rate. The clock configuration is set as below. I use printf to show some character such as "hello world" on the terminal. It only works with 9600. And the baud rate would be not correct with setting to 115200. I am not sure if the demo board on my hand is broken. Strange.
  *=============================================================================
  *                         System Clock Configuration
  *=============================================================================
  *        System Clock source          | PLL(HSE)
  *-----------------------------------------------------------------------------
  *        SYSCLK                       | 32000000 Hz
  *-----------------------------------------------------------------------------
  *        HCLK                         | 32000000 Hz
  *-----------------------------------------------------------------------------
  *        AHB Prescaler                | 1
  *-----------------------------------------------------------------------------
  *        APB1 Prescaler               | 1
  *-----------------------------------------------------------------------------
  *        APB2 Prescaler               | 1
  *-----------------------------------------------------------------------------
  *        HSE Frequency                | 8000000 Hz
  *-----------------------------------------------------------------------------
  *        PLL DIV                      | 3
  *-----------------------------------------------------------------------------
  *        PLL MUL                      | 12
  *-----------------------------------------------------------------------------
  *        VDD                          | 3.3 V
  *-----------------------------------------------------------------------------
  *        Vcore                        | 1.8 V (Range 1)
  *-----------------------------------------------------------------------------
  *        Flash Latency                | 1 WS
  *-----------------------------------------------------------------------------
  *        SDIO clock (SDIOCLK)         | 48000000 Hz
  *-----------------------------------------------------------------------------
  *        Require 48MHz for USB clock  | Disabled
  *-----------------------------------------------------------------------------
  *=============================================================================
I also use the driver in the library to configure the USART as below:
    USART_InitTypeDef USART_InitStructure;
     GPIO_InitTypeDef GPIO_InitStructure;
     
     /* --------------------------- System Clocks Configuration -----------------*/
     /* USART3 clock enable */
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
     
     /* GPIOC clock enable */
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);


     /*-------------------------- 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_40MHz;
     GPIO_Init(GPIOC, &GPIO_InitStructure);
     
     /* Connect USART pins to AF */
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);


     /* USARTx configuration ------------------------------------------------------*/
     /* USARTx configured as follow:
            - BaudRate = 9600 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 = 9600;
     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(USART3, &USART_InitStructure);
  
    /* Enable USART */
     USART_Cmd(USART3, ENABLE);     

Outcomes