UART/USART initialization part

Hi !

I’m looking for the initialization part for UART/USART in PX4 source code.

I uploaded the PX4 F/W on STM32F446 instead of STM32F427 and it need to change the pin configuration.

However, I just found UART/USART configuration code in px4fmu-4/nsh/defconfig.

How can I change the UART/USART initialization and where is the source code?

  • The pin definitions can be found in Firmware/nuttx-configs/px4fmu-v4/include/board.h. This is where you define which pins should be used for each of the UARTs.

  • The port initialisation is done in Firmware/NuttX/nuttx/arch/arm/src/chip/stm32_serial.c, with a lot of the defines being configured in Firmware/NuttX/nuttx/arch/arm/src/chip/stm32_uart.h The function that initially configures the port is called static int up_setup(struct uart_dev_s *dev).

If you only need to change the pin definition, do it in Firmware/nuttx-configs/px4fmu-v4/include/board.h.

I found “void stm32_lowsetup(void)” function in Nuttx/nuttx/arch/arm/src/stm32/stm32_lowputc.c.

There is configuration part related to UART/USART.

Do you know what’s different from “up_setup”?

There is a comment in up_setup that says

  /* Note: The logic here depends on the fact that that the USART module
   * was enabled in stm32_lowsetup().

In the initial booting of the board (nuttx/arch/arm/src/stm32/stm32_start.c), stm32_lowsetup() is called. I think the stm32_serial.c relies on the fact that the function has been called during boot.