While debugging CAN for STMF103C8T6, I came across a small problem in
can_init() that needs correction:

lib/stm32/can.c around line 176:

        /* Set bit timings. */
        CAN_BTR(canport) |= sjw | ts2 | ts1 |
                ((brp - 1ul) & CAN_BTR_BRP_MASK);

The problem with this statement is the "|=" part.  I discovered I was
getting a high bit on in the BRP field because of a pre-existing value. If
I supply a different value than the current value, it just gets OR-ed into
the register with the existing bits.  Obviously unintended behaviour. The
same problem exists for the SWJ/TS2/TS1 bit fields.

There is one additional problem in the header file
include/libopencm3/stm32/can.h near line 483:

/* BRP[9:0]: Baud rate prescaler */
#define CAN_BTR_BRP_MASK                (0x1FFUL << 0)

This ten bit field should have the mask value of 0x3FFUL, rather than 1FFUL.

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
libopencm3-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libopencm3-devel

Reply via email to