Discussion:
[libopencm3-devel] lib/stm32/can.c correction request: can_filter_id_mask_16bit_init()
Warren Gay
2017-05-20 00:42:36 UTC
Permalink
I made the following small change locally to the routine
*can_filter_id_mask_16bit_init()* to get it working correctly. The mask and
id values need to be reversed (mask goes to the upper 16 bits, while the
IDs values go to the lower 16 bits):

diff --git a/lib/stm32/can.c b/lib/stm32/can.c
index a7ca00fd..4e9d7c07 100644
--- a/lib/stm32/can.c
+++ b/lib/stm32/can.c
@@ -276,8 +276,8 @@ void can_filter_id_mask_16bit_init(uint32_t canport,
uint32_t nr, uint16_t id1,
uint16_t mask2, uint32_t fifo, bool
enable)
{
can_filter_init(canport, nr, false, false,
- ((uint32_t)id1 << 16) | (uint32_t)mask1,
- ((uint32_t)id2 << 16) | (uint32_t)mask2, fifo,
enable);
+ ((uint32_t)mask1 << 16) | (uint32_t)id1,
+ ((uint32_t)mask2 << 16) | (uint32_t)id2, fifo,
enable);
}

Once this change was made, both of my filters worked correctly (with my
setup, sending odd 11-bit addresses to one fifo, and the even addresses to
the other).

Thanks, Warren
Karl Palsson
2017-05-23 21:53:06 UTC
Permalink
Thanks for this. I can confirm this against the ref manuals and
have staged this in my tree.

Cheers,
Karl P
Post by Warren Gay
I made the following small change locally to the routine
*can_filter_id_mask_16bit_init()* to get it working correctly.
The mask and id values need to be reversed (mask goes to the
diff --git a/lib/stm32/can.c b/lib/stm32/can.c
index a7ca00fd..4e9d7c07 100644
--- a/lib/stm32/can.c
+++ b/lib/stm32/can.c
@@ -276,8 +276,8 @@ void can_filter_id_mask_16bit_init(uint32_t canport,
uint32_t nr, uint16_t id1,
uint16_t mask2, uint32_t fifo, bool
enable)
{
can_filter_init(canport, nr, false, false,
- ((uint32_t)id1 << 16) | (uint32_t)mask1,
- ((uint32_t)id2 << 16) | (uint32_t)mask2, fifo,
enable);
+ ((uint32_t)mask1 << 16) | (uint32_t)id1,
+ ((uint32_t)mask2 << 16) | (uint32_t)id2, fifo,
enable);
}
Once this change was made, both of my filters worked correctly
(with my setup, sending odd 11-bit addresses to one fifo, and
the even addresses to the other).
Thanks, Warren
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org!
http://sdm.link/slashdot_______________________________________________
libopencm3-devel mailing list
https://lists.sourceforge.net/lists/listinfo/libopencm3-devel
Loading...