AnsweredAssumed Answered

Garbage character in Usart buffer on reset

Question asked by vigelette.george.001 on Jan 6, 2014
Latest reply on Jan 7, 2014 by vigelette.george.001
Hello Everyone, 

I have been having this issue for a while on a STM32L100-Discovery board, apparently on reset there is always a garbage character transmitted to the terminal.  After the reset the USART works fine.  My code to initialize the USART is below, any help or ideas would be welcome and appreciated.  Thanks in advance.

GPIO_InitTypeDef GPIO_InitStructure;
     USART_InitTypeDef USART_InitStructure;
     NVIC_InitTypeDef   NVIC_InitStructure;
    int c = 0x1FFFF;


     /**
      *  USART1 GPIO Configuration
           PA9      ------> USART1_TX
           PA10      ------> USART1_RX
     */


     /*Enable or disable the AHB1 peripheral clock */
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);


     /*Configure GPIO pin */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
     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(GPIOA, &GPIO_InitStructure);


     /*Configure GPIO pin alternate function */
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);


     /*Configure GPIO pin alternate function */
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);


     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(USART1, &USART_InitStructure);




     USART_Cmd(USART1, DISABLE);
     NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );


     /* Enable USART Interrupt */
     NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 8;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);




     /* Enable USART */
     USART_Cmd(USART1, ENABLE);


     // enable interrupt for uart
     USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
     USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

On first printf we see, second printf is fine:

ÿBegin
Success

Outcomes