[BACKPORT] arch/arm/src/imxrt: Unify FlexCAN TX work and add SIOCGCANERRORS. - #401
Merged
dakejahl merged 4 commits intoSep 1, 2026
Merged
Conversation
dakejahl
marked this pull request as ready for review
August 30, 2026 01:42
dakejahl
force-pushed
the
dakejahl/imxrt-flexcan-tx-and-errors
branch
from
August 30, 2026 03:18
10e032f to
93ad415
Compare
dakejahl
added a commit
to PX4/PX4-Autopilot
that referenced
this pull request
Aug 30, 2026
PX4/NuttX#401 now carries the apache-review rework that merges the per-command CAN ioctl options into NETDEV_CAN_IOCTL. The old BITRATE and FILTER lines stay so the bitrate ioctl keeps working on the current NuttX gitlink, where the merged option does not exist yet and is silently dropped. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
dakejahl
added a commit
to PX4/PX4-Autopilot
that referenced
this pull request
Aug 30, 2026
PX4/NuttX#401 merges the per-command CAN ioctl options into a single NETDEV_CAN_IOCTL, so the old BITRATE/FILTER/ERROR names no longer exist there and would be silently dropped, disabling the whole CAN ioctl block. Requires the NuttX gitlink to include PX4/NuttX#401; until that bump the option is dropped against the old tree and the bitrate/error ioctls are inert at runtime (the code builds either way). mr-canhubk3 is included so its bitrate ioctl survives the bump. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
dakejahl
force-pushed
the
dakejahl/imxrt-flexcan-tx-and-errors
branch
from
August 31, 2026 00:39
23576ef to
70bd9ae
Compare
Previously, SIOCSCANBITRATE brought the iterface up to ensure changes where immediately applied. This was confusing, see https://lists.apache.org/thread/g8d0m6yp7noywhroby5br4hxt3r4og2c Now SIOCSCANBITRATE fails is interface is up. All existing SocketCAN drivers updated. Signed-off-by: Carlos Sanchez <carlossanchez@geotab.com> (cherry picked from commit dd53c34) Backport note: imx9 is not in this tree. On i.MX RT the old behaviour is a bus fault, not just confusing: imxrt_ifup() from the ioctl runs imxrt_init_eccram() on a running controller, and the FlexCAN RAM it zeroes is only writable in freeze mode. Measured on an ARK FMU-v6XRT with UAVCAN_BITRATE 500000 (PX4/PX4-Autopilot#28457): imxrt_busfault in wq:uavcan on every boot.
The SIOCxCANxxFILTER cases in fdcan_netdev_ioctl() call stm32_addextfilter(), stm32_delextfilter(), stm32_addstdfilter() and stm32_delstdfilter(), none of which exist anywhere in the tree. The block only ever compiled because no stm32h7 config enables NETDEV_CAN_FILTER_IOCTL; enabling it breaks the link. The commands now fall through to the existing -ENOTSUP default, which is also what a caller observed before. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> (cherry picked from commit fbe3468)
… NETDEV_CAN_IOCTL NETDEV_CAN_BITRATE_IOCTL, NETDEV_CAN_FILTER_IOCTL and NETDEV_CAN_STATE_IOCTL guarded identical option blocks, and every SIOCxCANxxx case in netdev_ifr_ioctl() forwarded a member of the same ifr_ifru union to d_ioctl(). One option and one case block now cover all of the CAN commands; drivers and defconfigs are updated to the new name. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> (cherry picked from commit 60ef78f) Backport note: this tree has no NETDEV_CAN_STATE_IOCTL, and the case block keeps the netdev_ifr_dev() lookup pattern of this branch.
…ERRORS. TX-complete and the deadline watchdog each queued their own callback on the same work_s, and work_queue() cancels whatever is pending when a work_s is reused, so whichever ran second was dropped: deadlines were left set, the TX interrupt mask stayed off, or expired frames were never aborted. Both now queue imxrt_tx_work(), which retires completions before it aborts expired mailboxes. Add SIOCGCANERRORS so a socket can read fault confinement, TEC/REC, a monotonic bus error count and the RX mailbox overrun count. SIOCGCANSTATE reports sleep/operational, not fault confinement, hence a new command. The error count is sampled from the clear-on-read ESR1 error flags at every driver entry rather than from ERRINT, which fires per error frame and storms at bus rate once the bus is dead. Frames the CAN socket layer drops for want of an IOB now count as rx_dropped in the netdev statistics as well as in the global CAN statistics. Tested on an i.MX RT1176 (ARK FMU-v6XRT) running PX4 with two DroneCAN nodes: unplugging one node the ioctl reports error-passive, TEC 128, REC 0 and a monotonic error count, matching ECR/ESR1 read over SWD at 20 Hz, while the other interface stays error-active with zero errors. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> (cherry picked from commit eb40eed)
dakejahl
force-pushed
the
dakejahl/imxrt-flexcan-tx-and-errors
branch
from
September 1, 2026 19:19
70bd9ae to
e173d2f
Compare
This was referenced Sep 1, 2026
dakejahl
added a commit
to PX4/PX4-Autopilot
that referenced
this pull request
Sep 1, 2026
PX4/NuttX#401 merges the per-command CAN ioctl options into a single NETDEV_CAN_IOCTL, so the old BITRATE/FILTER/ERROR names no longer exist there and would be silently dropped, disabling the whole CAN ioctl block. Requires the NuttX gitlink to include PX4/NuttX#401; until that bump the option is dropped against the old tree and the bitrate/error ioctls are inert at runtime (the code builds either way). mr-canhubk3 is included so its bitrate ioctl survives the bump. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
dakejahl
added a commit
to PX4/PX4-Autopilot
that referenced
this pull request
Sep 1, 2026
Picks up PX4/NuttX#401 so SIOCGCANERRORS, SIOCSCANBITRATE-requires-ifdown and NETDEV_CAN_IOCTL are in the tree the SocketCAN changes need. Also includes PX4/NuttX#399 (STM32F412VG/CG chip selections), which landed between main's gitlink and #401. Assisted-by: Grok:grok-4.6 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
dakejahl
added a commit
to PX4/PX4-Autopilot
that referenced
this pull request
Sep 1, 2026
…ketCAN (#28457) * fix(uavcan): report FlexCAN bus state and error counters on SocketCAN The SocketCAN platform driver returned 0 from getErrorCount(), getRxQueueOverflowCount() and isInBusOffState(), so a controller sitting error-passive or bus-off was invisible from `uavcan status` and the can_interface_status topic on every i.MX RT board. Read them through NuttX's SIOCGCANERRORS instead, and print fault confinement, TEC/REC and RX overruns per interface. Builds without the ioctl keep the old zeros. * fix(uavcan): apply UAVCAN_BITRATE on SocketCAN CanDriver::init() ignored its bitrate argument, so the controller stayed at the Kconfig rate and a bus configured for anything but 1 Mbit/s never came up. Program the nominal rate through SIOCSCANBITRATE when it differs from what the driver reports, keeping the data-phase settings untouched. The driver applies the timing at the next ifup, so the interface is taken down around the request. Older PX4/NuttX restarted a running controller from inside the ioctl instead, which on FlexCAN with ECC RAM initialisation is a bus fault; against that NuttX the rate is left as configured with a warning. * fix(boards): switch SocketCAN defconfigs to NETDEV_CAN_IOCTL PX4/NuttX#401 merges the per-command CAN ioctl options into a single NETDEV_CAN_IOCTL, so the old BITRATE/FILTER/ERROR names no longer exist there and would be silently dropped, disabling the whole CAN ioctl block. Requires the NuttX gitlink to include PX4/NuttX#401; until that bump the option is dropped against the old tree and the bitrate/error ioctls are inert at runtime (the code builds either way). mr-canhubk3 is included so its bitrate ioctl survives the bump. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> * chore(nuttx): bump NuttX to the px4_firmware_nuttx-10.3.0+ tip Picks up PX4/NuttX#401 so SIOCGCANERRORS, SIOCSCANBITRATE-requires-ifdown and NETDEV_CAN_IOCTL are in the tree the SocketCAN changes need. Also includes PX4/NuttX#399 (STM32F412VG/CG chip selections), which landed between main's gitlink and #401. Assisted-by: Grok:grok-4.6 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> --------- Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
dakejahl
added a commit
to PX4/PX4-Autopilot
that referenced
this pull request
Sep 2, 2026
Picks up PX4/NuttX#406, which sets SRAM1_END to 0x20040000 for the F412. The gitlink is the 10.3 tip, so this also carries PX4/NuttX#401. Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of apache/nuttx#20008, now merged upstream as fbe3468, 60ef78f and eb40eed, cherry-picked here in that order. The first commit is apache/nuttx dd53c34, which upstream already had and #20008 therefore does not carry:
SIOCSCANBITRATErequires the interface down. PX4 side is PX4/PX4-Autopilot#28457, whose board defconfigs enableNETDEV_CAN_IOCTL(the old names are silently dropped, taking the whole CAN ioctl block with them).The nxstyle commit of #20008 (3e2f28e) is not backported: this tree's SocketCAN drivers have diverged, so it is whitespace churn against files that no longer match upstream.
The same set is backported to
px4_firmware_nuttx-12.12.0+in #404.Bench (ARK FMU-v6XRT, two nodes, 2026-08-29): unplugging one node, the ioctl reports
error-passive, TEC 128, REC 0 for the gap and a monotonic error count, matchingECR/ESR1read over SWD at 20 Hz sample for sample, while the other interface stays error-active with 0 errors.UAVCAN_BITRATE 500000through ifdown → set → ifup brings both nodes up at 500 kbit/s. The T0–T7 CAN regression suite passes with the pre-existing IOB-drop failure of T2 unchanged from main.ark_fmu-v6xrt_defaultrebuilt withCONFIG_NETDEV_CAN_IOCTL=y, error path confirmed linked.Problem
imxrt_txdone_workandimxrt_txtimeout_worksharedpriv->irqwork.work_queue()cancels a pending callback when itswork_sis reused, so whichever was queued second silently replaced the first: deadlines left set,IMASK1TX bits left off, or expired frames never aborted.The socket layer had no way to see the controller's error state. libuavcan's
getErrorCount()/isInBusOffState()are stubs on every SocketCAN board, and the last error-passive failure on this driver was only diagnosed by readingECR/ESR1over SWD.SIOCSCANBITRATEcalledimxrt_ifup()on a running controller. WithCONFIG_IMXRT_FLEXCAN_ECCthat zeroes the FlexCAN RAM outside freeze mode, which is a bus fault:imxrt_busfaultinwq:uavcanon every boot onceUAVCAN_BITRATEdiffers from the Kconfig rate.Solution
Both paths queue
imxrt_tx_work(), which retires completions before aborting expired mailboxes.SIOCGCANERRORS(_SIOC(0x0045), behindNETDEV_CAN_IOCTL) fillscan_ioctl_errors_s. Bus errors are counted by sampling the clear-on-readESR1error flags at every driver entry (TX work, RX work, the ioctl) instead of enablingERRINT, which fires per error frame and storms at bus rate on a dead bus.rx_overrunscountsCODE=OVERRUNmailboxes. CAN frames the socket layer drops for want of an IOB now count asrx_droppedunderNETDEV_STATISTICS.SIOCSCANBITRATEstores the timings and the netdev layer returns-EBUSYwhile the interface is up, as upstream does since dd53c34; the caller takes the interface down, sets the rate and brings it up.NETDEV_CAN_BITRATE_IOCTLandNETDEV_CAN_FILTER_IOCTLguarded identical option blocks, and every SIOCxCANxxx case forwarded a member of the sameifr_ifruunion tod_ioctl(); one option and one case block now cover all of them (this tree has noNETDEV_CAN_STATE_IOCTL).Upstream
SIOCGCANSTATE(0x0041) is sleep/operational, not fault confinement, hence a new command. Submitted upstream as apache/nuttx#20008 (without the bitrate-down commit, which upstream already has).