cancel
Showing results for 
Search instead for 
Did you mean: 

Clock tree frequency values duplication in code

ranran
Senior II

Hello,

It seems that most examples (stm32cubeh7) are independent in clock tree values, which is exactly the correct way to do it, yet some of the examples are using hardcoded values duplicated from clock tree (duplication) which seems like a bad idea because of duplication.

For example, fdcan example FDCAN_Com_polling, is calculating the configuration based on the value set in clock tree,( but not using same define, or get_clock ) .

/* Bit time configuration:
  ************************
  Bit time parameter     | Nominal   | Data
  ---------------------------|--------------|----------------
  fdcan_ker_ck        | 20 MHz    | 20 MHz
  Time_quantum (tq)     | 50 ns    | 50 ns
....
  Bit_length         | 40 tq = 2 µs | 10 tq = 0.5 µs
  Bit_rate          | 0.5 MBit/s  | 2 MBit/s
 */
 hfdcan.Init.NominalPrescaler = 0x1; /* tq = NominalPrescaler x (1/fdcan_ker_ck) */

I am not familiar with other frequency duplication aside of fdcan, (yet, there might be)

Why is there such a duplication and isn't it better to create a get clock for these peripherals instead ?

Another thing I don't understand in fdcan example, in systemclock_config there are 2 comments regarding fdcan clock:

static void SystemClock_Config(void)
{
....
  RCC_OscInitStruct.PLL.PLLR = 2;
  RCC_OscInitStruct.PLL.PLLQ = 40;  /* fdcan_ker_ck = 20 MHz */
  
....
  RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;  
  RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; /* fdcan_pclk = 100 MHz */
 
  ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
...
}

I understand the 1st (fdcan_ker_ck ) which set fdcan clock frequenecy, but was is the relation between 2nd comment (fdcan_pclk ) and fdcan ?

Thanks,

ranran

0 REPLIES 0