Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Dec 3, 2025

User description

Summary

Fixes "Invalid name" CLI error when users attempt to configure magnetometer settings on NEXUSX target.

Problem

The NEXUSX target was missing USE_MAG definition, causing all magnetometer-related CLI settings to be excluded from the settings table. Users received "Invalid name" errors when trying to use:

  • set align_mag_roll=<value>
  • set align_mag_pitch=<value>
  • set align_mag_yaw=<value>
  • Other compass settings (mag_hardware, mag_declination, etc.)

Root Cause

The PG_COMPASS_CONFIG parameter group in settings.yaml has condition: USE_MAG (line 558), which excludes all magnetometer settings when USE_MAG is not defined for the target.

Solution

Added magnetometer support to NEXUSX target:

  • Added #define USE_MAG to target.h
  • Configured MAG_I2C_BUS to use I2C3 (same bus as barometer)

Hardware Compatibility

NEXUSX board has I2C3 available for external magnetometer:

  • I2C3 SCL: PA8
  • I2C3 SDA: PC9
  • Barometer already on I2C3 (SPL06)
  • Compatible with standard I2C magnetometers (HMC5883L, QMC5883, IST8310, LIS3MDL, etc.)

Testing

✅ Built NEXUSX target successfully
✅ Verified settings present in binary via strings command
✅ All compass settings now available:

  • align_mag_roll, align_mag_pitch, align_mag_yaw (-1800 to 3600 decidegrees)
  • mag_hardware (AUTO, HMC5883, QMC5883, IST8310, etc.)
  • mag_declination (-18000 to 18000)
  • magzero_x/y/z, maggain_x/y/z
  • mag_calibration_time (20-120 seconds)

Impact

  • Risk: Low - Only enables missing functionality, no behavior changes
  • Flash: Minimal increase (<1KB)
  • Default: No change (mag hardware defaults to AUTO, disabled if not detected)
  • Backward compatibility: Existing configurations unaffected

Files Changed

  • src/main/target/NEXUSX/target.h - Added USE_MAG and MAG_I2C_BUS definitions

PR Type

Bug fix


Description

  • Enables missing magnetometer support on NEXUSX target

  • Adds USE_MAG definition and configures MAG_I2C_BUS to I2C3

  • Resolves "Invalid name" CLI errors for compass settings

  • Allows external magnetometer configuration via I2C3 bus


Diagram Walkthrough

flowchart LR
  A["NEXUSX Target"] -->|Missing USE_MAG| B["CLI Errors"]
  B -->|Invalid name| C["Compass Settings Unavailable"]
  A -->|Add USE_MAG| D["Magnetometer Enabled"]
  D -->|Configure MAG_I2C_BUS| E["I2C3 Bus"]
  E -->|Shared with| F["Barometer SPL06"]
  D -->|Enable| G["Compass Settings Available"]
Loading

File Walkthrough

Relevant files
Bug fix
target.h
Enable magnetometer on I2C3 bus                                                   

src/main/target/NEXUSX/target.h

  • Added #define USE_MAG to enable magnetometer support
  • Added #define MAG_I2C_BUS BUS_I2C3 to configure magnetometer I2C bus
  • Magnetometer shares I2C3 bus with existing barometer (SPL06)
  • Enables all compass-related CLI settings (align_mag_roll/pitch/yaw,
    mag_hardware, mag_declination, etc.)
+3/-0     

The NEXUSX target was missing USE_MAG definition, which caused all
magnetometer-related CLI settings to be unavailable. Users received
"Invalid name" errors when attempting to configure align_mag_roll,
align_mag_pitch, align_mag_yaw, and other compass settings.

Changes:
- Added USE_MAG to NEXUSX target.h
- Configured MAG_I2C_BUS to use I2C3 (same bus as barometer)
- Enables external magnetometer support for GPS navigation

Hardware compatibility:
- NEXUSX has I2C3 available (SCL: PA8, SDA: PC9)
- Barometer already on I2C3 (SPL06)

Testing:
- Built NEXUSX target successfully
- Verified settings present in binary via strings command
- All compass settings now available in settings table:
  * align_mag_roll, align_mag_pitch, align_mag_yaw
  * mag_hardware, mag_declination
  * magzero_x/y/z, maggain_x/y/z
  * mag_calibration_time
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

@sensei-hacker
Copy link
Member Author

Something to be aware of @functionpointer

Comment on lines +60 to +61
#define USE_MAG
#define MAG_I2C_BUS BUS_I2C3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a definition for the specific magnetometer hardware driver (e.g., USE_MAG_QMC5883L) to ensure the device is properly initialized, as simply defining USE_MAG is insufficient. [possible issue, importance: 9]

Suggested change
#define USE_MAG
#define MAG_I2C_BUS BUS_I2C3
#define USE_MAG
#define MAG_I2C_BUS BUS_I2C3
#define USE_MAG_QMC5883L // Or other magnetometer type used on this board

Comment on lines 57 to +61
#define BARO_I2C_BUS BUS_I2C3
#define USE_BARO_SPL06

#define USE_MAG
#define MAG_I2C_BUS BUS_I2C3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add an explicit note or guard to document/validate the shared I2C3 usage between barometer and magnetometer to prevent accidental divergence and bus conflicts across modules and docs. [Learned best practice, importance: 6]

New proposed code:
 #define USE_BARO
-#define BARO_I2C_BUS            BUS_I2C3
+#define BARO_I2C_BUS            BUS_I2C3     // Shares I2C3 with magnetometer
 #define USE_BARO_SPL06
 
 #define USE_MAG
-#define MAG_I2C_BUS             BUS_I2C3
+#define MAG_I2C_BUS             BUS_I2C3     // Shares I2C3 with barometer (SPL06)

@functionpointer
Copy link
Contributor

Why not I2C2 instead, using DEFAULT_I2C?
That one is more easily accessible on Port C

@functionpointer
Copy link
Contributor

Now that I am properly awake, I can tell you that I2C3 is not physically accessible at all. See the Readme.md.

The only possible interface besides I2C2 is I2C1, which may be mapped on AUX and SBUS pins. However, they are already used by UART1 and two Servo/Motor outputs and the target is currently not set up to use I2C1 at all.

So use I2C2 like this

#define USE_MAG
#define MAG_I2C_BUS             DEFAULT_I2C
#define USE_MAG_ALL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants