Skip to content

Conversation

@functionpointer
Copy link
Contributor

@functionpointer functionpointer commented Nov 23, 2025

User description

Fixes resource conflict discussed in #11120 and #11082 (comment)

The "C" port exposes pins PB10 and PB11, which can be used for UART3 and I2C2. Previously, an initialization order quirk caused UART3 to only be usable for serial rx. For other functions such as GPS the pins would be initialized as I2C2.

This PR adds the #define I2C_DEVICE_2_SHARES_UART3 directive to target.h, which enables deconflicting logic in fc_init.c.

Using the resource command, i have tested:

  • When UART3 is unused in ports tab, PB10 and PB11 are initialized as I2C2
  • When UART3 is set as serial rx, PB10 and PB11 are set to UART3
  • When UART3 is set as GPS, PB10 and PB11 are set to UART3

I have also attached a physical GPS module to UART3 and it works.

With this PR, UART3 can now be used without any limitations


PR Type

Bug fix


Description

  • Add I2C_DEVICE_2_SHARES_UART3 directive to enable resource conflict resolution

  • Remove redundant NEXUSX preprocessor check around UART1 definition

  • Allows UART3 to be fully functional for GPS and other applications


Diagram Walkthrough

flowchart LR
  A["I2C2 and UART3<br/>share PB10/PB11"] -->|"Add I2C_DEVICE_2_SHARES_UART3"| B["Deconflicting logic<br/>in fc_init.c"]
  B -->|"Resolves conflict"| C["UART3 fully functional<br/>for GPS/Serial"]
  D["Redundant NEXUSX<br/>preprocessor check"] -->|"Remove"| E["Cleaner target.h<br/>configuration"]
Loading

File Walkthrough

Relevant files
Bug fix
target.h
Add I2C/UART3 conflict resolution and cleanup                       

src/main/target/NEXUSX/target.h

  • Added I2C_DEVICE_2_SHARES_UART3 define to enable resource conflict
    resolution logic
  • Removed redundant #ifdef NEXUSX and #endif preprocessor directives
    around UART1 definition
  • Maintains I2C2 configuration on pins PB10/PB11 with proper conflict
    handling
+1/-2     

@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No auditing scope: The added preprocessor define I2C_DEVICE_2_SHARES_UART3 and related pin configs do not
involve runtime actions or logging, so audit trail implications cannot be determined from
this hardware configuration change alone.

Referred Code
#define I2C_DEVICE_2_SHARES_UART3
#define DEFAULT_I2C BUS_I2C2

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
No error paths: The changes are compile-time configuration (#defines) without added error handling code;
verifying edge-case handling for UART3/I2C2 conflict resolution requires inspecting
fc_init.c logic not shown in this diff.

Referred Code
#define USE_I2C_DEVICE_2 // clashes with UART3
#define I2C2_SCL                PB10
#define I2C2_SDA                PB11
#define I2C_DEVICE_2_SHARES_UART3
#define DEFAULT_I2C BUS_I2C2

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status:
No user errors: No user-facing error messages are introduced; assessing secure error reporting for the
deconflicting logic would require reviewing runtime code outside this target
configuration.

Referred Code
// *************** UART *****************************
#define USE_VCP

#define USE_UART1 // clashes with I2C1
#define UART1_TX_PIN            PB6 // pin labelled "AUX"
#define UART1_RX_PIN            PB7 // pin labelled "SBUS"

#define USE_UART2
#define UART2_TX_PIN            PA2 // pin labelled as "RPM"
#define UART2_RX_PIN            PA3 // pin labelled as "TLM"

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Config-only change: The PR adds a hardware-sharing define and removes a guard without introducing input
handling; confirming secure handling of shared UART/I2C at runtime needs review of
initialization code not present here.

Referred Code
#define I2C_DEVICE_2_SHARES_UART3
#define DEFAULT_I2C BUS_I2C2

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Use standard macro for resource sharing

Replace the custom macro I2C_DEVICE_2_SHARES_UART3 with the standard
UART3_SHARED_WITH_I2C2. This change ensures that the resource conflict between
I2C2 and UART3 is handled correctly by the existing INAV framework.

src/main/target/NEXUSX/target.h [50-53]

 #define USE_I2C_DEVICE_2 // clashes with UART3
 #define I2C2_SCL                PB10
 #define I2C2_SDA                PB11
-#define I2C_DEVICE_2_SHARES_UART3
+#define UART3_SHARED_WITH_I2C2
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies the use of a non-standard macro for resource sharing and recommends the conventional UART3_SHARED_WITH_I2C2, which is essential for the framework's conflict resolution to work correctly.

Medium
  • More

@sensei-hacker sensei-hacker merged commit 485f789 into iNavFlight:master Nov 23, 2025
21 checks passed
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