drivers/can: stm32fd fix not applied clock divider

The configurable CAN clock divider CAN_STM32FD_CLOCK_DIVISOR
was not applied during initialization, because write protection
was not disabled.

While the clock divider was not applied, it was still used in clock rate
calculation, therefore resulting in incorrect bus speed setup.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
This commit is contained in:
Thomas Stranger 2022-08-12 23:42:16 +02:00 committed by Fabio Baltieri
commit 09f45840f1
3 changed files with 15 additions and 0 deletions

View file

@ -1086,3 +1086,15 @@ int can_mcan_get_max_bitrate(const struct device *dev, uint32_t *max_bitrate)
return 0;
}
/* helper function allowing mcan drivers without access to private mcan
* definitions to set CCCR_CCE, which might be needed to disable write
* protection for some registers.
*/
void can_mcan_enable_configuration_change(const struct device *dev)
{
const struct can_mcan_config *cfg = dev->config;
struct can_mcan_reg *can = cfg->can;
can->cccr |= CAN_MCAN_CCCR_CCE;
}

View file

@ -296,4 +296,6 @@ void can_mcan_set_state_change_callback(const struct device *dev,
int can_mcan_get_max_bitrate(const struct device *dev, uint32_t *max_bitrate);
void can_mcan_enable_configuration_change(const struct device *dev);
#endif /* ZEPHYR_DRIVERS_CAN_MCAN_H_ */

View file

@ -87,6 +87,7 @@ static int can_stm32fd_clock_enable(const struct device *dev)
return ret;
}
can_mcan_enable_configuration_change(dev);
FDCAN_CONFIG->CKDIV = CAN_STM32FD_CLOCK_DIVISOR >> 1;
return 0;