Skip to content

arch/arm/src/stm32h7: treat classic data_bitrate 0 as arbitration - #397

Draft
AlexKlimaj wants to merge 3 commits into
PX4:px4_firmware_nuttx-10.3.0+from
AlexKlimaj:px4_firmware_nuttx-10.3.0+
Draft

arch/arm/src/stm32h7: treat classic data_bitrate 0 as arbitration#397
AlexKlimaj wants to merge 3 commits into
PX4:px4_firmware_nuttx-10.3.0+from
AlexKlimaj:px4_firmware_nuttx-10.3.0+

Conversation

@AlexKlimaj

Copy link
Copy Markdown
Member

Problem

Classic CAN SIOCSCANBITRATE callers (PX4 UAVCAN/SLCAN) pass data_bitrate = 0. fdcan_bittiming() rejects that after fdcan_initialize() has already cleared FDCAN IE, so RX interrupts never run. On an ARK FPV + DroneCAN ESC this filled RX FIFO 0 (RF0L set) while UAVCAN showed RX frames: 0 and dynamic node allocation never completed.

Fix

  • Map a zero data-phase rate onto the arbitration rate so BRSE stays off and IE.RF0NE is programmed.
  • Reject a zero target bitrate before dividing.
  • Do not ifup after fdcan_initialize() fails.

Verified on ARK FPV: after this plus the matching PX4 SocketCAN caller change, CAN1 RX runs, DNA allocates node 123, and esc.Status is received.

Classic CAN SIOCSCANBITRATE callers pass data_bitrate 0.
fdcan_bittiming() then fails after FDCAN IE has been cleared, so RX
interrupts never run and DNA/esc frames sit in the FIFO unread.

Map a zero data-phase rate onto the arbitration rate (BRSE stays off),
reject a zero target bitrate before dividing, and do not ifup after
initialize fails.

Assisted-by: Grok:grok-4.6
Signed-off-by: alexklimaj <alex@arkelectron.com>
@AlexKlimaj
AlexKlimaj requested review from dakejahl and a balanced review from Copilot August 26, 2026 23:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Handles classic CAN bitrate ioctls correctly in the STM32H7 FDCAN socket driver.

Changes:

  • Rejects zero target bitrates safely.
  • Maps a zero data bitrate to the arbitration bitrate.
  • Propagates initialization failures from fdcan_ifup().

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

*/
if (priv->data_timing.bitrate == 0)
{
priv->data_timing.bitrate = priv->arbi_timing.bitrate;
@dakejahl
dakejahl marked this pull request as draft August 26, 2026 23:38
Without transceiver delay compensation the H7 samples its own delayed
bit on the data phase and goes bus-off. Same TDCO formula as the PX4
stm32h7 UAVCAN driver. Required to talk CAN FD at 2/4 Mbps to the
ARK G431 ESC.

Assisted-by: Grok:grok-4.6
Signed-off-by: alexklimaj <alex@arkelectron.com>
Hold the net lock across can_datahandler(), drop the FDCAN critical
section before can_input(), and clear recycled connection readahead
pointers. STM32H7 FDCAN was hardfaulting (IMPRECISERR) in
can_datahandler / can_readahead_signal when UAVCAN RX ran on HPWORK.

Assisted-by: Grok:grok-4.6
Signed-off-by: alexklimaj <alex@arkelectron.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants