Repository navigation
stm32: pyb.CAN.init(extframe=False) excludes all frames #5508
Description
Activity
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.micropython/ports/stm32/pyb_can.c
Lines 710 to 713 in bfbd944
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.
has it been fixed already?we met it again,firmware we used is
pybv11-20200902-v1.13Don'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
thx,a new version lib works,no preblems appear till now
- added a commit that references this issue
on Oct 28, 2021 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))@jimmo this issue can be closed
From the forum -- https://forum.micropython.org/viewtopic.php?f=2&t=7530 (I have not verified this myself though)