CubeMx Generates FDCAN clock divider multiple times for STM32G474RETx
When configuring multiple FDCAN instances in CubeMx, the clock divider settings are not synchronised and are generated twice.
For me, FDCAN1 clock divider has the drop down box with multiple options.
FDCAN2 only has the "Divide kernel clock by 1" option. This should match FDCAN1 as one common clock divider value. "The clock is common to all FDCAN instances. This parameter is applied only at initialisation of first FDCAN instance." from UM2570.
The first issue is within CubeMx, this clock divider value is then used for the indicator calculations:
- Nominal Time Quantum
- Nominal Time for One Bit
- Nominal Baud Rate
If the clock values are wrong, these values will be wrong.
Second issue is the Init.ClockDivider code is generated twice, one per instance instead of just once.
If these values are the same, there'll be no issue. If different then the latter will overwrite the former.
In main.c
MX_FDCAN1_Init();
MX_FDCAN2_Init();
in fdcan.c
void MX_FDCAN1_Init(void)
{
/* USER CODE END FDCAN1_Init 1 */
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV2;
// More code removed
}
void MX_FDCAN2_Init(void)
{
/* USER CODE END FDCAN2_Init 1 */
hfdcan2.Instance = FDCAN2;
hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1;
// More code removed
}
CubeMx version 6.17.0