From 8f2ede870e2602101e7dbd3b04aac065539e99c3 Mon Sep 17 00:00:00 2001 From: Peter van der Perk Date: Sun, 10 Mar 2024 11:28:33 +0100 Subject: [PATCH] tropic: fix system power --- boards/nxp/tropic/init/rc.board_defaults | 1 - boards/nxp/tropic/nuttx-config/Kconfig | 4 ++++ boards/nxp/tropic/nuttx-config/nsh/defconfig | 1 - boards/nxp/tropic/src/board_config.h | 21 +++++++++++++++++--- boards/nxp/tropic/src/usb.c | 4 ++++ 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 boards/nxp/tropic/nuttx-config/Kconfig diff --git a/boards/nxp/tropic/init/rc.board_defaults b/boards/nxp/tropic/init/rc.board_defaults index 6c5122bc8a..c87952922c 100644 --- a/boards/nxp/tropic/init/rc.board_defaults +++ b/boards/nxp/tropic/init/rc.board_defaults @@ -19,7 +19,6 @@ param set-default SENS_EN_INA226 0 param set-default BAT1_V_DIV 10.177939394 param set-default BAT1_A_PER_V 15.391030303 - if [ -f "/fs/microsd/ipcfg-eth0" ] then else diff --git a/boards/nxp/tropic/nuttx-config/Kconfig b/boards/nxp/tropic/nuttx-config/Kconfig new file mode 100644 index 0000000000..f72f3c094c --- /dev/null +++ b/boards/nxp/tropic/nuttx-config/Kconfig @@ -0,0 +1,4 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# diff --git a/boards/nxp/tropic/nuttx-config/nsh/defconfig b/boards/nxp/tropic/nuttx-config/nsh/defconfig index 505698d05b..efc59a2446 100644 --- a/boards/nxp/tropic/nuttx-config/nsh/defconfig +++ b/boards/nxp/tropic/nuttx-config/nsh/defconfig @@ -142,7 +142,6 @@ CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSSERVER_NOADDR=y CONFIG_NETDEV_CAN_BITRATE_IOCTL=y CONFIG_NETDEV_CAN_FILTER_IOCTL=y -CONFIG_NETDEV_IFINDEX=y CONFIG_NETDEV_LATEINIT=y CONFIG_NETDEV_PHY_IOCTL=y CONFIG_NETINIT_DHCPC=y diff --git a/boards/nxp/tropic/src/board_config.h b/boards/nxp/tropic/src/board_config.h index 6a37ef9104..a4f3c2750f 100644 --- a/boards/nxp/tropic/src/board_config.h +++ b/boards/nxp/tropic/src/board_config.h @@ -50,8 +50,10 @@ #include "imxrt_gpio.h" #include "imxrt_iomuxc.h" #include "hardware/imxrt_pinmux.h" +#include "hardware/imxrt_usb_analog.h" #include +#include /**************************************************************************************************** * Definitions @@ -132,7 +134,7 @@ /* HW has to large of R termination on ADC todo:change when HW value is chosen */ -#define BOARD_ADC_OPEN_CIRCUIT_V (5.6f) +//#define BOARD_ADC_OPEN_CIRCUIT_V (5.6f) /* PWM */ @@ -185,6 +187,7 @@ #define RC_SERIAL_SINGLEWIRE 1 // Suport Single wire wiring #define RC_SERIAL_SWAP_RXTX 1 // Set Swap (but not supported in HW) to use Single wire #define RC_SERIAL_SWAP_USING_SINGLEWIRE 1 // Set to use Single wire swap as HW does not support swap +#define BOARD_SUPPORTS_RC_SERIAL_PORT_OUTPUT /* Safety Switch is HW version dependent on having an PX4IO * So we init to a benign state with the _INIT definition @@ -219,8 +222,20 @@ * provides the true logic GPIO BOARD_ADC_xxxx macros. */ -//#define BOARD_ADC_USB_VALID (!px4_arch_gpioread(GPIO_nVDD_USB_VALID)) -//#define BOARD_ADC_USB_CONNECTED (board_read_VBUS_state() == 0) +#define BOARD_NUMBER_BRICKS 1 + +/* Use USB2 VBUS 4.7V comparator for valid check */ +static inline int board_read_usb2_vbus_state(void) +{ + return (getreg32(IMXRT_USB_ANALOG_USB2_VBUS_DETECT_STAT) & USB_ANALOG_USB_VBUS_DETECT_STAT_VBUS_VALID) ? 0 : 1; +} + +#define BOARD_ADC_BRICK_VALID (board_read_usb2_vbus_state() == 0) + + + + +#define BOARD_ADC_USB_CONNECTED (board_read_VBUS_state() == 0) /* FMUv5 never powers odd the Servo rail */ diff --git a/boards/nxp/tropic/src/usb.c b/boards/nxp/tropic/src/usb.c index cae9750e9c..d723fdb656 100644 --- a/boards/nxp/tropic/src/usb.c +++ b/boards/nxp/tropic/src/usb.c @@ -71,6 +71,10 @@ int imxrt_usb_initialize(void) { imxrt_clockall_usboh3(); + + // We abuse VBUS2 to check if system power checks VBUS gets below 4.7V + putreg32(USB_ANALOG_USB_VBUS_DETECT_VBUSVALID_THRESH_4V7 | USB_ANALOG_USB_VBUS_DETECT_VBUSVALID_PWRUP_CMPS, + IMXRT_USB_ANALOG_USB2_VBUS_DETECT); return 0; } /************************************************************************************