Hey everyone,
I’m running into a really strange issue with CAN reception on a Pixhawk 6X CM4 (STM32H7, using CAN1/2). I implemented a simple SocketCAN implementation and disabled UAVCAN. When testing RX, only some CAN IDs are received, but others are just missing entirely — and it’s always mostly the same pattern but not 100% consistent. I’m using a PCAN-USB adapter and sending messages via MacCAN Monitor on macOS. I’m not sending at a crazy rate either, just 100 Hz or even slower in some tests.
I tried stepping through the full range of IDs (0 to 0x7FF) in a script and the pattern of messages that got received is quite strange. Also, its not always the same, sometimes other IDs than the ones below are present. My first thought was some kind of filter but I tried the setting the socket filter and that wasn’t it.
I am very confused as why its pretty much always a pattern like this where 0-3 are received but 4 never is. But there is definitely some inconsistency either between runs of this test or between Pixhawk power cycles as I have definitely seen other IDs present.
INFO [my_can] RECEIVED CAN FRAME - ID: 0, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 3, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 18, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 44, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 45, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 46, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 47, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 172, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 173, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 174, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 175, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 840, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 841, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 842, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 844, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 845, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 872, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 873, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 874, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 876, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 877, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 878, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1420, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1421, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1422, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1423, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1424, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1425, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1426, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1427, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1428, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1429, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1430, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1431, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1432, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1433, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1434, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1435, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1436, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1437, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1439, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1440, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1441, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1442, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1443, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1444, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1445, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1446, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1447, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1448, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1449, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1450, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1451, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1452, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1453, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1454, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1455, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1456, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1457, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1458, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1459, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1460, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1461, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1462, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1463, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1464, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1465, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1466, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1467, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1468, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1469, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1470, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1471, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1472, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1473, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1476, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1477, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1478, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1479, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1480, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1481, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1482, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1483, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1486, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1487, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1488, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1489, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1492, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1493, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1494, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1495, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1496, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1497, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1498, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1499, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1500, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1501, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1502, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1503, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1504, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1505, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1508, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1509, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1510, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1511, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1512, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1513, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1514, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1515, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1518, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1519, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1520, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1521, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1524, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1525, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1526, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1528, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1529, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1530, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1531, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1532, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1533, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1534, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1535, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1536, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1537, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1538, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1540, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1541, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1542, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1544, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1545, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1546, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1548, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1549, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1550, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1552, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1553, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1554, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1556, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1557, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1558, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1560, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1561, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1562, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1564, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1565, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1566, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1568, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1569, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1570, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1572, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1573, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1574, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1576, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1577, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1578, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1580, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1581, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1582, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1584, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1585, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1586, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1588, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1589, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1590, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1592, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1593, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1594, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1596, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1597, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1598, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1600, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1601, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1604, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1605, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1606, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1608, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1609, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1610, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1612, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1613, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1614, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1616, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1617, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1620, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1621, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1622, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1624, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1625, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1626, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1628, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1629, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1630, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1632, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1633, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1636, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1637, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1638, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1640, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1641, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1642, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1644, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1645, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1646, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1648, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1649, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1652, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1653, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1654, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1656, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1657, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1658, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1660, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1661, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1662, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1664, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1665, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1666, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1668, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1669, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1670, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1672, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1673, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1674, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1676, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1677, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1678, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1680, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1681, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1682, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1684, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1685, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1686, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1688, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1689, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1690, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1692, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1693, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1694, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1696, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1697, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1698, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1700, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1701, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1702, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1704, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1705, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1706, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1708, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1709, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1710, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1712, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1713, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1714, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1716, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1717, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1718, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1720, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1721, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1722, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1724, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1725, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1726, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1728, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1729, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1732, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1733, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1734, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1736, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1737, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1738, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1742, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1744, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1745, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1748, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1749, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1750, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1752, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1753, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1754, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1756, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1757, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1758, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1760, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1761, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1764, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1765, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1766, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1768, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1769, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1770, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1774, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1776, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1777, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1780, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1781, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1782, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1784, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1785, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1786, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1788, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1789, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1790, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1792, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1793, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1794, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1796, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1797, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1798, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1800, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1801, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1802, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1804, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1805, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1806, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1808, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1809, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1810, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1812, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1813, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1814, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1816, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1817, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1818, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1820, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1821, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1822, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1824, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1825, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1826, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1828, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1829, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1830, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1832, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1833, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1834, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1836, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1837, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1838, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1840, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1841, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1842, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1844, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1845, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1846, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1848, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1849, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1850, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1852, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1853, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1854, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1856, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1857, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1860, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1861, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1862, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1864, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1865, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1866, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1868, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1869, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1870, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1872, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1873, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1876, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1877, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1878, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1880, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1881, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1882, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1884, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1885, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1886, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1888, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1889, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1892, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1893, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1894, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1896, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1897, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1898, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1900, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1901, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1902, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1904, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1905, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1908, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1909, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1910, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1912, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1913, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1914, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1916, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1917, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1918, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1920, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1921, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1922, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1924, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1925, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1926, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1928, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1929, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1930, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1932, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1933, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1934, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1936, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1937, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1938, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1940, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1941, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1942, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1944, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1945, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1946, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1948, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1949, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1950, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1952, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1953, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1954, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1956, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1957, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1958, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1960, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1961, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1962, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1964, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1965, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1966, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1968, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1969, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1970, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1972, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1973, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1974, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1976, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1977, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1978, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1980, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1981, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1982, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1984, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1985, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1988, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1989, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1990, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1992, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1993, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1994, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 1998, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2006, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2010, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2016, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2017, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2020, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2021, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2022, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2024, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2025, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2026, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2030, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2032, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2038, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2042, LEN: 8
INFO [my_can] RECEIVED CAN FRAME - ID: 2046, LEN: 8
Background
I am working on a project that requires writing and receiving custom CAN messages on both CAN1 and CAN2 of a Holybro Pixhawk 6x CM4 flight controller. The CAN messages I need to send/receive are fixed and I have no say over the decoding and encoding protocol. I basically need to have a simple read/write SocketCAN implementation that is outside the PX4 UAVCAN stack so my custom app can call read and write and handle the data.
Getting this to work has been kind of weird because Nuttx does not have a driver for CAN standard and you have to use the FDCAN driver configured for standard messages.
There are some existing forum posts about this:
My Setup
I have implemented a very basic SocketCAN wrapper and have done my best to disable PX4 builtin UAVCAN, and set up the CAN busses manually.
In my default.px4board I have:
CONFIG_DRIVERS_UAVCAN=n
CONFIG_BOARD_UAVCAN_TIMER_OVERRIDE=2
And in my boards/my_project/my_board/nuttx-config/nsh/defconfig I have added:
CONFIG_NETDEV_CAN_BITRATE_IOCTL=y
CONFIG_NETDEV_LATEINIT=y
CONFIG_NETDEV_IFINDEX=y
CONFIG_NET_CAN=y
CONFIG_NET_CAN_RAW=y
CONFIG_NET_CAN_RAW_TX_DEADLINE=y
CONFIG_NET_CAN_SOCK_OPTS=y
CONFIG_NET_CAN_NOTIFIER=y
CONFIG_NET_TIMESTAMP=y
CONFIG_STM32H7_FDCAN1=y
CONFIG_STM32H7_FDCAN2=y
CONFIG_NET_CAN_CANFD=n
CONFIG_FDCAN1_DATA_BITRATE=500000
CONFIG_FDCAN2_DATA_BITRATE=500000
CONFIG_FDCAN1_BITRATE=500000
CONFIG_FDCAN2_BITRATE=500000
CONFIG_FDCAN1_ARBI_BITRATE=500000
CONFIG_FDCAN2_ARBI_BITRATE=500000
CONFIG_CANUTILS_CANDUMP=y
CONFIG_CANUTILS_CANSEND=y
And here is my pretty boiler-plate SocketCAN implementation (I think):
#include "my_can.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
char *can_ids[] = {"can0", "can1"};
struct {
int s;
struct ifreq ifr;
} CAN_db[2];
MY_ErrorStatus MY_CAN_Init(CAN_ID_t can_id)
{
/// CAN init
if ((CAN_db[can_id].s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
#ifdef DEBUG
perror("Socket");
#endif
return MY_ERROR;
}
// Allow all IDs
struct can_filter filter[1];
filter[0].can_id = 0;
filter[0].can_mask = 0;
setsockopt(CAN_db[can_id].s, SOL_CAN_RAW, CAN_RAW_FILTER, &filter, sizeof(filter));
strcpy(CAN_db[can_id].ifr.ifr_name, can_ids[can_id]);
ioctl(CAN_db[can_id].s, SIOCGIFINDEX, &CAN_db[can_id].ifr);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_family = AF_CAN;
addr.can_ifindex = CAN_db[can_id].ifr.ifr_ifindex;
if (bind(CAN_db[can_id].s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
#ifdef DEBUG
perror("Bind");
#endif
return MY_ERROR;
}
int socket_state;
socket_state = fcntl(CAN_db[can_id].s, F_GETFL, 0);
fcntl(CAN_db[can_id].s, F_SETFL, socket_state | O_NONBLOCK);
return MY_SUCCESS;
}
MY_ErrorStatus MY_CAN_Write(CAN_ID_t can_id, struct can_frame *frame)
{
if (write(CAN_db[can_id].s, frame, sizeof(struct can_frame)) != sizeof(struct can_frame)) {
#ifdef DEBUG
perror("Write");
#endif
return MY_ERROR;
}
return MY_SUCCESS;
}
MY_ErrorStatus MY_CAN_Read(CAN_ID_t can_id, struct can_frame *frame)
{
int nbytes;
nbytes = read(CAN_db[can_id].s, frame, sizeof(struct can_frame));
if (nbytes < 0) {
return MY_ERROR;
}
printf("RECEIVED CAN FRAME - ID: %lu, LEN: %u, NBYTES: %i\r\n", frame->can_id, frame->can_dlc, nbytes);
return MY_SUCCESS;
}
What I have tried
- Wiring:
I’m connecting PCAN directly to the Pixhawk 6X via CAN1. No external terminator. PCAN may have built-in termination — not 100% sure.
- Bitrate:
500kbit, matching on both sides.
- Sending messages slowly:
Tried sending one frame at a time manually. Same issue — some IDs show, some don’t.
- Adding setsockopt() filters:
I’m setting CAN_RAW_FILTER with a wildcard to receive everything:
// Allow all IDs
struct can_filter filter[1];
filter[0].can_id = 0;
filter[0].can_mask = 0;
setsockopt(CAN_db[can_id].s, SOL_CAN_RAW, CAN_RAW_FILTER, &filter, sizeof(filter));
- Trying ioctl hardware filters:
I attempted using SIOCSCANFILTER, but discovered NuttX doesn’t actually implement CONFIG_NETDEV_CAN_FILTER_IOCTL. So that doesn’t help.
Ideas
I really thought it was gonna be a filter issue but so far that hasn’t worked.
It seems unlikely that it would be a wiring issue since things are mostly consistent and CAN transmit is working well. Although it is possible something is weird with the RX side only.
I have added no external 120 ohm resistors to the wiring between the PCAN and the Pixhawk.
I am currently out of ideas, if anyone has any ideas for potential causes or new things to try I would greatly appreciate it.
Thank you!