cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in CAN_TransmitStatus function?

raymartin
Associate II
Posted on June 10, 2013 at 23:31

I noticed something strange with the CAN_TransmitStatus function in the stm32f10x_can.c (V3.1.2) peripheral driver code. Most of the time it works fine but occasionally it returns the wrong status. The root cause is it’s reading the CANx->TSR register multiple times when updating “state�?. If that register changes between reads, the logic based on “state�? becomes corrupt. The correct way to do this is to first capture CANx->TSR in a local variable then test that value.

1 REPLY 1
stm322399
Senior
Posted on February 13, 2014 at 10:55

I just tumbled on your issue, and I agree that multiple readings of TSR is wrong. I assume that the bit organization inside that register may be leveraged by using 8-bit read depending which mailbox you need to check. An answer from ST about byte access to that register will be appreciated.

Moreover, I suggest that an empty mailbox just return that it is empty and not (as it is currently the case) that transmission failed.