cancel
Showing results for 
Search instead for 
Did you mean: 

USART display error on STM32 NUCLEO H533RE

Rav3nPho3nix
Visitor

Hi, i'm currently beginning to create my own RTOS (on bare metal) for my NUCLEO H533RE.

My source code is available here : https://github.com/Rav3nPho3nix/Rav3nTOS

Here is my issue : i'm trying to implement USART 2 for my board to have a "print" tool. I can connect with "minicom" to see the output from the ST LINK.

 

My main function (the main function on my repo is not up to date) is here :

#include <stdint.h>
#include "platform.h"
#include "usart.h"

int main(void) {
    platform_init();
    while (1) {
        usart_write_string("Test\n\r");
        for (volatile uint32_t i = 0; i < 1000000; i++);
    }
}

 It just call 'platform_init' then print with usart 2.

My 'platform_init' just initialize usart by setting the baud rate to 115200 :

usart_init(115200U);

 And to finish, here is the code for usart : https://github.com/Rav3nPho3nix/Rav3nTOS/blob/main/bsp/stm32h533/usart.c

I think my problem come from this line when is calculate the brr value :

    // Set up BBR
    // 64 Mhz of frequency
    // BBR = (64,000,000) / BaudRate
    USART2->BRR = 64000000U / baudrate;

Here is supposed that the frequency is 64 Mhz, but i'm not sure. I have read the reference manual and datasheet of the STM32H533 but i didn't found what is the correct frequency value.

As a result, when i use minicom to display my usart 'print', these characters appears : ����怆, wich correspond to my `Test\r\n', so it's really just a brr value calculation error for me.

Do you know the correct value ?
Thx in advance.

2 REPLIES 2
Pavel A.
Super User

>I think my problem come from this line when is calculate the brr value :

Yes, it doesn't look good. Please use the ST examples how to set up a UART and get the BRR value. For one, here.

 

Andrew Neil
Super User

@Rav3nPho3nix wrote:

when i use minicom to display my usart 'print', these characters appears : ����怆


Yes, that will be due to incorrect baud rate.

 


@Rav3nPho3nix wrote:

is supposed that the frequency is 64 Mhz, but i'm not sure..


Then you need to check!

Review your clock settings.

eg, route the clock to an MCO pin and measure it on a scope or frequency counter.

 


@Rav3nPho3nix wrote:

i didn't found what is the correct frequency value.


It is whatever your code configures it to be!

So check your code.

 

This is why ST provides tools like CubeMX.

Maybe at least do it in CubeMX to start, and then take your settings from there ...

 

PS:

 


@Rav3nPho3nix wrote:

Hi, i'm currently beginning to create my own RTOS (on bare metal) .


That's rather ambitious for a beginner project!

As you've seen, doing this does require a deep understanding on the inner workings of the chip.

I would suggest that you need to spend some time getting a good grip on the basics before embarking on such an advanced project.

eg, see:

https://community.st.com/t5/stm32-mcus-products/for-better-learning-stm32-programming-and-debugging/m-p/719485/highlight/true#M260696

also: 

https://community.st.com/t5/stm32-mcus-products/for-better-learning-stm32-programming-and-debugging/m-p/719468/highlight/true#M260690

 

PPS:

Sorry, I mis-read "beginning" as "beginner".

But it does still seem that you need a bit more familiarity with the platform ...

 

Implementing UART receive and transmit functions on an STM32

Wiki: Getting started with STM32 UART

ST's YouTube channel: https://www.youtube.com/@stmicroelectronics/search?query=uart

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.