Skip to main content
Explorer II
July 15, 2024
Solved

[SOLVED] STM32G431 : reading the current value of USART2->CR1 (and display it , for arduino style debugging)

  • July 15, 2024
  • 3 replies
  • 2130 views

 

Post

[EDIT] displaying the values of the registers works on STM32duino arduino console

Hi ,

I am in the arduino world ; for some more particular tasks , the existing API is not enough , so I have to write my own code and debug it
I am trying to spy the actual value (setting) of some registers of some peripherals
this generally works , but I have a problem with USART2->CR1 : it always says value is "0" , but this is not possible , because USART2 is currently working !
Quetion : is there an other way to designate USART2->CR1 , in ordre to read the right value ?
this is the code : USART2 is outputed to a logical analyser , so can I see it really works

MCU is generic STM32G431CBUx ; thanks !

CODE: SELECT ALL

HardwareSerial Serial2(PA3, PA2); // configure USART2
uint64_t millis_duration = 100, millis_begin; // configure a 100ms tick
void setup() {
 Serial.begin(115200); // USB to monitor
 delay(3000);
 Serial2.begin(250000); // PA2 USART2 Tx , to logical analyser
}
void loop() {
 if (millis() - millis_begin > millis_duration) { // debug USART2
 millis_begin += millis_duration;
 Serial.println(USART2->CR1, BIN); // debug to monitor , display is always "0" ?
 Serial2.write(USART2->CR1); // can see the signal with logical analyser , confirms USART2 is working , confirms read CR1 value is false
 }
}
    This topic has been closed for replies.
    Best answer by mwalt.3

    the problem was that , I tried to configure the USARTs as receive only , but this is not an option at STM32duino , because it accepts only Rx + Tx pins mode , or single wire half duplex on Tx pin mode

    so STM32duino did nothing , nor signalling an error

    people wanting to use USARTs as Rx only , are terrible perverts

    3 replies

    Super User
    July 15, 2024

    Are you sure USART2 = Serial2?

    Try to read/print *all* USARTs' CR1.

    JW

    Super User
    July 15, 2024

    @mwalt.3 wrote:

    is there an other way to designate USART2->CR1 , in ordre to read the right value 


    Why not use the debugger?

    Arduino IDE now supports the debugger - doesn't it?

    mwalt.3Author
    Explorer II
    July 21, 2024

    it looks like there is something wrong in STM32duino with this (not so) particular MCU

    in addition , STM32duino does not seem to support debugger , so I will switch to STM32cube for this project (will be back)

    Super User
    July 22, 2024

    @mwalt.3 wrote:

    it looks like there is something wrong in STM32duino


    Have you reported this to them - on their forum and/or their GitHub?

    https://www.stm32duino.com/

    https://github.com/stm32duino 

    https://github.com/stm32duino/Arduino_Core_STM32/issues ?

    mwalt.3Author
    Explorer II
    July 27, 2024

    I will do , after some further researches

    what seams to be clear now :

    - displaying the registers on arduino's monitor , works

    - I am using the right variant , in order to configure the USARTS (putting a typo into the variant's file leads to a compiler error)

    - nevertheless , STM32duino doesn't configure the USART , because USART1->CR1 is always 0

    - and this , even for sure , as the corresponding bit is not set in the peripheral clock enable register