cancel
Showing results for 
Search instead for 
Did you mean: 

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

mwalt.3
Associate II

 

PostHi ,

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
  }
}
5 REPLIES 5

Are you sure USART2 = Serial2?

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

JW

Andrew Neil
Evangelist III

@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.3
Associate II

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)


@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 ?

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