Skip to content

Commit 289cf15

Browse files
authored
Merge pull request #5347 from rtthread-bot/rtt_bot
[update] RT-Thread Robot automatic submission
2 parents fd9eea2 + 9bbb74a commit 289cf15

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_can.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* 2019-03-27 YLZ support double can channels, support stm32F4xx (only Legacy mode).
1313
* 2019-06-17 YLZ port to new STM32F1xx HAL V1.1.3.
1414
* 2021-02-02 YuZhe XU fix bug in filter config
15+
* 2021-8-25 SVCHAO The baud rate is configured according to the different APB1 frequencies.
16+
f4-series only.
1517
*/
1618

1719
#include "drv_can.h"
@@ -34,7 +36,22 @@ static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
3436
{CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ | CAN_BS2_3TQ | 150)},
3537
{CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ | CAN_BS2_3TQ | 300)}
3638
};
37-
#elif defined (SOC_SERIES_STM32F4)/* APB1 45MHz(max) */
39+
#elif defined (SOC_SERIES_STM32F4) /* 42MHz or 45MHz */
40+
#if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx) ||\
41+
defined(STM32F401xC) || defined(STM32F401xE) /* 42MHz(max) */
42+
static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
43+
{
44+
{CAN1MBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 3)},
45+
{CAN800kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ | CAN_BS2_5TQ | 4)},
46+
{CAN500kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 6)},
47+
{CAN250kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 12)},
48+
{CAN125kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 24)},
49+
{CAN100kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 30)},
50+
{CAN50kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 60)},
51+
{CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 150)},
52+
{CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 300)}
53+
};
54+
#else /* APB1 45MHz(max) */
3855
static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
3956
{
4057
{CAN1MBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 3)},
@@ -47,6 +64,7 @@ static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
4764
{CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 150)},
4865
{CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 300)}
4966
};
67+
#endif
5068
#elif defined (SOC_SERIES_STM32F7)/* APB1 54MHz(max) */
5169
static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
5270
{

0 commit comments

Comments
 (0)