cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX@F4 Bug Report: Baudrate calculation wrong

mklatt9
Associate II
Posted on April 15, 2015 at 11:38

Hi,

I'm new to STM32CubeMX 4.7.0/ HAL F4 1.5.0. I do some evaluation at the STM32F4Disco-Board (STM32F407)

The baudrate calculation fails on USART3 @ 3 MBd/s with OVER8 enabled. fCLK is 42 MHz. It calculates 0x1C for the BRR but 0x16 (half of fraction field) is correct to achieve 3 Mbd. I corrected this by filling in 3818181 instead of 3000000 for the baudrate. This worked for me. Validated with scope after a bit of searching. It seem to be a bug in the calculation algo...

Greetings

#usart-stm32-baud #stm32cube-bug
3 REPLIES 3
stm32cube-t
Senior III
Posted on April 16, 2015 at 14:48

Hello,

Only the max value of the baud rate is adjusted according to clock settings.

It's the user responsibility to set the baudrate value actually required for his application (within the bounds automatically derived by CubeMX according to clock settings).

mklatt9
Associate II
Posted on April 16, 2015 at 22:45

Hello,

I should clarify this. There is an error in the HAL BRR register value calculation. If I enter 3,000,000 in CubeMX or init structure, the HAL will set the BRR to 0x1C. But 0x16 is the correct value. So I didn't get 3 MBd at the peripheral pins until I do my workaround. The OVER8 setting was switched on. Slower Baudrates will result in correct values/calculations.

Can you confirm this?

zh_jianjun
Associate II
Posted on April 23, 2015 at 11:49

try replace UART_BRR_SAMPLING16 and UART_BRR_SAMPLING8 in stm32f4xx_hal_uart.h with these:

#define UART_BRR_SAMPLING16(_PCLK_, _BAUD_)     (((_PCLK_)+(_BAUD_)/2)/_BAUD_)

__INLINE static uint16_t UART_BRR_SAMPLING8(uint32_t _PCLK_, uint32_t _BAUD_)

{

    uint16_t Div = (_PCLK_ + _BAUD_/2)/_BAUD_;    //result in 3 bit fraction, 15 bit Mantissa

    //When OVER8=1, the DIV_Fraction3 bit is not considered and must be kept cleared.

    uint16_t DIV_Mantissa = (Div & ~0x7)<<1;

    uint16_t DIV_Fraction = Div & 0x07;   

    return (DIV_Mantissa | DIV_Fraction);

}

The origin code is too complex to find errors.

my git commit:

https://git.oschina.net/dingtu/STM32Cube_FW_F4_BugFix/commit/ccdb3219c88559b7652d00859f5a82087af4afeb