Skip to main content
Graduate
April 1, 2024
Solved

STMG01 Baremetal UART not Working

  • April 1, 2024
  • 3 replies
  • 2002 views

Hi, I wonder has anyone experience with baremetal USART implementation as I have attached a Source file for USART for a 'STM32G0B1RET' discovery board but it just sits there and doesn't transmit anything? See attached (usart.c). I have basically just copied this from a working F4 board and modified it for a G0 board (assuming it would work!?)...

 

 

    This topic has been closed for replies.
    Best answer by waclawek.jan

    > 'STM32G0B1RET' discovery board

    Do you mean Nucleo board?

    I compiled your code (commenting out SetSystemClockTo16Mhz() as you did not provide that function, but simply leaving the default HSI16 clock, that's 16MHz too), and on Nucleo I can see the transmitted data on PA2 (and also LED on PA5 blinking slowly).

    JW

     

    PS. You set USART2_BRR in USART1 setup, but you don't call that function here.

    3 replies

    Super User
    April 1, 2024

    > 'STM32G0B1RET' discovery board

    Do you mean Nucleo board?

    I compiled your code (commenting out SetSystemClockTo16Mhz() as you did not provide that function, but simply leaving the default HSI16 clock, that's 16MHz too), and on Nucleo I can see the transmitted data on PA2 (and also LED on PA5 blinking slowly).

    JW

     

    PS. You set USART2_BRR in USART1 setup, but you don't call that function here.

    PLee.3Author
    Graduate
    April 2, 2024

    Hi JW,

    Thanks for trying it out I have just had a closer look and something really odd is happening if you use "UART2_send" it transmits to UART1 TX (PC4) and if you use "UART1_send" it transmits to UART2 TX (PA2)? I can't workout why it's doing this as the UART send commands it clearly states the correct Registries:-

    void UART1_send(char *msg, size_t len){
    for (uint64_t i=0; i<len; i++)
    {
     // send character
     USART1->TDR = msg[i];
     // wait for transmit complete (ts)
     while(!(USART1->ISR & (1 << 6)));
    }
    }

     

    PLee.3Author
    Graduate
    April 2, 2024

    Hi JW, Now it explains as I used the incorrect pinouts and the pins where swapped! as below diagram (wrong one is at the bottom).

    G070RB Pinout.PNG

    STMF32G01B1RE.PNG

     

    Super User
    April 2, 2024

    Thanks for coming back with the solution. Please click on "Accept as solution" in that post so that the thread is marked as solved.

    Where is that incorrect picture from?

    JW