Skip to content

stm32: pyb.CAN.init(extframe=False) excludes all frames #5508

Description

@jimmo

From the forum -- https://forum.micropython.org/viewtopic.php?f=2&t=7530 (I have not verified this myself though)

Activity

  1. JohnieBraaf commented on Jan 9, 2020

    @JohnieBraaf
    Contributor

    thnx @jimmo, see the details below:

    There apprears to be an issue in the CAN drivers which prevents receiving messages with non extended id's.

    As a test I'm using a pyboard-D to send data between the 2 CAN ports.
    This works fine when the can filter is set to extframe=True.
    can.init(mode=pyb.CAN.NORMAL, extframe=True, prescaler=4, sjw=1, bs1=7, bs2=1)

    However, when changed to False, there are no incoming frames detected.
    I can see the frames with a CAN bus analyzer, but the rx callback does not trigger.
    can.init(mode=pyb.CAN.NORMAL, extframe=False, prescaler=4, sjw=1, bs1=7, bs2=1


    I think I might have found where this goes wrong.

    I'm using CAN.MASK32 with a blank values like this:
    can.setfilter(bank=self.itf-1, mode=pyb.CAN.MASK32, fifo=self.itf-1, params=(0x0, 0x0))

    Now when I trace back the code, I come to pyb_can.c, where the filtermasks are set.
    They appear to be designed for extended identifier format judging from the high value 0x1FFFE000.

    filter.FilterIdHigh = (mp_obj_get_int(params[0]) & 0x1FFFE000) >> 13;
    filter.FilterIdLow = (((mp_obj_get_int(params[0]) & 0x00001FFF) << 3) | 4) | rtr_masks[0];
    filter.FilterMaskIdHigh = (mp_obj_get_int(params[1]) & 0x1FFFE000 ) >> 13;
    filter.FilterMaskIdLow = (((mp_obj_get_int(params[1]) & 0x00001FFF) << 3) | 4) | rtr_masks[1];

    Now when I change it to blank, I start receiving the packets.
    filter.FilterIdHigh = 0x0000; filter.FilterIdLow = 0x0000;
    filter.FilterMaskIdHigh = 0x0000; filter.FilterMaskIdLow = 0x0000;

    I don't understand the bitwise operators that are applied in the original code, maybe someone can have a look at it.

  2. gooyle commented on Oct 15, 2020

    @gooyle

    has it been fixed already?we met it again,firmware we used is pybv11-20200902-v1.13

  3. JohnieBraaf commented on Oct 15, 2020

    @JohnieBraaf
    Contributor

    Don't think so. You will need to hack the workaround in yourself or even better attempt a proper fix. The workaround works in any case

  4. gooyle commented on Oct 25, 2020

    @gooyle

    thx,a new version lib works,no preblems appear till now

  5. added a commit that references this issue on Oct 28, 2021
  6. JohnieBraaf commented on Jan 24, 2022

    @JohnieBraaf
    Contributor

    While writing down the steps to reproduce and looking at the code I realized, I should have used MASK16 instead of MASK32.
    Sorry for the confusion. I managed to receive non-extended id messages on non fd interfaces with the following filter:
    can1.setfilter(bank=0, mode=pyb.CAN.MASK16, fifo=0, params=(0x0, 0x0, 0x0, 0x0))

  7. JohnieBraaf commented on Jan 24, 2022

    @JohnieBraaf
    Contributor

    @jimmo this issue can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions