6 years, 8 months ago.

change baudrate for fe411re to 3686400

Hello i'm using the nucleo f411re and i want use the usart at speed of 3686400 or (3000000 , 3200000) someone can suggest me the right way ? i think that only serial.baud (3686400 ); is not enough Thank you very much!

2 Answers

6 years, 8 months ago.

Stefano -

I think the problem you may be having is that you are using the default usart, USART2, which is not capable of operating at a target baud rate of 3686400 without making additional changes to the mbed default uart configuration for the nuclei f411re (e.g. reducing the default mbed oversampling from 16 to 8).

The f411re’s USART1 and USART6 should be capable of operating at a target baud rate of 3686400 since they run off of the APB2 bus. The APB2 bus has an f_pclk of 100MHz when the MCU is clocked at 100 MHz. USART2 runs off of the APB1 bus, which only has an f_pclk of 50 MHz. USART2 therefore can only operate at half the maximum baud rate of USART1 and USART6.

General information on setting the f411re usart baud rate can be found in Section 19.3.4 of the MCU reference manual RM0383. That section describes how to configure the BRR register for the baud rate closest to the desired target and the associated baud rate error.

The mbed api sets the baud rate using the init_uart function in serial_api.c, using oversampling by 16 (OVER8 = 0). This function calculates the BRR register DIV_Mantissa and DIV_Fraction values using the macro USART_BRR(_PCLK_, _BAUD_) which you can find in "stm32f4xx_hal_usart.h".

The APB2 f_pclk is 100 MHz for the nucleo f411re board clocked at 100 Mhz. For a target baud rate of 3686400 with 16x oversampling, the desired USARTDIV value is 1.695. The closest available USARTDIV value is 1.6875 (DIV_Mantissa = 1, DIV_Fraction = 11). This gives an actual baud rate of 3703703.7, or an error of 0.4672 percent.

If you switch to USART1 or USART6 and still have problems, you can check that the USART baud rate is being correctly configured by reading out the values in the BRR register after you have initialized the uart. Note that you are trying to run the usart at the maximum specified value for the f411re, so other factors may come into play that could effect its performance at this rate.

Accepted Answer

Hello thanks for your reply it's very interesting, i'm beginning with mbed and nucleo so i want ask you one thing about stm32f4xx_hal_usart.h file. I've included "stm32f4xx_hal_usart.h" in my project and i haven't get error but i can't find this for modify, do you know where i can find it ?Thank you very much!

posted by stefano funicella 10 Sep 2017

The HAL drivers can be found in the mbed source files at this link:

https://developer.mbed.org/users/mbed_official/code/mbed-dev/shortlog

You don’t have to include "stm32f4xx_hal_usart.h" or any of the other STM HAL driver files if you are using the online compiler - the compiler does that for you. You don’t want to modify any of these files. Instead, take a look at the examples that STM has provided in their firmware example package for the F4 series MCUs: STM32CubeF4. You can download this package as a zip file. The zip file contains all of the HAL files. The path is: targets->TARGET_STM->TARGET_STM32F4->device. The zip file also contains UM1725 at the very end of the directory. This is the User Manual for this firmware package.

You can find the STM32CubeF4 firmware package at this link:

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

You might also want to look at this thread where I provided some hints on how to use the STM firmware examples with mbed. The thread deals with a question about the STM32L4 MCU on the nucleo-L432KC board, but the approach is the same for the STM32F4 series.

https://developer.mbed.org/questions/78045/why-am-in-geting-30-Erors-just-by-import/

posted by J Roth 10 Sep 2017
6 years, 8 months ago.

Hi Stefano,

The examples on the Serial API reference page should help: https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/interfaces/digital/Serial/#examples

Please let me know if you have any questions!

- Jenny, team Mbed