Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Fix for FlexCAN library provided with Teensyduino

  1. #1

    Fix for FlexCAN library provided with Teensyduino

    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.

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Detroit, Michigan, USA
    Posts
    101
    I have cloned it and I will begin testing it. I have used Colin's FlexCAN with great success, so I look forward to testing with this version.

    Just swapping libraries from a known-good implementation of the COlinK library, here's the result:

    Code:
    FlexCAN.h: In member function void FlexCAN::irqLock()
     
    FlexCAN.h: 126:49: error: 'IRQ_CAN_MESSAGE' was not declared in this scope
       void irqLock() { IrqEnabled=NVIC_IS_ENABLED(IRQ_CAN_MESSAGE); NVIC_DISABLE_IRQ(IRQ_CAN_MESSAGE); }
    kinetis.h:5630: note  in definition of macro NVIC_IS_ENABLED
       #define NVIC_IS_ENABLED(n) (*((volatile uint32_t *)0xE000E100 + ((n) >> 5)) & (1 << ((n) & 31)))
    FlexCAN.h: In member function void FlexCAN::irqRelease()
    Last edited by Detroit_Aristo; 06-23-2017 at 01:17 AM.

  3. #3
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    271
    Quote Originally Posted by Detroit_Aristo View Post
    I have cloned it and I will begin testing it. I have used Colin's FlexCAN with great success, so I look forward to testing with this version.

    Just swapping libraries from a known-good implementation of the COlinK library, here's the result:

    Code:
    FlexCAN.h: In member function void FlexCAN::irqLock()
     
    FlexCAN.h: 126:49: error: 'IRQ_CAN_MESSAGE' was not declared in this scope
       void irqLock() { IrqEnabled=NVIC_IS_ENABLED(IRQ_CAN_MESSAGE); NVIC_DISABLE_IRQ(IRQ_CAN_MESSAGE); }
    kinetis.h:5630: note  in definition of macro NVIC_IS_ENABLED
       #define NVIC_IS_ENABLED(n) (*((volatile uint32_t *)0xE000E100 + ((n) >> 5)) & (1 << ((n) & 31)))
    FlexCAN.h: In member function void FlexCAN::irqRelease()
    I am getting this issue in Collin's FlexCAN library as well(https://github.com/collin80/FlexCAN_Library), but Pawsky's works fine (https://github.com/pawelsky/FlexCAN_Library).

  4. #4
    Quote Originally Posted by brtaylor View Post
    I am getting this issue in Collin's FlexCAN library as well(https://github.com/collin80/FlexCAN_Library), but Pawsky's works fine (https://github.com/pawelsky/FlexCAN_Library).
    I have IRQ_CAN_MESSAGE defined on c:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\ki netis.h, which came with latest Teensyduino (1.36?) I have downloaded.

    Collin80 has now merged library, so there will be same problem.

  5. #5
    Senior Member
    Join Date
    Jan 2013
    Posts
    843
    Quote Originally Posted by ttlappalainen View Post
    I have IRQ_CAN_MESSAGE defined on c:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\ki netis.h, which came with latest Teensyduino (1.36?) I have downloaded.
    IRQ_CAN_MESSAGE is only there for Teensy 3.2. Teensy 3.5 / 3.6 use IRQ_CAN0_MESSAGE / IRQ_CAN1_MESSAGE:

    https://github.com/collin80/FlexCAN_...exCAN.cpp#L224

  6. #6
    Quote Originally Posted by tni View Post
    IRQ_CAN_MESSAGE is only there for Teensy 3.2. Teensy 3.5 / 3.6 use IRQ_CAN0_MESSAGE / IRQ_CAN1_MESSAGE:

    https://github.com/collin80/FlexCAN_...exCAN.cpp#L224
    Is there common way to disable CAN interrupt? If not then I have to save CAN id and use that.

    For some reason global disable nointerrupts/interrupts did not work.

  7. #7
    My mistake. Download updated fix on my fork.

  8. #8
    My original question is still open. Could FlexCan library provided with Teensyduino be my developed version. Now when people installs Teensyduino, it installs as default the version, which does not work right with NMEA2000. So to get things working, they have to manually remove FlexCan under "C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FlexCA N"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •