STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin
-
- Posts: 34
- Joined: Wed Jul 12, 2023 11:09 am
STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin
Hi ,
I am trying make these USARTs to work , using the API , it doesn't , so for for exemple , USART1 :
- before the setup :
// setting PA10 as USART1 Rx : might be correct , according the DS , the RM , and the variant file
HardwareSerial Serial1(PA_10);
- in the setup :
Serial1.begin(250000); // at this point , USART1 and PA10 must be configured
but when I print the registers on the monitor , nothing is configured :
GPIOA_MODER is not correct for PA10 , same thing for GPIOA_AFRH
USART1->CR1 is 0 , it must be at least 1
then I looked at the peripheral clock enable registers , oho :
the peripheral clock enable bit for PORTA is not set , nothing can work , same thing for the peripheral clock enable bit for USART1
as a test I have put a typo in the file of the variant for this STM32 : I got an compilator error , so I think STM32duino tries to configure the STM32 with the right parameters , but it doesn't succeed
if have tried to look further to show were the bug can be , but I am too limited in C++ and arduino core making , to find it
thanks for reply
I am trying make these USARTs to work , using the API , it doesn't , so for for exemple , USART1 :
- before the setup :
// setting PA10 as USART1 Rx : might be correct , according the DS , the RM , and the variant file
HardwareSerial Serial1(PA_10);
- in the setup :
Serial1.begin(250000); // at this point , USART1 and PA10 must be configured
but when I print the registers on the monitor , nothing is configured :
GPIOA_MODER is not correct for PA10 , same thing for GPIOA_AFRH
USART1->CR1 is 0 , it must be at least 1
then I looked at the peripheral clock enable registers , oho :
the peripheral clock enable bit for PORTA is not set , nothing can work , same thing for the peripheral clock enable bit for USART1
as a test I have put a typo in the file of the variant for this STM32 : I got an compilator error , so I think STM32duino tries to configure the STM32 with the right parameters , but it doesn't succeed
if have tried to look further to show were the bug can be , but I am too limited in C++ and arduino core making , to find it
thanks for reply
Last edited by trimarco232 on Wed Aug 07, 2024 6:29 pm, edited 1 time in total.
-
- Posts: 131
- Joined: Mon May 06, 2024 1:46 pm
- Location: Germany
Re: STM32G431CBU6 (and others) : USART1 to 4 don't work ...
Those boards from WeActStudio?
Normally I connect FTDI-adapter to PA3 (RX) and PA2 (TX)
In one case, when I needed PA0 - PA7 for a display, I placed a
before begin(115200).
It worked and I don't have to look into registers ...
Normally I connect FTDI-adapter to PA3 (RX) and PA2 (TX)
In one case, when I needed PA0 - PA7 for a display, I placed a
Code: Select all
Serial.setRx(PB10);
Serial.setTx(PB11);
It worked and I don't have to look into registers ...
Re: STM32G431CBU6 (and others) : USART1 to 4 don't work ...
It's working fine on WeAct G431CB board.
With generic G341 and my WeAct G431 variant.
With generic G341 and my WeAct G431 variant.
-
- Posts: 34
- Joined: Wed Jul 12, 2023 11:09 am
STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin
deleted
Last edited by trimarco232 on Wed Aug 07, 2024 6:31 pm, edited 2 times in total.
Re: STM32G431CBU6 (and others) : USART1 to 4 don't work ...
@trimarco232
No. I didn't use LPUART. I used USART 1-3.
Serial1 doesn't have to be defined as it's defined in variant.h for WeaAct G431.
In your case, you give only one pin to constructor and this means that it will be initialized in half-duplex mode using one pin for TX and RX. In this mode registers might be setup differently.
Signal on TX pins of Serial1 (PA9) and Serial3 (PB8):
In May you wrote that you don't have problems with UART3... viewtopic.php?t=2400
So does it work or not ??
No. I didn't use LPUART. I used USART 1-3.
Code: Select all
//HardwareSerial Serial1(PA10, PA9);
HardwareSerial Serial2(PB4, PB3);
HardwareSerial Serial3(PB9, PB8);
void setup() {
// put your setup code here, to run once:
Serial.begin(1);
while (!Serial) {}
delay(100);
Serial.println("st");
Serial1.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("1");
Serial1.println("1");
Serial2.println("1");
Serial3.println("1");
}
Code: Select all
// UART Definitions
#ifndef SERIAL_UART_INSTANCE
#define SERIAL_UART_INSTANCE 1
#endif
// Default pin used for generic 'Serial' instance
// Mandatory for Firmata
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX PA10
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX PA9
#endif
Signal on TX pins of Serial1 (PA9) and Serial3 (PB8):
In May you wrote that you don't have problems with UART3... viewtopic.php?t=2400
So does it work or not ??
-
- Posts: 34
- Joined: Wed Jul 12, 2023 11:09 am
STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin
oh yes , sorry , you have pointed the right thing :
the sketch with USART3 works , printing the registers to be sure :
USART3->CR1 : 45
LPUART1->CR1 : 0
my problem is actually that I only want the USART to work as a receiver ; Tx pin will be used for another task
so if I declare :
HardwareSerial Serial3(PB11); /// PB11 is USART3 Rx pin
it does not work (and in addition , makes the STM32 partially to crash)
maybe you have an idea how to declare this the right way ?
now :
USART3->CR1: 45
LPUART1->CR1: 45
USART2->CR1: 45
USART1->CR1: 45
UART4->CR1: 45
but still with both Rx and unwanted Tx pins must be declared
the sketch with USART3 works , printing the registers to be sure :
USART3->CR1 : 45
LPUART1->CR1 : 0
my problem is actually that I only want the USART to work as a receiver ; Tx pin will be used for another task
so if I declare :
HardwareSerial Serial3(PB11); /// PB11 is USART3 Rx pin
it does not work (and in addition , makes the STM32 partially to crash)
maybe you have an idea how to declare this the right way ?
now :
USART3->CR1: 45
LPUART1->CR1: 45
USART2->CR1: 45
USART1->CR1: 45
UART4->CR1: 45
but still with both Rx and unwanted Tx pins must be declared
-
- Posts: 34
- Joined: Wed Jul 12, 2023 11:09 am
Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin
what I want to do , all USARTs Rx only :
USART3 Rx = PB11
LPUART1 Rx = PB10
USART2 Rx = PA15
USART1 Rx = PA10
UART4 Rx = PC11
USART3 Rx = PB11
LPUART1 Rx = PB10
USART2 Rx = PA15
USART1 Rx = PA10
UART4 Rx = PC11
Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin
UART - as the name says is a two way interface (Universal Asynchronous Receiver-Transmitter).
You can use it in full duplex (2 pins: TX, RX) or half duplex mode (1 pin, TXRX).
https://github.com/stm32duino/Arduino_C ... wareserial
You can use it in full duplex (2 pins: TX, RX) or half duplex mode (1 pin, TXRX).
https://github.com/stm32duino/Arduino_C ... wareserial
-
- Posts: 34
- Joined: Wed Jul 12, 2023 11:09 am
Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin
STM32 , from the beginning , can do Rx or Tx alone , and the other pin can be used for another purpose
( I have being playing with STM32 a looong time before STM32duino )
some of the features of the USARTs (from the reference manual of your G431, a very interesting document ! ) :
• Separate enable bits for transmitter and receiver
• Separate signal polarity control for transmission and reception
• Swappable Tx/Rx pin configuration
...
( I have being playing with STM32 a looong time before STM32duino )
some of the features of the USARTs (from the reference manual of your G431, a very interesting document ! ) :
• Separate enable bits for transmitter and receiver
• Separate signal polarity control for transmission and reception
• Swappable Tx/Rx pin configuration
...
Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin
I don't know anything specific about G431, but there are many hardware features that STM32DUINO does not support, even for F103 processors (which I guess would be the most commonly used ones with STM32DUINO).trimarco232 wrote: ↑Thu Aug 08, 2024 8:48 am some of the features of the USARTs (from the reference manual of your G431, a very interesting document ! ) :
• Separate enable bits for transmitter and receiver
...
It might be as simple as setting things up with STM32DUINO, and then turning off or on a couple of register bits. From the hardware point of view, what does the "very interesting document" say? Of course, doing that might upset the STM32DUINO code in some way, if not now, potentially later with some future modification, and it would be up to you to work around that.
There is no harm in asking the STM32DUINO developers to consider adding a feature like that (assuming that they really have not done that), but my feeling is that receive-only serial is a bit too niche.