2015-04-15 02:38 AM
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-bug2015-04-16 05:48 AM
2015-04-16 01:45 PM
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?2015-04-23 02:49 AM
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