Where put macro to enable RS485?

I want my Pixhawk 4 to communicate with servomotors over an RS485 interface. For that, I have a communication module, which takes UART as an input and translates it to RS485. The Pixhawk needs to tell the module via the ~RE and DE pins whether it should read or write messages. I want to use the TELEM2 port of the Pixhawk to connect to the module and have its RTS pin connect to both ~RE and DE of the module.

Reading through the code of the file stm32_serial.c (lines 93, 187 and 965), I see that I need to set/alter a few macros for this to work:

  • “CONFIG_USART3_RS485” needs to be defined.
  • RXDMA/TXDMA and RS485 cannot be active on the same port at the same time, so “CONFIG_USART3_RXDMA” and “CONFIG_USART3_TXDMA” must not be defined.
  • The direction pin that will connect to ~RE and DE must be set with the appropriate configuration through the macro “GPIO_USART3_RS485_DIR”.
  • The direction polarity should be set to 1 via the macro “CONFIG_USART1_RS485_DIR_POLARITY”.

The macros that start with “CONFIG_” can handily be set in a defconfig file via the terminal command “make px4_fmu-v5 menuconfig”. However, the macro “GPIO_USART3_RS485_DIR” cannot be configured there. I found this answer on Github, which suggests to put the following line somewhere into the board.h file:


I put it in line 324 to group it with the other “#define GPIO_USART3…” macros.

Now the communication works as desired with the RTS pin of the TELEM2 port going HIGH before data is sent via the TX pin and going back to LOW right after.

My question is, whether this is the appropriate way to set up RS485 on my Pixhawk envisioned by whoever implemented those macros. Should the macro really be handwritten into the board.h file or is there some config file and terminal command to set it like for the other macros?