ttlappalainen
Member
I have been developing NMEA2000 library since 2015. It has used FlexCAN library with teensy. The original FlexCAN library did not use interrupting for receiving and transmitting. The new version of FlexCAN did not work with our system due to compatibilitys change on initialization. Some days ago I started to solve problems with new version to get interrupt handled frame handling to work. So I finally found several bugs on Current FlexCAN release:
- There was parameter used before initialization. So my code sometimes started to communicate and sometimes not.
- There was no interrupt locking during reading and writing buffers outside of interrupt. So in possible case one could just read buffer and change buffer read index, while you got interrupt for new frame, which also modifies indexes. In principle different indexes will be used, but it is not good to rely that all logic will work.
- writing frames tested is mail box free a bit wrong.
- writing to specific mailbox caused that mailbox lock time to time.
- frames were sometimes send in wrong order. In NMEA 2000 it is important that fast packet frames will be sent on right order.
I made new fork under my repositories (https://github.com/ttlappalainen/FlexCAN_Library), where
- I fixed errors I found.
- I also made cosmetic changes to code to improve readibility.
- Added mailbox specific transmit buffers, which user have to enable
- Changed buffers sizing so that it does not require code change. So buffers are created dynamically on open.
Code after my changes should be still compatible with current version of FlexCAN library except now it works reliably with NMEA 2000 protocol.
So I would prefer to at least think about updating FlexCAN library! I also prefer that someone with CAN project would try my fork for testing.
- There was parameter used before initialization. So my code sometimes started to communicate and sometimes not.
- There was no interrupt locking during reading and writing buffers outside of interrupt. So in possible case one could just read buffer and change buffer read index, while you got interrupt for new frame, which also modifies indexes. In principle different indexes will be used, but it is not good to rely that all logic will work.
- writing frames tested is mail box free a bit wrong.
- writing to specific mailbox caused that mailbox lock time to time.
- frames were sometimes send in wrong order. In NMEA 2000 it is important that fast packet frames will be sent on right order.
I made new fork under my repositories (https://github.com/ttlappalainen/FlexCAN_Library), where
- I fixed errors I found.
- I also made cosmetic changes to code to improve readibility.
- Added mailbox specific transmit buffers, which user have to enable
- Changed buffers sizing so that it does not require code change. So buffers are created dynamically on open.
Code after my changes should be still compatible with current version of FlexCAN library except now it works reliably with NMEA 2000 protocol.
So I would prefer to at least think about updating FlexCAN library! I also prefer that someone with CAN project would try my fork for testing.