why i need SetRx/SetTx before use Serial?

Post here first, or if you can't find a relevant section!
Post Reply
ahsanu
Posts: 7
Joined: Wed Jul 27, 2022 1:14 pm

why i need SetRx/SetTx before use Serial?

Post by ahsanu »

i don't know if this question already answered, but.

when i try to doing serial communication(STM32F407VGTx) in default Serial instance i need to set

Code: Select all

Serial.setRx(PA10);
Serial.setTx(PA9);
even i already change default pin on variant_generic.h (i use generic board), and i have use --board-options on arduino-cli

Code: Select all

#ifndef PIN_SERIAL_RX
  #define PIN_SERIAL_RX         PA10
#endif
#ifndef PIN_SERIAL_TX
  #define PIN_SERIAL_TX         PA9
#endif

Code: Select all

arduino-cli compile -b STMicroelectronics:stm32:GenF4 --board-options pnum=GENERIC_F407VGTX -v -u
before add setRx/Tx serial communication not working, and after add setRx/Tx serial working as expected

it is normal way to use Serial instance?
thanks for any help
by ABOSTM » Mon Aug 01, 2022 4:32 pm
Hi @ahsanu,
It is not normal, I mean you should be able to use Serial without setRx()/setTx()

But,
In variant_generic.h , you changed:
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX PA10
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX PA9
#endif

This implicitly change Uart instance from UART4 to USART1 (see PeripheralPins.c)
So you should also change (in variant_generic.h)
// UART Definitions
#ifndef SERIAL_UART_INSTANCE
#define SERIAL_UART_INSTANCE 1
#endif
Go to full post
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: why i need SetRx/SetTx before use Serial?

Post by ABOSTM »

Hi @ahsanu,
It is not normal, I mean you should be able to use Serial without setRx()/setTx()

But,
In variant_generic.h , you changed:
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX PA10
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX PA9
#endif

This implicitly change Uart instance from UART4 to USART1 (see PeripheralPins.c)
So you should also change (in variant_generic.h)
// UART Definitions
#ifndef SERIAL_UART_INSTANCE
#define SERIAL_UART_INSTANCE 1
#endif
ahsanu
Posts: 7
Joined: Wed Jul 27, 2022 1:14 pm

Re: why i need SetRx/SetTx before use Serial?

Post by ahsanu »

thanks for reply.
even though the definition is above exactly, thank you for the help

Code: Select all

// UART Definitions
#ifndef SERIAL_UART_INSTANCE
  #define SERIAL_UART_INSTANCE  4 	//<<<<<<<<<<<<<<<<<<
#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

Post Reply

Return to “General discussion”