Skip to content

Commit 35e7d9c

Browse files
HenrikSolverdpgeorge
authored andcommitted
stmhal/can: Fix a bug in filter handling.
Reported here: http://forum.micropython.org/viewtopic.php?f=2&t=845
1 parent 06f7097 commit 35e7d9c

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

stmhal/can.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,10 @@ STATIC mp_obj_t pyb_can_setfilter(mp_uint_t n_args, const mp_obj_t *pos_args, mp
688688
rtr_masks[1] = mp_obj_get_int(rtr_flags[1]) ? 0x02 : 0;
689689
}
690690
}
691-
filter.FilterIdHigh = (mp_obj_get_int(params[0]) & 0xFF00) >> 13;
692-
filter.FilterIdLow = (((mp_obj_get_int(params[0]) & 0x00FF) << 3) | 4) | rtr_masks[0];
693-
filter.FilterMaskIdHigh = (mp_obj_get_int(params[1]) & 0xFF00 ) >> 13;
694-
filter.FilterMaskIdLow = (((mp_obj_get_int(params[1]) & 0x00FF) << 3) | 4) | rtr_masks[1];
691+
filter.FilterIdHigh = (mp_obj_get_int(params[0]) & 0x1FFFE000) >> 13;
692+
filter.FilterIdLow = (((mp_obj_get_int(params[0]) & 0x00001FFF) << 3) | 4) | rtr_masks[0];
693+
filter.FilterMaskIdHigh = (mp_obj_get_int(params[1]) & 0x1FFFE000 ) >> 13;
694+
filter.FilterMaskIdLow = (((mp_obj_get_int(params[1]) & 0x00001FFF) << 3) | 4) | rtr_masks[1];
695695
if (args[1].u_int == MASK32) {
696696
filter.FilterMode = CAN_FILTERMODE_IDMASK;
697697
}

tests/pyb/can.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@
5858
else:
5959
print('failed, wrong data received')
6060

61+
# Test filters
62+
for n in [0, 8, 16, 24]:
63+
filter_id = 0b00001000 << n
64+
filter_mask = 0b00011100 << n
65+
id_ok = 0b00001010 << n
66+
id_fail = 0b00011010 << n
67+
68+
can.clearfilter(0)
69+
can.setfilter(0, pyb.CAN.MASK32, 0, (filter_id, filter_mask))
70+
71+
can.send('ok', id_ok, timeout=3)
72+
if can.any(0):
73+
msg = can.recv(0)
74+
print((hex(filter_id), hex(filter_mask), hex(msg[0]), msg[3]))
75+
76+
can.send("fail", id_fail, timeout=3)
77+
if can.any(0):
78+
msg = can.recv(0)
79+
print((hex(filter_id), hex(filter_mask), hex(msg[0]), msg[3]))
80+
6181
del can
6282

6383
# Test RxCallbacks

tests/pyb/can.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ True
1616
passed
1717
CAN(1, CAN.LOOPBACK, extframe=True)
1818
passed
19+
('0x8', '0x1c', '0xa', b'ok')
20+
('0x800', '0x1c00', '0xa00', b'ok')
21+
('0x80000', '0x1c0000', '0xa0000', b'ok')
22+
('0x8000000', '0x1c000000', '0xa000000', b'ok')
1923
cb0
2024
pending
2125
cb0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy