Skip to content

Commit 5db55b0

Browse files
drivers: can: can_stm32h7_fdcan: add device fail on invalid fed clock value
Fail on wrong FDCAN clock in can_stm32h7_clock_enable() stage. Signed-off-by: Alexander Kozhinov <[email protected]>
1 parent df6d4e7 commit 5db55b0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

drivers/can/can_stm32h7_fdcan.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ LOG_MODULE_REGISTER(can_stm32h7, CONFIG_CAN_LOG_LEVEL);
2828
#define STM32H7_FDCAN_DOMAIN_CLOCK_SUPPORT 0
2929
#endif
3030

31+
#define VOS0_MAX_FREQ MHZ(125)
32+
3133
struct can_stm32h7_config {
3234
mm_reg_t base;
3335
mem_addr_t mrba;
@@ -107,6 +109,7 @@ static int can_stm32h7_clock_enable(const struct device *dev)
107109
const struct can_mcan_config *mcan_cfg = dev->config;
108110
const struct can_stm32h7_config *stm32h7_cfg = mcan_cfg->custom;
109111
const struct device *const clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
112+
uint32_t fdcan_clock = 0xffffffff;
110113
int ret;
111114

112115
if (!device_is_ready(clk)) {
@@ -122,6 +125,24 @@ static int can_stm32h7_clock_enable(const struct device *dev)
122125
LOG_ERR("Could not select can_stm32fd domain clock");
123126
return ret;
124127
}
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+
}
125146
}
126147

127148
ret = clock_control_on(clk, (clock_control_subsys_t)&stm32h7_cfg->pclken[0]);

0 commit comments

Comments
 (0)