@@ -28,6 +28,8 @@ LOG_MODULE_REGISTER(can_stm32h7, CONFIG_CAN_LOG_LEVEL);
28
28
#define STM32H7_FDCAN_DOMAIN_CLOCK_SUPPORT 0
29
29
#endif
30
30
31
+ #define VOS0_MAX_FREQ MHZ(125)
32
+
31
33
struct can_stm32h7_config {
32
34
mm_reg_t base ;
33
35
mem_addr_t mrba ;
@@ -107,6 +109,7 @@ static int can_stm32h7_clock_enable(const struct device *dev)
107
109
const struct can_mcan_config * mcan_cfg = dev -> config ;
108
110
const struct can_stm32h7_config * stm32h7_cfg = mcan_cfg -> custom ;
109
111
const struct device * const clk = DEVICE_DT_GET (STM32_CLOCK_CONTROL_NODE );
112
+ uint32_t fdcan_clock = 0xffffffff ;
110
113
int ret ;
111
114
112
115
if (!device_is_ready (clk )) {
@@ -122,6 +125,24 @@ static int can_stm32h7_clock_enable(const struct device *dev)
122
125
LOG_ERR ("Could not select can_stm32fd domain clock" );
123
126
return ret ;
124
127
}
128
+
129
+ /* Check if clock has correct range according to chosen regulator voltage
130
+ * scaling (Table 62 of RM0399 Rev 4).
131
+ * There is no need to test HSE case, since it's value is in range of
132
+ * 4 to 50 MHz (please refer to CubeMX clock control).
133
+ */
134
+ ret = clock_control_get_rate (clk ,
135
+ (clock_control_subsys_t )& stm32h7_cfg -> pclken [1 ], & fdcan_clock );
136
+ if (ret != 0 ) {
137
+ LOG_ERR ("failure getting clock rate" );
138
+ return ret ;
139
+ }
140
+
141
+ if (fdcan_clock > VOS0_MAX_FREQ ) {
142
+ LOG_ERR ("FDCAN Clock source %d exceeds max allowed %d" ,
143
+ fdcan_clock , VOS0_MAX_FREQ );
144
+ return - ENODEV ;
145
+ }
125
146
}
126
147
127
148
ret = clock_control_on (clk , (clock_control_subsys_t )& stm32h7_cfg -> pclken [0 ]);
0 commit comments