Skip to content

Fix driver ranger finder terra ranger EVO#11311

Merged
sensei-hacker merged 2 commits intoiNavFlight:maintenance-9.xfrom
error414:error414/fix/terra-ranger-evo
Feb 3, 2026
Merged

Fix driver ranger finder terra ranger EVO#11311
sensei-hacker merged 2 commits intoiNavFlight:maintenance-9.xfrom
error414:error414/fix/terra-ranger-evo

Conversation

@error414
Copy link
Contributor

@error414 error414 commented Feb 3, 2026

User description

Fix driver for terra ranger EVo rangerfinder.

See: #11310


PR Type

Bug fix, New Target


Description

  • Fix TeraRanger Evo rangefinder driver with improved I2C communication

    • Refactored static variables into struct for better encapsulation
    • Fixed CRC validation logic and measurement timing
    • Corrected license header from Cleanflight to INAV
  • Add CRSF frame length validation for MSP requests

    • Prevents buffer overflow by checking frame length before processing
  • Add CoreWingF405WingV2 flight controller target

    • Complete target configuration with timer, sensor, and serial definitions
  • Improve PG version check script for struct definitions in separate headers

    • Now correctly detects struct changes across companion .c and .h files

Diagram Walkthrough

flowchart LR
  A["TeraRanger Evo Driver"] -->|Refactor variables| B["Static struct"]
  A -->|Fix CRC logic| C["Improved validation"]
  A -->|Fix timing| D["Correct I2C flow"]
  E["CRSF Handler"] -->|Add frame check| F["Length validation"]
  G["New Target"] -->|CoreWingF405WingV2| H["Timer & Sensor Config"]
  I["PG Check Script"] -->|Search companions| J["Struct detection"]
Loading

File Walkthrough

Relevant files
Bug fix
rangefinder_teraranger_evo.c
Refactor TeraRanger Evo driver with improved I2C handling

src/main/drivers/rangefinder/rangefinder_teraranger_evo.c

  • Updated license header from Cleanflight to INAV/Mozilla Public License
  • Refactored global variables into static struct teraRangerEvo for
    encapsulation
  • Extracted CRC validation into separate checkCrc() function
  • Simplified teraRangerInit() to use busWrite() instead of busWriteBuf()
  • Restructured teraRangerUpdate() with early returns for error
    conditions
  • Fixed measurement timing by triggering next read after each update
  • Added datasheet reference URL in comments
+57/-43 
crsf.c
Add CRSF frame length validation for MSP frames                   

src/main/rx/crsf.c

  • Added frame length validation before processing MSP_REQ and MSP_WRITE
    frames
  • Checks that frameLength >= 4 to prevent buffer overflow
  • Sets crsfFrameDone = false for invalid frame lengths
  • Prevents potential security issue from malformed CRSF packets
+7/-3     
Configuration changes
target.h
Add CoreWingF405WingV2 target hardware definitions             

src/main/target/COREWINGF405WINGV2/target.h

  • New target header file with complete hardware definitions
  • Defines board identifier CW4W2 and product string
  • Configures 6 UART ports, 3 SPI buses, and I2C interface
  • Sets up IMU (ICM42605), barometer, magnetometer, and rangefinder
    sensors
  • Defines ADC channels for voltage, current, RSSI, and airspeed
  • Configures LED strip, OSD, SD card, and other peripherals
+174/-0 
target.c
Add CoreWingF405WingV2 timer and sensor configuration       

src/main/target/COREWINGF405WINGV2/target.c

  • New target implementation file with timer and sensor configuration
  • Registers ICM42605 IMU on SPI1 with CW270 degree alignment
  • Defines 11 PWM output channels using TIM2, TIM3, TIM4, TIM8, and TIM12
  • Configures LED output on TIM1 and softserial on TIM5
  • Sets up timer hardware mappings with DMA configurations
+48/-0   
config.c
Add CoreWingF405WingV2 serial and feature configuration   

src/main/target/COREWINGF405WINGV2/config.c

  • New target configuration file with serial port and feature setup
  • Assigns USART6 for RX serial, USART5 for GPS, USART1 for MSP
  • Configures pinio box with USER1 permanent ID
  • Provides target-specific initialization in targetConfiguration()
    function
+41/-0   
CMakeLists.txt
Add CoreWingF405WingV2 CMake build configuration                 

src/main/target/COREWINGF405WINGV2/CMakeLists.txt

  • New CMake build configuration file for CoreWingF405WingV2 target
  • Specifies STM32F405XG microcontroller variant
+1/-0     
Enhancement
check-pg-versions.sh
Improve PG version check for separate header files             

.github/scripts/check-pg-versions.sh

  • Improved PG_REGISTER detection to check current version instead of
    diff
  • Enhanced struct definition search to check all changed files, not just
    current file
  • Added companion file detection (.c <-> .h) to find struct definitions in
    headers
  • Refined version increment validation with better error messages
  • Improved handling of edge cases where struct and PG_REGISTER are in
    different files
  • Added detailed logging for struct location and version change
    recommendations
+81/-24 

@github-actions
Copy link

github-actions bot commented Feb 3, 2026

Branch Targeting Suggestion

You've targeted the master branch with this PR. Please consider if a version branch might be more appropriate:

  • maintenance-9.x - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

  • maintenance-10.x - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

If master is the correct target for this change, no action is needed.


This is an automated suggestion to help route contributions to the appropriate branch.

@error414 error414 changed the title Error414/fix/terra ranger evo Fix driver ranger finder terra ranger EVO Feb 3, 2026
@error414 error414 changed the base branch from master to maintenance-9.x February 3, 2026 18:35
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Feb 3, 2026

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

@error414
Copy link
Contributor Author

error414 commented Feb 3, 2026

Fixed all qodo suggestions

@sensei-hacker sensei-hacker merged commit da16fec into iNavFlight:maintenance-9.x Feb 3, 2026
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