One, can baud rate
STM32 bit time definition:
Synchronization segment (SYNC_SEG): The change in the expected bit usually occurs within that time period. Its value is fixed to 1
Time unit (1 x tcan).
Time period 1 (BS1): Defines the location of the sample point. It contains the PROP_SEG in the Can standard and
Phase_seg1. The value can be programmed to 1 to 16 time units, but can also be automatically extended
To compensate for the forward drift of the phase caused by the frequency difference of different nodes in the network.
Time period 2 (BS2): Defines the location of the send point. It stands for the can standard.
PHASE_SEG2. The value can be programmed to 1 to 8 time units, but can also be automatically shortened
To compensate for the negative drift of the phase
BRP[9:0]: Baud rate divider
PCLK1 = 36M
bps = 36m/(brp[9:0]* (BS1+BS2+SYNC_SEG))
Where sync_seg is fixed to 1 time units so bps = 36m/(brp[9:0]* (bs1+bs2+1)), it's okay to pay attention to sync jump width sjw, although he has been set to 1.
Second, can sampling point
The sampling point is between time period 1 and time period 2. According to the CIA recommended sampling points, preferably set in 85%~90%.
Check on the Internet a lot, basically is so calculated (bs1+1)/(1+BS1+BS2), the result is BS1 is larger and BS2 relatively small is basically 1.
STM32 CAN baud rate setting and sample point setting