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

Post Reply
trimarco232
Posts: 27
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

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

Post 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 ?
User avatar
fpiSTM
Posts: 1776
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 92
Location: Le Mans
Contact:

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

Post 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
*/
trimarco232
Posts: 27
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

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

Post 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 ?
Last edited by trimarco232 on Thu May 30, 2024 3:48 pm, edited 1 time in total.
User avatar
fpiSTM
Posts: 1776
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 92
Location: Le Mans
Contact:

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

Post 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.
trimarco232
Posts: 27
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

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

Post 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 ...)
Last edited by trimarco232 on Thu May 30, 2024 11:31 pm, edited 3 times in total.
User avatar
fpiSTM
Posts: 1776
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 92
Location: Le Mans
Contact:

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

Post 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);
Post Reply

Return to “PR's bugs and enhancements”