Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
1fda091
Initial framework to init CAN driver.
daijoubu Jan 23, 2026
219d0e4
Add dsdlc generated files. Added dronecan tasks to scheduler and set…
daijoubu Jan 25, 2026
53b77f1
Fix DFU cli and more CAN debugging
daijoubu Jan 26, 2026
36de6dd
Enabled the FDCAN clock to get access to registers and configured the…
daijoubu Jan 27, 2026
21b9861
Created pin definitions for CAN in Matek H743 target.
daijoubu Jan 27, 2026
1f41663
Found the correct timers and bit timing values to transmit dronecan a…
daijoubu Jan 28, 2026
fbef5b4
Remove unused code and clean up debugging messages.
daijoubu Jan 29, 2026
3cac417
Corrected filters and adjusted bit timing to receive a single message.
daijoubu Jan 29, 2026
cefc884
Setup the IO structures to read Pin numbers from target.h
daijoubu Jan 30, 2026
cd6b62c
Further progress with the IO system to handle pin assigment.
daijoubu Jan 30, 2026
0f91431
Cleaned up hardware initialization
daijoubu Jan 30, 2026
c757bfc
Calculate bit timing from clockspeed and baudrate for portability. A…
daijoubu Jan 31, 2026
fa6384a
Cleaned up problems in LOG_DEBUG messages that were skipping/obscurin…
daijoubu Jan 31, 2026
5b867ec
Process entire FIFO if messages are waiting but limit to number of me…
daijoubu Jan 31, 2026
33cd1b9
Moved hardware initialization down to canard_stm32_driver
daijoubu Feb 1, 2026
aa5cfd2
Added bitrate and node ID into the configuration of the flight contro…
daijoubu Feb 1, 2026
b568e1e
Forgot to update the docs.
daijoubu Feb 1, 2026
9c2408c
Add an example driver for gps_dronecan modeled on gps_msp.
daijoubu Feb 3, 2026
65bd6f8
Add an interrupt priority for dronecan (lowest)
daijoubu Feb 3, 2026
2cf9617
Removed interrupt code and set up a state machine to poll and handle …
daijoubu Feb 5, 2026
85bdad4
support gdb on stlink with MATEKH743
daijoubu Feb 5, 2026
3479d25
Created CANbus log topic
daijoubu Feb 6, 2026
392c0c6
Clean up error handling.
daijoubu Feb 6, 2026
a2607af
Correct include search scopes in autogenerated files.
daijoubu Feb 6, 2026
29fadbf
fixing search scope for include files. Make and Ninja have different…
daijoubu Feb 6, 2026
16d2fc1
Moving STM32H7 specific code to it's own module to prepare for bxCan …
daijoubu Feb 6, 2026
3ccefe2
Remove unneeded settings header.
daijoubu Feb 7, 2026
0ad4fc1
Removed incorrect USE_DRONECAN define that was enabling it for all ta…
daijoubu Feb 7, 2026
976c6f9
Only try to initialize hardware pins if defined.
daijoubu Feb 7, 2026
04abcab
Move define to pin initialization and use pin definitions for check.
daijoubu Feb 7, 2026
35d2916
Clean up warning causing build failure on Github.
daijoubu Feb 7, 2026
947ea8f
Moved all references to FDCAN down to the STM32H7 driver.
daijoubu Feb 7, 2026
25e78fa
Working on the f7 port but need to update the HAL library
daijoubu Feb 7, 2026
569f953
Reworked to use HAL_CAN v1.2.2
daijoubu Feb 7, 2026
2b10d06
Setup canard for 64 bit platforms on SITL builds
daijoubu Feb 8, 2026
0b4cadb
Moved define to fix targets that don't use dronecan.
daijoubu Feb 8, 2026
823f3be
Move the unique id call into the chip specific drivers as the older H…
daijoubu Feb 8, 2026
7ebc087
Fixed missing call to get protocol status in F7 driver for canard
daijoubu Feb 8, 2026
2e1e1f8
Helps to compile the HAL CAN library.
daijoubu Feb 8, 2026
eff9c7a
Flag unused parameter in HAL as unused.
daijoubu Feb 8, 2026
ef4f3e1
Add the CAN standby pin to the target description as per AP hwdef for…
daijoubu Feb 9, 2026
fbe8078
Move the storage for the receive message to the same scope as the han…
daijoubu Feb 9, 2026
6e55583
Adding a dronecan battery sensor
daijoubu Feb 9, 2026
5d9d6dc
Move the F7 driver to use interrupt based receives to fill a ring buf…
daijoubu Feb 10, 2026
c3ad505
Added CAN battery voltage meter and tested with Matek CAN-L4-BM
daijoubu Feb 11, 2026
e4d54d9
Add DroneCAN/libcanard unit tests (44 tests)
daijoubu Feb 11, 2026
f54bb4d
Add DroneCAN current sensor support to battery system
daijoubu Feb 11, 2026
7fb2567
Add DroneCAN documentation
daijoubu Feb 11, 2026
1e69ba0
Add some clarifications to the docs and run update_cli_docs.py becaus…
daijoubu Feb 11, 2026
204ed72
Fix DroneCAN battery current scaling (10x too low)
daijoubu Feb 12, 2026
62963a1
Fix multiple DroneCAN driver bugs found in code review
daijoubu Feb 12, 2026
9690892
Fix bug introduced by Claude. STM32F7xx HAL is too old to support HA…
daijoubu Feb 12, 2026
8d5042f
Improve DroneCAN error handling and logging
daijoubu Feb 12, 2026
a06e1ab
Addressed issues 2, 3 and 4 from Qodo.
daijoubu Feb 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Empty file added .gitmodules
Empty file.
8 changes: 4 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
"version": "2.0.0",
"tasks": [
{
"label": "Build AOCODARCH7DUAL",
"label": "Build MATEKH743",
"type": "shell",
"command": "make AOCODARCH7DUAL",
"command": "ninja MATEKH743",
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}/build"
}
},
{
"label": "Build AOCODARCH7DUAL",
"label": "Build MATEKH743",
"type": "shell",
"command": "make AOCODARCH7DUAL",
"command": "ninja MATEKH743",
"group": {
"kind": "build",
"isDefault": true
Expand Down
132 changes: 132 additions & 0 deletions cmake/dsdlc_generated.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

set(DSDLC_GENERATED_DIR "${MAIN_LIB_DIR}/main/dsdlc_generated")

set(DSDLC_GENERATED_SRC
dronecan.protocol.CanStats.c
dronecan.protocol.FlexDebug.c
dronecan.protocol.GlobalTime.c
dronecan.protocol.Stats.c
dronecan.remoteid.ArmStatus.c
dronecan.remoteid.BasicID.c
dronecan.remoteid.Location.c
dronecan.remoteid.OperatorID.c
dronecan.remoteid.SecureCommand_req.c
dronecan.remoteid.SecureCommand_res.c
dronecan.remoteid.SelfID.c
dronecan.remoteid.System.c
dronecan.sensors.hygrometer.Hygrometer.c
dronecan.sensors.magnetometer.MagneticFieldStrengthHiRes.c
dronecan.sensors.rc.RCInput.c
dronecan.sensors.rpm.RPM.c
uavcan.CoarseOrientation.c
uavcan.equipment.actuator.ArrayCommand.c
uavcan.equipment.actuator.Command.c
uavcan.equipment.actuator.Status.c
uavcan.equipment.ahrs.MagneticFieldStrength2.c
uavcan.equipment.ahrs.MagneticFieldStrength.c
uavcan.equipment.ahrs.RawIMU.c
uavcan.equipment.ahrs.Solution.c
uavcan.equipment.air_data.AngleOfAttack.c
uavcan.equipment.air_data.IndicatedAirspeed.c
uavcan.equipment.air_data.RawAirData.c
uavcan.equipment.air_data.Sideslip.c
uavcan.equipment.air_data.StaticPressure.c
uavcan.equipment.air_data.StaticTemperature.c
uavcan.equipment.air_data.TrueAirspeed.c
uavcan.equipment.camera_gimbal.AngularCommand.c
uavcan.equipment.camera_gimbal.GEOPOICommand.c
uavcan.equipment.camera_gimbal.Mode.c
uavcan.equipment.camera_gimbal.Status.c
uavcan.equipment.device.Temperature.c
uavcan.equipment.esc.RawCommand.c
uavcan.equipment.esc.RPMCommand.c
uavcan.equipment.esc.Status.c
uavcan.equipment.esc.StatusExtended.c
uavcan.equipment.gnss.Auxiliary.c
uavcan.equipment.gnss.ECEFPositionVelocity.c
uavcan.equipment.gnss.Fix2.c
uavcan.equipment.gnss.Fix.c
uavcan.equipment.gnss.RTCMStream.c
uavcan.equipment.hardpoint.Command.c
uavcan.equipment.hardpoint.Status.c
uavcan.equipment.ice.FuelTankStatus.c
uavcan.equipment.ice.reciprocating.CylinderStatus.c
uavcan.equipment.ice.reciprocating.Status.c
uavcan.equipment.indication.BeepCommand.c
uavcan.equipment.indication.LightsCommand.c
uavcan.equipment.indication.RGB565.c
uavcan.equipment.indication.SingleLightCommand.c
uavcan.equipment.power.BatteryInfo.c
uavcan.equipment.power.CircuitStatus.c
uavcan.equipment.power.PrimaryPowerSupplyStatus.c
uavcan.equipment.range_sensor.Measurement.c
uavcan.equipment.safety.ArmingStatus.c
uavcan.navigation.GlobalNavigationSolution.c
uavcan.protocol.AccessCommandShell_req.c
uavcan.protocol.AccessCommandShell_res.c
uavcan.protocol.CANIfaceStats.c
uavcan.protocol.DataTypeKind.c
uavcan.protocol.debug.KeyValue.c
uavcan.protocol.debug.LogLevel.c
uavcan.protocol.debug.LogMessage.c
uavcan.protocol.dynamic_node_id.Allocation.c
uavcan.protocol.dynamic_node_id.server.AppendEntries_req.c
uavcan.protocol.dynamic_node_id.server.AppendEntries_res.c
uavcan.protocol.dynamic_node_id.server.Discovery.c
uavcan.protocol.dynamic_node_id.server.Entry.c
uavcan.protocol.dynamic_node_id.server.RequestVote_req.c
uavcan.protocol.dynamic_node_id.server.RequestVote_res.c
uavcan.protocol.enumeration.Begin_req.c
uavcan.protocol.enumeration.Begin_res.c
uavcan.protocol.enumeration.Indication.c
uavcan.protocol.file.BeginFirmwareUpdate_req.c
uavcan.protocol.file.BeginFirmwareUpdate_res.c
uavcan.protocol.file.Delete_req.c
uavcan.protocol.file.Delete_res.c
uavcan.protocol.file.EntryType.c
uavcan.protocol.file.Error.c
uavcan.protocol.file.GetDirectoryEntryInfo_req.c
uavcan.protocol.file.GetDirectoryEntryInfo_res.c
uavcan.protocol.file.GetInfo_req.c
uavcan.protocol.file.GetInfo_res.c
uavcan.protocol.file.Path.c
uavcan.protocol.file.Read_req.c
uavcan.protocol.file.Read_res.c
uavcan.protocol.file.Write_req.c
uavcan.protocol.file.Write_res.c
uavcan.protocol.GetDataTypeInfo_req.c
uavcan.protocol.GetDataTypeInfo_res.c
uavcan.protocol.GetNodeInfo_req.c
uavcan.protocol.GetNodeInfo_res.c
uavcan.protocol.GetTransportStats_req.c
uavcan.protocol.GetTransportStats_res.c
uavcan.protocol.GlobalTimeSync.c
uavcan.protocol.HardwareVersion.c
uavcan.protocol.NodeStatus.c
uavcan.protocol.Panic.c
uavcan.protocol.param.Empty.c
uavcan.protocol.param.ExecuteOpcode_req.c
uavcan.protocol.param.ExecuteOpcode_res.c
uavcan.protocol.param.GetSet_req.c
uavcan.protocol.param.GetSet_res.c
uavcan.protocol.param.NumericValue.c
uavcan.protocol.param.Value.c
uavcan.protocol.RestartNode_req.c
uavcan.protocol.RestartNode_res.c
uavcan.protocol.SoftwareVersion.c
uavcan.Timestamp.c
uavcan.tunnel.Broadcast.c
uavcan.tunnel.Call_req.c
uavcan.tunnel.Call_res.c
uavcan.tunnel.Protocol.c
uavcan.tunnel.SerialConfig.c
uavcan.tunnel.Targetted.c
)

list(TRANSFORM DSDLC_GENERATED_SRC PREPEND "${DSDLC_GENERATED_DIR}/Src/")

set(DSDLC_GENERATED_DIRS
${DSDLC_GENERATED_DIR}/Include
)


2 changes: 2 additions & 0 deletions cmake/main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ set(MAIN_INCLUDE_DIRS
"${MAIN_LIB_DIR}"
"${MAIN_SRC_DIR}"
"${MAIN_LIB_DIR}/main/MAVLink"
"${MAIN_SRC_DIR}/drivers/dronecan/libcanard"
"${MAIN_SRC_DIR}/drivers/dronecan/dsdlc_generated/include"
)

set(MAIN_DEFINITIONS
Expand Down
3 changes: 3 additions & 0 deletions cmake/stm32f7.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(STM32F7_HAL_SRC
stm32f7xx_hal.c
stm32f7xx_hal_adc.c
stm32f7xx_hal_adc_ex.c
stm32f7xx_hal_can.c
stm32f7xx_hal_cortex.c
stm32f7xx_hal_dac.c
stm32f7xx_hal_dac_ex.c
Expand Down Expand Up @@ -77,6 +78,8 @@ main_sources(STM32F7_SRC
drivers/serial_uart_stm32f7xx.c
drivers/serial_uart_hal.c
drivers/sdcard/sdmmc_sdio_hal.c
drivers/dronecan/libcanard/canard_stm32f7xx_driver.c

)

main_sources(STM32F7_MSC_SRC
Expand Down
4 changes: 3 additions & 1 deletion cmake/stm32h7.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(STM32H7_HAL_SRC
# stm32h7xx_hal_eth.c
# stm32h7xx_hal_eth_ex.c
stm32h7xx_hal_exti.c
# stm32h7xx_hal_fdcan.c
stm32h7xx_hal_fdcan.c
stm32h7xx_hal_flash.c
stm32h7xx_hal_flash_ex.c
stm32h7xx_hal_gfxmmu.c
Expand Down Expand Up @@ -162,6 +162,8 @@ main_sources(STM32H7_SRC
drivers/serial_uart_hal.c
drivers/sdio.h
drivers/sdcard/sdmmc_sdio_hal.c
drivers/dronecan/libcanard/canard_stm32h7xx_driver.c

)

main_sources(STM32H7_MSC_SRC
Expand Down
12 changes: 9 additions & 3 deletions docs/Battery.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ Configure the current meter type using the `current_meter_type` settings here:

| Value | Sensor Type |
| ----- | ---------------------- |
| 0 | None |
| 1 | ADC/hardware sensor |
| 2 | Virtual sensor |
| NONE | Disabled |
| ADC | ADC/hardware sensor |
| VIRTUAL | Virtual sensor (estimated from throttle) |
| FAKE | Fake sensor (for testing) |
| ESC | ESC telemetry |
| SMARTPORT | SmartPort telemetry |
| CAN | DroneCAN battery monitor |

See [DroneCAN](DroneCAN.md) for information on using DroneCAN battery monitors.

Configure capacity using the `battery_capacity` setting, in mAh units.

Expand Down
145 changes: 145 additions & 0 deletions docs/DroneCAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# DroneCAN

DroneCAN (formerly UAVCAN v0) is a lightweight protocol designed for reliable communication in aerospace and robotic applications over CAN bus. INAV supports DroneCAN for connecting external sensors and peripherals.

## Supported Features

| Feature | Status | Description |
|---------|--------|-------------|
| GPS | Supported | GNSS receivers via DroneCAN |
| Battery Voltage | Supported | Voltage sensing from DroneCAN battery monitors |
| Battery Current | Supported | Current sensing from DroneCAN battery monitors |
| Parameter Get/Set | Planned | Remote parameter configuration |
| ESC Control | Planned | Motor control via DroneCAN ESCs |
| Dynamic Node Assignment | Planned | Manage node IDs dynamically to minimize first time configuration |

## Supported Hardware

DroneCAN requires a flight controller with CAN bus hardware:

- **STM32H7** boards with FDCAN peripheral
- **STM32F7** boards with bxCAN peripheral

Check your board's documentation to confirm CAN bus availability.

## Configuration

### Enabling DroneCAN

DroneCAN settings are configured via CLI:

```
set dronecan_node_id = 10
set dronecan_bitrate = 1000KBPS
save
```

### Settings

| Setting | Values | Default | Description |
|---------|--------|---------|-------------|
| `dronecan_node_id` | 1-127 | 10 | CAN node ID for the flight controller |
| `dronecan_bitrate` | 125KBPS, 250KBPS, 500KBPS, 1000KBPS | 1000KBPS | CAN bus bitrate |

All peripherals need to have the node ID and the bitrate set manually through the dronecan_gui for now. You can use your flight controller as a CAN interface by loading an Ardupilot image on it. Once the set up is complete, you can reflash it to Inav.

### GPS via DroneCAN

To use a DroneCAN GPS receiver:

```
set gps_provider = DRONECAN
save
```

The flight controller will automatically receive GPS data from any DroneCAN GNSS device on the bus. GPS configuration needs to be set using dronecan_gui to enable additional satellite networks.

### Battery Monitoring via DroneCAN

DroneCAN battery monitors send both voltage and current data using the `BatteryInfo` message type.

**Voltage sensing:**
```
set bat_voltage_src = CAN
save
```

**Current sensing:**
```
feature CURRENT_METER
set current_meter_type = CAN
save
```

Both voltage and current come from the same DroneCAN BatteryInfo message, so they update together when using a DroneCAN battery monitor.

## Hardware Setup

### Wiring

Connect the CAN bus lines between your flight controller and DroneCAN peripherals:

| Signal | Description |
|--------|-------------|
| 4v5 | Power supply for peripheral (see dronecan specification for limitations) |
| CAN_H | CAN High (dominant high) |
| CAN_L | CAN Low (dominant low) |
| GND | Ground reference |

**Important:** CAN bus requires 120 ohm termination resistors at each end of the bus. Many DroneCAN devices include built-in termination that can be enabled via jumper or configuration.

### Typical Setup

```
[FC CAN Port] ----CAN_H/CAN_L---- [DroneCAN GPS] ----CAN_H/CAN_L---- [DroneCAN Battery Monitor]
| | |
120R (pass-through) 120R
```

## Troubleshooting

### No data from DroneCAN devices

1. **Check wiring** - Ensure CAN_H and CAN_L are not swapped
2. **Check termination** - Bus requires 120 ohm termination at both ends
3. **Check bitrate** - All devices must use the same bitrate
4. **Check node IDs** - Each device must have a unique node ID

### GPS not detected

1. Verify `gps_provider = DRONECAN` is set
2. Check that the GPS is broadcasting Fix2 or Fix messages
3. Some GPS modules need external power - check power supply

### Battery readings incorrect

1. Verify the DroneCAN battery monitor is configured correctly
2. Check that `bat_voltage_src = CAN` and/or `current_meter_type = CAN` are set
3. Some battery monitors need calibration - consult device documentation

## DroneCAN Message Types

INAV processes the following DroneCAN message types:

| Message Type | Data Type ID | Description |
|--------------|--------------|-------------|
| Fix2 | 1063 | GNSS fix data (preferred) |
| Fix | 1060 | GNSS fix data (legacy) |
| Auxiliary | 1061 | GNSS auxiliary data (HDOP, VDOP) |
| BatteryInfo | 1092 | Battery voltage, current, temperature, SoC |
| NodeStatus | 341 | Node health and status |

## Compatibility

DroneCAN devices compatible with INAV include:

- **GPS:** (not tested) ARK GPS, Holybro DroneCAN GPS, mRo Location One
- **Battery Monitors:** Matek CAN-L4-BM, Various DroneCAN-compatible power modules

For the latest compatibility information, check the INAV Discord or GitHub discussions.

## Resources

- [DroneCAN Specification](https://dronecan.github.io/)
- [libcanard Library](https://github.com/dronecan/libcanard)
- [INAV Discord](https://discord.gg/peg2hhbYwN)
Loading