Page 1 of 1

why i need SetRx/SetTx before use Serial?

Posted: Sat Jul 30, 2022 9:45 pm
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

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

Posted: Mon Aug 01, 2022 4:32 pm
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

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

Posted: Wed Aug 03, 2022 9:55 pm
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