Page 1 of 1

STM32G431CBU6 (and others) : how to make LPUART1 to work ?

Posted: Thu May 16, 2024 10:24 pm
by trimarco232
this code works :

Code: Select all

HardwareSerial Serial3(PB11, PB10);  /// USART3 works
uint64_t millis_duration = 100, millis_begin;

void setup() {
  Serial.begin(115200); // USB
  Serial3.begin(19200);
}
void loop() {
  if (millis() - millis_begin >= millis_duration) {  // debug uart
    millis_begin += millis_duration;
    Serial3.write("UUU"); // PB10
  }
}
this one don't :

Code: Select all

uint64_t millis_duration = 100, millis_begin;

void setup() {
  Serial.begin(115200);
  SerialLP1.begin(19200);
}
void loop() {
  if (millis() - millis_begin >= millis_duration) {  // debug uart
    millis_begin += millis_duration;
    SerialLP1.write("UUU"); // PB11
    Serial.println(RCC->CCIPR, BIN);  /// debug
  }
}
the problem could be that LPUART1 is configured to work with HSI16 clock , instead of PCLK , even when it is not used
if I try to clear the LPUART1SEL[1] bit manually , it won't work , and in addition , USART3 gets a false clock
so not the right way : please which is the working one ?

Re: STM32G431CBU6 (and others) : how to make LPUART1 to work ?

Posted: Tue May 21, 2024 12:12 pm
by fpiSTM
Hi @trimarco232
LPUART1 has some constraint around clock vs speed.
/*
* Note that LPUART clock source must be in the range
* [3 x baud rate, 4096 x baud rate]
* check Reference Manual
*/

Re: STM32G431CBU6 (and others) : how to make LPUART1 to work ?

Posted: Thu May 30, 2024 2:51 pm
by trimarco232
Hi @ fpiSTM
OK , thanks , my fault , again : now LPUART1 and RCC_CCIPR are configured ok since I use an adequate baudrate
BUT , it didn't output or input anything , I had to set manually the MODER and the AFR[1] registers of the PORTB , in order to make it to work : is there any else secret reason for this ?

Re: STM32G431CBU6 (and others) : how to make LPUART1 to work ?

Posted: Thu May 30, 2024 3:18 pm
by fpiSTM
It is not normal, the pin is configured using the value from peripheral pins.
Anyway looking at your code, I don't see how you instantiate SerialLP1?
If you used the generic target then LPUART1 is well initialized but for pins PAx not the one rol PBx. This would explain your issue. Simply change the default pins used by the one you want.

Re: STM32G431CBU6 (and others) : how to make LPUART1 to work ?

Posted: Thu May 30, 2024 4:09 pm
by trimarco232
a blank sketch with just :
HardwareSerial SerialLP1(PB10, PB11); // LPUART1_RX , LPUART1_TX
outputs the error :
multiple definition of `SerialLP1' ?

(so I thought PB10 , PB11 are the generic target ...)

Re: STM32G431CBU6 (and others) : how to make LPUART1 to work ?

Posted: Thu May 30, 2024 6:01 pm
by fpiSTM
This is normal it is already instantiate.

Here the default pins used for Serial instance (defined to be SerialLP1):
https://github.com/stm32duino/Arduino_C ... #L158-L170

See the wiki which explain how it works and how change default pins.
https://github.com/stm32duino/Arduino_C ... wareserial

So if you want use PB10/11, do in setup() before Serial.begin (SerialLP1.begin()):

Code: Select all

    Serial.setRx(PB10);
    Serial.setTx(PB11);