cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMx Generates FDCAN clock divider multiple times for STM32G474RETx

HamTomo
Visitor

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

2 REPLIES 2
Ghofrane GSOURI
ST Employee

Hello @HamTomo 

I am checking this behavior. I will get back to you as soon as possible.

 

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @Ghofrane GSOURI 
.ioc is attached.
MCU_A.ioc is with both set to Clock divider 1.
MCU_A_2.ioc is with FDCAN1 set to Clock divider 2 and FDCAN2 set to Clock divider 1.
Hope it helps.