FD update!!
FD is up for testing! Big update!
Sorry guys I have been busy for months but I never give up on this
I spent time on doing text-like graphs for the new baudrate generator in FlexCAN_T4FD.
According to NXP, after they tested, advertised, and documented it as having FD FIFO, they now claim that the 1062 does NOT have FD FIFO, only mailbox support. So throwing it out here in case FIFO is questioned, it is NOT supported.
There are big changes to the way the library operates, it is more efficient and faster redesign implementation of IFCT. (Take what you learn and make it better, right?
Sketch:
Code:
#include <FlexCAN_T4.h>
FlexCAN_T4FD<CAN3, RX_SIZE_256, TX_SIZE_16> FD;
void setup(void) {
Serial.begin(115200); delay(500);
pinMode(6, OUTPUT); digitalWrite(6, LOW);
FD.begin();
[COLOR="#FF0000"] CANFD_timings_t config;
config.clock = CLK_24MHz;
config.baudrate = 1000000;
config.baudrateFD = 2000000;
config.propdelay = 190;
config.bus_length = 1;
config.sample = 87.5;
FD.setBaudRate(config, 1, 1);[/COLOR]
FD.onReceive(canSniff);
FD.setMBFilter(REJECT_ALL);
FD.setMBFilter(MB22, ACCEPT_ALL);
FD.setMBFilter(MB0, 0x8);
FD.setMBFilter(MB12, 0x1, 0x04);
FD.setMBFilterRange(MB13, 0x1, 0x04);
FD.enableMBInterrupt(MB12);
FD.enableMBInterrupt(MB13);
FD.mailboxStatus();
FD.enhanceFilter(MB12);
FD.enhanceFilter(MB13);
FD.distribute();
}
void canSniff(const CANFD_message_t &msg) {
Serial.print("ISR - MB "); Serial.print(msg.mb);
Serial.print(" OVERRUN: "); Serial.print(msg.flags.overrun);
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" EXT: "); Serial.print(msg.flags.extended);
Serial.print(" TS: "); Serial.print(msg.timestamp);
Serial.print(" ID: "); Serial.print(msg.id, HEX);
Serial.print(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print(msg.buf[i], HEX); Serial.print(" ");
} Serial.println();
}
void loop() {
FD.events(); /* needed for sequential frame transmit and callback queues */
CANFD_message_t msg;
msg.len = 8;
msg.id = 0x321;
msg.seq = 1;
msg.buf[0] = 1; msg.buf[1] = 2; msg.buf[2] = 3; msg.buf[3] = 4;
msg.buf[4] = 5; msg.buf[5] = 6; msg.buf[6] = 9; msg.buf[7] = 9;
FD.write( msg);
if ( FD.read(msg) ) {
bool prnt = 1;
if ( prnt ) {
Serial.print("MB: "); Serial.print(msg.mb);
Serial.print(" OVERRUN: "); Serial.print(msg.flags.overrun);
Serial.print(" ID: 0x"); Serial.print(msg.id, HEX );
Serial.print(" EXT: "); Serial.print(msg.flags.extended );
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" DATA: ");
for ( uint8_t i = 0; i < 8; i++ ) {
Serial.print(msg.buf[i]); Serial.print(" ");
}
Serial.print(" TS: "); Serial.println(msg.timestamp);
}
}
delay(25);
}
1) The clocks and bitrates are set by the red region in the sketch posted above. You have full control of the baudrates for nominal, data, length of bus, propagation delay of transceiver, and what clock you want to use.
1000/6000 was tested by skpang on his analyzer using CLK_60MHz.
2) Automatic Filtering support! - More efficient, More faster than previous implementation! Mask? What mask? Put your ID and your all set!
3) Smart filtering support! - More efficient, More faster than previous implementation! Stop those bleed-thru frames in a multi/range setup mailbox mask!
4) Distribution support! - Having mailbox 13 capture 2 can ids only? CAN ID 0x1 and 0x4, and mailbox 14 capture can ids range based from 0x2-0x5? Heads up, Your second callback won't fire because the hardware is designed to drop it into ONLY one. So ID 0x04 will ONLY goto mailbox 13, and not 14. With distribution support, all overlapping filter callbacks with a match will get a copy!
5) Change the region sizes of your memory blocks! Want 8, 16, 32 or 64 bytes data for send/receive? The bigger the data, the less amount of mailboxes you'll have. No problem for the library to handle! FD.setRegions(64); sets 14 mailboxes with 64 bytes data!
6) Callback and CBA queue support! More optimized, faster than previous implementation
7) Direct mailbox offset support, unlike the SDK running hundreds of thousands of divisions in a constant poll/isr for mailbox access, FlexCAN_T4 accesses it using a different calculation method, division is NOT required to get to the mailbox ram location!
8) Sequential frame support with ability to resend should the mailbox be busy! Keep your frames in-order!
msg.seq = 1;
PS: Thanks Paul and Robin for getting me the hardware needed to get this setup needed to work with and mjs513 for the SDK code I can work against.
Github has been updated! (Note, This is the FD side I'm working on, I will adapt the optimisations later to the CAN2.0 side once things are running good on FD end)
https://github.com/tonton81/FlexCAN_T4/