Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2c1b895
dronecan/h7: reduce FDCAN SJW from 8 to 3
daijoubu May 23, 2026
79abe9c
dronecan/h7: extend PLL2 block to cover USE_DRONECAN, fix PLL2Q for F…
daijoubu May 28, 2026
6683fee
dronecan/h7: use system PLL2 clock for FDCAN; add KAKUTEH7WING CAN su…
daijoubu May 29, 2026
bebaa6a
dronecan/h7: remove BusOff/ErrorPassive LOG_DEBUG spam from GetProtoc…
daijoubu May 29, 2026
fd9942b
dronecan/h7: fix FDCAN timing clock source and restore SJW=3
daijoubu May 29, 2026
08ec78f
dronecan/h7: remove LOG_DEBUG spam and fix PLL2 VCI range
daijoubu May 29, 2026
6b7549a
dronecan: remove LOG_DEBUG spam from H7/F7 drivers and dronecan.c
daijoubu May 29, 2026
40acc2a
dronecan/h7: set SJW=1 for ISO 11898-1 conformance and verified 1Mbps…
daijoubu May 29, 2026
8b8b334
dronecan: set SJW=1 in F7 driver; clean up stale comments in H7/F7 dr…
daijoubu May 29, 2026
b34ec8a
dronecan: gate GPS fix handlers on GPS_DRONECAN provider
daijoubu May 29, 2026
274a587
dronecan/f7: restore SJW=3 (hardware 4 tq); document register encodin…
daijoubu May 29, 2026
34883a3
dronecan: add STATE_DRONECAN_FAILED; set on CAN peripheral init failure
daijoubu May 29, 2026
2c81808
dronecan: add FAILED to CLI state name array
daijoubu May 29, 2026
140ae20
dronecan/h7: flush TX FIFO before clearing CCCR.INIT on bus-off recovery
daijoubu May 29, 2026
b634b6a
dronecan: disable AutoRetransmission on H7/F7 to prevent TX FIFO stall
daijoubu May 29, 2026
2137616
dronecan/f7: check canardSTM32ComputeTimings return value
daijoubu May 29, 2026
72940b5
dronecan: increase bus-off recovery delay from 1ms to 20ms
daijoubu May 29, 2026
40786a2
dronecan: move GPS provider guard to dispatch layer in dronecan.c
daijoubu May 29, 2026
4aa03ed
dronecan: rate-limit protocol status check to 1Hz in NORMAL state
daijoubu May 29, 2026
beef5b3
dronecan/f7: implement RecoverFromBusOff to clear sticky ESR.BOFF flag
daijoubu May 29, 2026
cb04564
dronecan/h7: fix static_assert comment for PLL2M HSE divisibility check
daijoubu May 29, 2026
c953369
dronecan: rate-limit protocol status check in BUS_OFF state to 20ms c…
daijoubu May 29, 2026
fd56f93
dronecan/f7: revert RecoverFromBusOff HAL_CAN_Stop/Start — causes lockup
daijoubu May 29, 2026
26b9378
dronecan: only log CAN status when BusOff or ErrorPassive is non-zero
daijoubu May 29, 2026
9d244c3
dronecan/f7: remove TX failure log spam
daijoubu May 29, 2026
858b1ad
dronecan/gps: guard GNSSAuxiliary DOP fields against NaN and overflow
daijoubu May 29, 2026
c93570e
dronecan/gps: remove lastVDOP — no vdop field in gpsSol and not EPV-c…
daijoubu May 29, 2026
43aa5e8
dronecan: add STATE_DRONECAN_COUNT sentinel and assert dronecanStateN…
daijoubu May 29, 2026
606c932
dronecan: handle STATE_DRONECAN_COUNT in switch to satisfy -Werror=sw…
daijoubu May 29, 2026
a8937d6
dronecan: fix ARRAYLEN macro name in dronecanStateNames assert
daijoubu May 30, 2026
f17bb69
dronecan: clamp state index before dronecanStateNames lookup in CLI
daijoubu May 30, 2026
21cc608
dronecan/f7: document why RecoverFromBusOff is a no-op
daijoubu May 31, 2026
25734bd
dronecan: fix sign-compare in CLI state name clamp
daijoubu May 31, 2026
ff85f78
dronecan: fix %lu format specifier for uint32_t fields
daijoubu May 31, 2026
354df59
fix: use PRIu32 for uint32_t format specifiers in dronecan LOG_DEBUG
daijoubu May 31, 2026
ebb39c9
fix(dronecan): send elapsed ms since last seen in MSP2_INAV_DRONECAN_…
daijoubu Jun 1, 2026
69d565d
fix(dronecan): send elapsed ms since last seen in MSP2_INAV_DRONECAN_…
daijoubu Jun 1, 2026
1532585
dronecan/h7: TX queue mode, depth 3, ISR pump, NVIC masking
daijoubu Jun 12, 2026
b330a8a
dronecan: F7 ISR-driven TX, NVIC masking, TEC/REC/LEC counters, cliDr…
daijoubu Jun 12, 2026
ddbe187
dronecan: fix H7 ISR pump, ECR TEC field, narrow TX mask window
daijoubu Jun 12, 2026
3184173
dronecan: reorder driver files to public API before private helpers
daijoubu Jun 12, 2026
5079420
dronecan: address code review findings
daijoubu Jun 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
733 changes: 395 additions & 338 deletions src/main/drivers/dronecan/dronecan.c

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/main/drivers/dronecan/dronecan.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ typedef enum {
typedef enum {
STATE_DRONECAN_INIT,
STATE_DRONECAN_NORMAL,
STATE_DRONECAN_BUS_OFF
STATE_DRONECAN_BUS_OFF,
STATE_DRONECAN_FAILED,
STATE_DRONECAN_COUNT
} dronecanState_e;

#define DRONECAN_MAX_NODES 32 // Reasonably expected number of devices on the bus. If this is regularly hit, we could go higher but it consumes more ram.
Expand Down
41 changes: 8 additions & 33 deletions src/main/drivers/dronecan/libcanard/canard_sitl_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,12 @@ static int16_t sitlCANTransmitStub(const CanardCANFrame* const tx_frame) {
}

static void sitlCANGetStatsStub(canardProtocolStatus_t *pProtocolStat) {
pProtocolStat->BusOff = 0;
pProtocolStat->ErrorPassive = 0;
memset(pProtocolStat, 0, sizeof(*pProtocolStat));
}

#ifdef __linux__
// SocketCAN implementations

/**
* @brief Initialize SocketCAN interface
* @param bitrate CAN bitrate in bps (for logging, actual rate set via ip link)
* @retval 0 on success, negative on error
*/
static int16_t sitlCANInitSocketCAN(uint32_t bitrate) {
struct sockaddr_can addr;
struct ifreq ifr;
Expand Down Expand Up @@ -163,9 +157,6 @@ static int16_t sitlCANInitSocketCAN(uint32_t bitrate) {
return 0;
}

/**
* @brief Convert libcanard frame to Linux CAN frame
*/
static void sitlCANFrameToLinux(const CanardCANFrame *const src, struct can_frame *const dst) {
memset(dst, 0, sizeof(struct can_frame));

Expand All @@ -183,9 +174,6 @@ static void sitlCANFrameToLinux(const CanardCANFrame *const src, struct can_fram
}
}

/**
* @brief Convert Linux CAN frame to libcanard frame
*/
static void sitlCANFrameFromLinux(const struct can_frame *const src, CanardCANFrame *const dst) {
memset(dst, 0, sizeof(CanardCANFrame));

Expand All @@ -203,11 +191,6 @@ static void sitlCANFrameFromLinux(const struct can_frame *const src, CanardCANFr
}
}

/**
* @brief Receive a CAN frame via SocketCAN
* @param rx_frame Pointer to frame structure to fill
* @retval 0 if no frame available, 1 if frame received, negative on error
*/
static int16_t sitlCANReceiveSocketCAN(CanardCANFrame *const rx_frame) {
struct can_frame frame;
ssize_t nbytes;
Expand Down Expand Up @@ -235,11 +218,6 @@ static int16_t sitlCANReceiveSocketCAN(CanardCANFrame *const rx_frame) {
return 1;
}

/**
* @brief Transmit a CAN frame via SocketCAN
* @param tx_frame Pointer to frame to transmit
* @retval 1 on success, 0 if busy, negative on error
*/
static int16_t sitlCANTransmitSocketCAN(const CanardCANFrame* const tx_frame) {
struct can_frame frame;
ssize_t nbytes;
Expand All @@ -262,16 +240,9 @@ static int16_t sitlCANTransmitSocketCAN(const CanardCANFrame* const tx_frame) {
return 1; // Success
}

/**
* @brief Get CAN protocol status from SocketCAN
* @param pProtocolStat Pointer to status structure to fill
*/
/* Always returns zeroes — SocketCAN provides no per-frame error counters via raw sockets. */
static void sitlCANGetStatsSocketCAN(canardProtocolStatus_t *pProtocolStat) {
// SocketCAN doesn't expose bus-off/error-passive directly
// We could check interface flags via netlink, but for SITL testing
// we assume the virtual CAN is always healthy
pProtocolStat->BusOff = 0;
pProtocolStat->ErrorPassive = 0;
memset(pProtocolStat, 0, sizeof(*pProtocolStat));
}
#endif // __linux__

Expand All @@ -280,7 +251,7 @@ static void sitlCANGetStatsSocketCAN(canardProtocolStatus_t *pProtocolStat) {
* @param rx_frame Pointer to frame structure to fill
* @retval 0 if no frame available, 1 if frame received, negative on error
*/
int16_t canardSTM32Recieve(CanardCANFrame *const rx_frame) {
int16_t canardSTM32Receive(CanardCANFrame *const rx_frame) {
if (rx_frame == NULL) {
return -CANARD_ERROR_INVALID_ARGUMENT;
}
Expand Down Expand Up @@ -357,6 +328,10 @@ int32_t canardSTM32GetRxFifoFillLevel(void) {
return 0;
}

int32_t canardSTM32GetTxQueueFillLevel(void) {
return 0;
}

/**
* @brief Recover from bus-off condition
*/
Expand Down
6 changes: 5 additions & 1 deletion src/main/drivers/dronecan/libcanard/canard_stm32_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
typedef struct {
uint32_t BusOff;
uint32_t ErrorPassive;
uint8_t tec;
uint8_t rec;
uint8_t lec;
} canardProtocolStatus_t;

#ifdef USE_DRONECAN

int16_t canardSTM32CAN1_Init(uint32_t bitrate);

int16_t canardSTM32Recieve(CanardCANFrame *const rx_frame);
int16_t canardSTM32Receive(CanardCANFrame *const rx_frame);
int16_t canardSTM32Transmit(const CanardCANFrame* const tx_frame);
void canardSTM32GetProtocolStatus(canardProtocolStatus_t *pProtocolStat);
int32_t canardSTM32GetTxQueueFillLevel(void);
int32_t canardSTM32GetRxFifoFillLevel(void);
void canardSTM32RecoverFromBusOff(void);
void canardSTM32GetUniqueID(uint8_t id[16]);
Expand Down
Loading
Loading