From 1c5db5ff65b74b290b1e1c6a2c243f7d079eba16 Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Wed, 5 Aug 2026 21:45:29 -0600 Subject: [PATCH] refactor(platforms/nuttx): remove dead PX4_I2C_BUS_MTD board define (#28167) * refactor(platforms/nuttx): remove dead PX4_I2C_BUS_MTD board define The macro's value has been unused since the MTD manifest refactor (68ab736b1 "Refactor mtd to make available to board startup"), which made the board manifest the source of truth for the EEPROM bus and address: at24xxx_attach() derives the bus from PX4_I2C_DEVID_BUS(instance.devid). All that survived was a presence check that silently degraded a former compile-time #error into a runtime failure. Because the value stopped mattering, it drifted freely. Eleven boards carry "4,5", which is not even a usable bus number, and several boards disagree with their own manifest (fmu-v5x declares 4,5 against actual buses 3 and 4; fmu-v6xrt declares 1 against 3 and 6; 7-nano declares 1 against 4). crazyflie21 defines it with no MTD manifest at all. Guard at24xxx_attach() on CONFIG_I2C instead, which is the condition the code actually depends on and matches how the neighbouring ramtron_attach() guards on CONFIG_MTD_RAMTRON. Assisted-by: Claude:claude-opus-5[1m] Signed-off-by: Jacob Dahl * fix(platforms/nuttx): guard at24xxx_attach on CONFIG_MTD CONFIG_I2C is too broad: nearly every board enables I2C, including those without MTD. Compiling the real at24xxx_attach body kept the mtd_partition / register_mtddriver / ftl_initialize path live, so boards without CONFIG_MTD failed to link. CONFIG_MTD is the NuttX flag that actually enables that infrastructure (and is set on every board with an I2C EEPROM manifest). CONFIG_MTD_AT24XX is not suitable: only crazyflie sets it; FMU boards use px4_24xxxx_mtd.c and deliberately omit the NuttX AT24 driver. Signed-off-by: Jacob Dahl --------- Signed-off-by: Jacob Dahl --- boards/accton-godwit/ga1/src/board_config.h | 3 --- boards/ark/fmu-v6s/src/board_config.h | 3 --- boards/ark/fmu-v6x/src/board_config.h | 3 --- boards/auterion/fmu-v6s/src/board_config.h | 2 -- boards/auterion/fmu-v6x/src/board_config.h | 3 --- boards/bitcraze/crazyflie/src/board_config.h | 2 -- boards/bitcraze/crazyflie21/src/board_config.h | 2 -- boards/cuav/7-nano/src/board_config.h | 3 --- boards/cuav/fmu-v6x/src/board_config.h | 3 --- boards/cuav/x25-evo/src/board_config.h | 3 --- boards/cuav/x25-mega/src/board_config.h | 3 --- boards/cuav/x25-super/src/board_config.h | 3 --- boards/nxp/mr-canhubk3/src/board_config.h | 2 -- boards/px4/fmu-v5x/src/board_config.h | 3 --- boards/px4/fmu-v6c/src/board_config.h | 2 -- boards/px4/fmu-v6x/src/board_config.h | 3 --- boards/px4/fmu-v6xrt/src/board_config.h | 1 - boards/sky-drones/smartap-airlink/src/board_config.h | 3 --- boards/svehicle/e2/src/board_config.h | 3 --- boards/zeroone/x6/src/board_config.h | 3 --- platforms/nuttx/src/px4/common/px4_mtd.cpp | 4 ++-- 21 files changed, 2 insertions(+), 55 deletions(-) diff --git a/boards/accton-godwit/ga1/src/board_config.h b/boards/accton-godwit/ga1/src/board_config.h index d82e96a3b71..4492b1d9bc1 100644 --- a/boards/accton-godwit/ga1/src/board_config.h +++ b/boards/accton-godwit/ga1/src/board_config.h @@ -469,9 +469,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 5 __BEGIN_DECLS diff --git a/boards/ark/fmu-v6s/src/board_config.h b/boards/ark/fmu-v6s/src/board_config.h index b4e1a4487b3..97aef81ecf4 100644 --- a/boards/ark/fmu-v6s/src/board_config.h +++ b/boards/ark/fmu-v6s/src/board_config.h @@ -451,9 +451,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 4 #define BOARD_SPIX_SYNC_FREQ 32000 diff --git a/boards/ark/fmu-v6x/src/board_config.h b/boards/ark/fmu-v6x/src/board_config.h index 037fd11296a..965feb57f67 100644 --- a/boards/ark/fmu-v6x/src/board_config.h +++ b/boards/ark/fmu-v6x/src/board_config.h @@ -478,9 +478,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 4 #define BOARD_SPIX_SYNC_FREQ 32000 diff --git a/boards/auterion/fmu-v6s/src/board_config.h b/boards/auterion/fmu-v6s/src/board_config.h index 5ba1338cd56..c57d61c225b 100644 --- a/boards/auterion/fmu-v6s/src/board_config.h +++ b/boards/auterion/fmu-v6s/src/board_config.h @@ -84,8 +84,6 @@ * Note that these are unshifted addresses. */ #define BOARD_MTD_NUM_EEPROM 1 /* MTD: imu_eeprom */ -#define PX4_I2C_BUS_MTD 4 - /* CAN */ #define UAVCAN_NUM_IFACES_RUNTIME 1 diff --git a/boards/auterion/fmu-v6x/src/board_config.h b/boards/auterion/fmu-v6x/src/board_config.h index 7f9825b14c8..3390d4cbad8 100644 --- a/boards/auterion/fmu-v6x/src/board_config.h +++ b/boards/auterion/fmu-v6x/src/board_config.h @@ -470,9 +470,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 4 /* No CDCACM driver for this board, so this is manually defined for version.c diff --git a/boards/bitcraze/crazyflie/src/board_config.h b/boards/bitcraze/crazyflie/src/board_config.h index b69a021a15e..d29781bba4d 100644 --- a/boards/bitcraze/crazyflie/src/board_config.h +++ b/boards/bitcraze/crazyflie/src/board_config.h @@ -91,8 +91,6 @@ #define PX4_I2C_BUS_ONBOARD_HZ 400000 #define PX4_I2C_BUS_EXPANSION_HZ 400000 -#define PX4_I2C_BUS_MTD 1 - #define BOARD_NUMBER_I2C_BUSES 3 #define BOARD_I2C_BUS_CLOCK_INIT {PX4_I2C_BUS_ONBOARD_HZ, 100000, PX4_I2C_BUS_EXPANSION_HZ} diff --git a/boards/bitcraze/crazyflie21/src/board_config.h b/boards/bitcraze/crazyflie21/src/board_config.h index b636bfd08cb..b39574b5d9b 100644 --- a/boards/bitcraze/crazyflie21/src/board_config.h +++ b/boards/bitcraze/crazyflie21/src/board_config.h @@ -92,8 +92,6 @@ #define PX4_I2C_BUS_ONBOARD_HZ 400000 #define PX4_I2C_BUS_EXPANSION_HZ 400000 -#define PX4_I2C_BUS_MTD 1 - #define BOARD_NUMBER_I2C_BUSES 3 #define BOARD_I2C_BUS_CLOCK_INIT {PX4_I2C_BUS_ONBOARD_HZ, 400000, PX4_I2C_BUS_EXPANSION_HZ} diff --git a/boards/cuav/7-nano/src/board_config.h b/boards/cuav/7-nano/src/board_config.h index a2c564ae89c..17944ef7f3f 100644 --- a/boards/cuav/7-nano/src/board_config.h +++ b/boards/cuav/7-nano/src/board_config.h @@ -357,9 +357,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 1 - - #define BOARD_NUM_IO_TIMERS 6 __BEGIN_DECLS diff --git a/boards/cuav/fmu-v6x/src/board_config.h b/boards/cuav/fmu-v6x/src/board_config.h index 8f99505fdab..d0c8e290f36 100644 --- a/boards/cuav/fmu-v6x/src/board_config.h +++ b/boards/cuav/fmu-v6x/src/board_config.h @@ -480,9 +480,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 5 __BEGIN_DECLS diff --git a/boards/cuav/x25-evo/src/board_config.h b/boards/cuav/x25-evo/src/board_config.h index e4cd35d19d8..952abd9870b 100644 --- a/boards/cuav/x25-evo/src/board_config.h +++ b/boards/cuav/x25-evo/src/board_config.h @@ -447,9 +447,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 5 #define BOARD_SPI_BUS_MAX_BUS_ITEMS 5 diff --git a/boards/cuav/x25-mega/src/board_config.h b/boards/cuav/x25-mega/src/board_config.h index 3fc87b1bc2b..77d967c3419 100644 --- a/boards/cuav/x25-mega/src/board_config.h +++ b/boards/cuav/x25-mega/src/board_config.h @@ -450,9 +450,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4 - - #define BOARD_NUM_IO_TIMERS 5 #define BOARD_SPI_BUS_MAX_BUS_ITEMS 5 diff --git a/boards/cuav/x25-super/src/board_config.h b/boards/cuav/x25-super/src/board_config.h index 47fc455dd93..38086812ccf 100644 --- a/boards/cuav/x25-super/src/board_config.h +++ b/boards/cuav/x25-super/src/board_config.h @@ -453,9 +453,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4 - - #define BOARD_NUM_IO_TIMERS 5 #define BOARD_SPI_BUS_MAX_BUS_ITEMS 5 diff --git a/boards/nxp/mr-canhubk3/src/board_config.h b/boards/nxp/mr-canhubk3/src/board_config.h index 3d9dab2a018..592272a9d64 100644 --- a/boards/nxp/mr-canhubk3/src/board_config.h +++ b/boards/nxp/mr-canhubk3/src/board_config.h @@ -81,8 +81,6 @@ __BEGIN_DECLS #define PX4_I2C_BUS_ONBOARD_HZ 400000 #define PX4_I2C_BUS_EXPANSION_HZ 400000 -#define PX4_I2C_BUS_MTD 1 - #define BOARD_NUMBER_I2C_BUSES 2 /* Timer I/O PWM and capture */ diff --git a/boards/px4/fmu-v5x/src/board_config.h b/boards/px4/fmu-v5x/src/board_config.h index 0e35b8f92af..20aa6efd158 100644 --- a/boards/px4/fmu-v5x/src/board_config.h +++ b/boards/px4/fmu-v5x/src/board_config.h @@ -436,9 +436,6 @@ #define BOARD_NUM_IO_TIMERS 5 - -#define PX4_I2C_BUS_MTD 4,5 - __BEGIN_DECLS /**************************************************************************************************** diff --git a/boards/px4/fmu-v6c/src/board_config.h b/boards/px4/fmu-v6c/src/board_config.h index d7663cddfb9..10713fabe3c 100644 --- a/boards/px4/fmu-v6c/src/board_config.h +++ b/boards/px4/fmu-v6c/src/board_config.h @@ -273,8 +273,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - #define BOARD_OVERRIDE_I2C_DEVICE_EXTERNAL diff --git a/boards/px4/fmu-v6x/src/board_config.h b/boards/px4/fmu-v6x/src/board_config.h index 39545d295cd..8459c437d95 100644 --- a/boards/px4/fmu-v6x/src/board_config.h +++ b/boards/px4/fmu-v6x/src/board_config.h @@ -471,9 +471,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 5 __BEGIN_DECLS diff --git a/boards/px4/fmu-v6xrt/src/board_config.h b/boards/px4/fmu-v6xrt/src/board_config.h index 790034d188e..bb1859a7161 100644 --- a/boards/px4/fmu-v6xrt/src/board_config.h +++ b/boards/px4/fmu-v6xrt/src/board_config.h @@ -609,7 +609,6 @@ } #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 1 __BEGIN_DECLS diff --git a/boards/sky-drones/smartap-airlink/src/board_config.h b/boards/sky-drones/smartap-airlink/src/board_config.h index 48c7695cb9d..e4be45bad09 100644 --- a/boards/sky-drones/smartap-airlink/src/board_config.h +++ b/boards/sky-drones/smartap-airlink/src/board_config.h @@ -356,9 +356,6 @@ #define BOARD_NUM_IO_TIMERS 5 - -#define PX4_I2C_BUS_MTD 4,5 - __BEGIN_DECLS /**************************************************************************************************** diff --git a/boards/svehicle/e2/src/board_config.h b/boards/svehicle/e2/src/board_config.h index 778224ae4cb..fa5b3af8b5f 100644 --- a/boards/svehicle/e2/src/board_config.h +++ b/boards/svehicle/e2/src/board_config.h @@ -434,9 +434,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 5 __BEGIN_DECLS diff --git a/boards/zeroone/x6/src/board_config.h b/boards/zeroone/x6/src/board_config.h index f26740e790b..999b9e0f22a 100644 --- a/boards/zeroone/x6/src/board_config.h +++ b/boards/zeroone/x6/src/board_config.h @@ -470,9 +470,6 @@ #define BOARD_ENABLE_CONSOLE_BUFFER -#define PX4_I2C_BUS_MTD 4,5 - - #define BOARD_NUM_IO_TIMERS 5 __BEGIN_DECLS diff --git a/platforms/nuttx/src/px4/common/px4_mtd.cpp b/platforms/nuttx/src/px4/common/px4_mtd.cpp index 380bf493b0a..68be74d0abf 100644 --- a/platforms/nuttx/src/px4/common/px4_mtd.cpp +++ b/platforms/nuttx/src/px4/common/px4_mtd.cpp @@ -167,8 +167,8 @@ static int spi_nor_attach(mtd_instance_s &instance, uint32_t spi_speed_hz) static int at24xxx_attach(mtd_instance_s &instance) { -#if !defined(PX4_I2C_BUS_MTD) - PX4_ERR("Misconfiguration PX4_I2C_BUS_MTD not set"); +#if !defined(CONFIG_MTD) + PX4_ERR("Misconfiguration CONFIG_MTD not set"); return -ENXIO; #else