STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin

STM32ardui
Posts: 131
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin

Post by STM32ardui »

ozcar wrote: Thu Aug 08, 2024 8:04 pm ... but there are many hardware features that STM32DUINO does not support, ...
The idea behind Arduino was a board together with an IDE and a skeleton of things to do one time and things to do again and again - setup() and loop(). People don't have to care about variant-files, clock-tree etc. Such a system will be limited comparing to what a STM32 can do.
fpiSTM
Posts: 1819
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 99
Location: Le Mans
Contact:

Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin

Post by fpiSTM »

trimarco232 wrote: Thu Aug 08, 2024 8:48 am 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
...
The core provides Arduino Core implementation. So not all feature are available. For UART, HardwareSerial support RX/TX and half duplex using TX.
If yo want use all features, you can disable the Arduino API part using the HAL UART part for Serial then implement your own feature: HAL_UART_MODULE_ONLY

See https://github.com/stm32duino/Arduino_C ... odule-only
trimarco232
Posts: 34
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin

Post by trimarco232 »

Hi fpiSTM , thanks !
I have tried to to declare first the the Rx and Tx pins , as STM32duino wants , and then make the Tx pin an input ; this works , but for a short moment , the Tx pin will be OUTPUT : HIGH , in conflict with the output of the device it is connected to , so this is not an option for me
my problem here is that I want/need to use the arduino stuff in order to handle the interrupts, the buffers aso. , so I can use the confortable functions like : if (Serial.available() and/or Serial.read();
so if I use HAL_UART_MODULE_ONLY , will I have to rewrite all the interrupt/buffer stuff , or hopefully , only the setup of the USART ?
fpiSTM
Posts: 1819
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 99
Location: Le Mans
Contact:

Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin

Post by fpiSTM »

All HWSerial stuff is removed. So yes you will have to manage all.
trimarco232
Posts: 34
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

Re: STM32G431CBU6 (and others) : USARTs : how to declare only Rx pin

Post by trimarco232 »

ok , I will try something different :
1) instead of configure the two pins , for exemple : HardwareSerial Serial1(PA10, PA9);
just configure the Tx pin : HardwareSerial Serial1(PA9);
this will configure USART1 as half-duplex single wire mode , on PA9 = Tx pin ; at this point , PA9 is high Z , so there is no risk of HIGH / LOW conflict with another device ; the following has to be done by writing to the registers :mrgreen:
2) swap Tx and Rx pin in the USART : the Tx signal will be swapped to PA10 , where I want my USART Rx alone ; this should work so , but before I must config PA10 as alternate function = USART1 Rx
3) now I can configure ex Tx pin PA9 of whatever I need
4) eventually , unswap the pins and reconfigure the USART as Rx only ... :shock:
Post Reply

Return to “PR's bugs and enhancements”