AnsweredAssumed Answered

stm32f0: effect of bootloader on usart

Question asked by roel on Jun 25, 2013
Latest reply on Mar 27, 2014 by roel
Hi there,

I'm using ST's bootloader in rom to program my device and USART1 for communications. Now I observed the following problem: when my code runs directly after startup, it works fine. However, when my code receives control via the bootloader, the USART speed seems a little but off and every few characters are corrupted on the rx side. I found a different value for the BRR which works for the post-bootloader-path, but now this value corrupts characters for the direct startup -- exactly the other way around.

I'm currently using a work around: I determine the presence of the bootloader by testing some registers at startup, and choose BRR accordingly, but this doesn't feel safe.

Any comments? Tia. This is my init code:

void init_usart(void)
    USART_InitTypeDef USART_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;


    USART_ClockInitTypeDef  USART_ClockInitStructure;
    USART_ClockInit(USART1, &USART_ClockInitStructure);

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);


    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);

    /* Configure USART1 pins:  Rx and Tx ----------------------------*/
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9 | GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOA, &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_Init(USART1, &USART_InitStructure);