Example Path: examples/PlatformSpecific/MODRT1171/CAN/CanFdLoopback
Overview
CAN FD (Flexible Data-rate) extends classic CAN in two ways: payloads grow from 8 bytes to up to 64 bytes per frame, and with bit-rate switching (BRS) the data phase of each frame runs at a higher bit rate than the arbitration phase. All three of the i.MX RT1171's FlexCAN controllers support CAN FD.
This example demonstrates CAN FD on a single bare MODRT1171 using the FlexCAN loopback self-test mode (the transmitter connected directly to the receiver inside the chip) – no transceiver, no wiring, no second node:
- Functional test – one 64-byte frame with BRS (500 kbit/s arbitration, 2 Mbit/s data phase) is sent through the internal loopback and the received payload is verified against what was sent.
- Throughput comparison – the same 4096-byte payload is moved once as 512 classic 8-byte frames and once as 64 FD 64-byte BRS frames, timed with the NetBurner StopWatch class, and the effective data rates are printed side by side.
The FlexCAN driver (fsl_flexcan, NXP SDK version 2.11.6) is built into the NetBurner MODRT1171 platform library; the example includes <fsl_flexcan.h> directly and bundles no driver source.
Hardware requirements
- MODRT1171 module
- Personal Computer
- Serial terminal program connected to the MODRT1171 UART0 serial port
Board settings
No special settings are required. Loopback mode uses no package pins.
- Note
- This example is written for the MODRT1171 rev 1.5 module, and uses FlexCAN1 to match the other MODRT1171 CAN examples. At rev 1.6 (which makes the module a MOD5441X drop-in replacement), the FlexCAN1 signals move from the P1 header to the P2 header: RX moves P1.26 -> P2.41 and TX moves P1.27 -> P2.44. The FlexCAN1 peripheral instance and this example's code are unchanged; only the connector pins move – and this example uses no pins at all. Designs that need more than one CAN bus have options beyond FlexCAN1: FlexCAN3 is available on the I2C pins for designs that do not use I2C (or that bit-bang I2C on spare GPIO), and on rev 1.5 FlexCAN2 also reaches module pins – all three controllers support CAN FD. For pin details see the MODRT1171 Software Developer Guide and the MODRT1171 Pinout Update document: https://www.netburner.com/download/MODRT1171_Rev1p5_to_Rev1p6_Pinout_Update/
Running the demo
Build and load the application, then open the serial terminal:
==FlexCAN FD loopback example -- Start.==
Send 64-byte FD frame (BRS on) from MB9 to MB10
Received frame: edl=1 brs=1, 64 bytes
word0 = 0x00000000 word1 = 0x01010101 word2 = 0x02020202 word3 = 0x03030303
...
Payload verified: received data matches transmitted data.
Throughput comparison, 4096 bytes of payload each way:
Classic CAN: 512 frames x 8 bytes: 141309 us (231 kbit/s effective)
CAN FD BRS: 64 frames x 64 bytes: 23228 us (1410 kbit/s effective)
CAN FD moved the same payload 6.0x faster.
==FlexCAN FD loopback example -- Finish.==
The throughput difference comes from both FD improvements at once: 64-byte frames amortize the frame overhead (ID, CRC, acknowledgement) over 8x more payload, and bit-rate switching runs the data bits at 4x the arbitration rate.
For CAN FD on a real bus, see the CanFdSimple example. For the classic CAN version of this self-test, see FlexcanLoopback.