cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H742 TIMER CLK 50MHz frequency

eogos
Associate II

I am using the STM32H742 MCU.
Currently, System CLOCK is set to 480 MHz and APB TIMER and AHB maximum CLK is set to 240 MHz.
However, the maximum frequency of TIMER and GPIO cannot exceed 25 MHz, so what should I do to make it over 50 MHz

Attached is the related code as well.

 

eogos_0-1758702607455.pngeogos_1-1758702626863.png

 

7 REPLIES 7
TDK
Super User

> the maximum frequency of TIMER and GPIO cannot exceed 25 MHz

Why not? Set PSC (Prescaler) to 0 and ARR (Period) to 1 and the frequency will be 120 MHz if the timer clock is 240 MHz. Ensure pin frequency is set to VERY_HIGH.

> AHB maximum CLK is set to 240 MHz

max AHB clock is 120 MHz on this chip.

If you feel a post has answered your question, please click "Accept as Solution".
eogos
Associate II

I set it like that, but the waveform appears as shown in the following picture

 

eogos_0-1758768471448.jpeg

 

eogos
Associate II

And I wonder why the cycle is at 25 MHz when I set the system clock to 480 MHz without timer and high/low it to gpio pin only. Gpio thought it would have a cycle of 240 MHz using ahb4bus.

Hello,

You asked another question in this thread today.

Is it the same question/related?

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.
TDK
Super User

Include a minimal (non-)working project which exhibits the problem.

If you feel a post has answered your question, please click "Accept as Solution".

Hello @eogos.

Switching the pin state does not fit into a single asm instruction, especially if it is wrapped in a function and speed optimization is not enabled.

 

To toggle the pin quickly, it makes sense to set up a timer function on one of the pins.

Here is my configuration for 48MHz with H753. The timer frequency is 240 MHz, and the pin is configured as TIM1_CH1. Every overflow pin toggles, so we have 48 / 2 = 24MHz output frequency on the TIM1_CH1 pin. You can get 30MHz toggling by decreasing period to 3, 40MHz by decreasing it to 2 and 60MHz by decreasing to 1. If you need 50, you should decrease timer clock from 240MHz to 200MHz for example, than set correct divider and period.

/**
  * @brief TIM1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_TIM1_Init(void)
{

  /* USER CODE BEGIN TIM1_Init 0 */

  /* USER CODE END TIM1_Init 0 */

  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_SlaveConfigTypeDef sSlaveConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};
  TIM_OC_InitTypeDef sConfigOC = {0};
  TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};

  /* USER CODE BEGIN TIM1_Init 1 */

  /* USER CODE END TIM1_Init 1 */
  htim1.Instance = TIM1;
  htim1.Init.Prescaler = 0;
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim1.Init.Period = 4;
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim1.Init.RepetitionCounter = 0;
  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_TIM_OC_Init(&htim1) != HAL_OK)
  {
    Error_Handler();
  }
  sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
  sSlaveConfig.InputTrigger = TIM_TS_ITR0;
  if (HAL_TIM_SlaveConfigSynchro(&htim1, &sSlaveConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
  sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
  if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }
  sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
  sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
  sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
  sBreakDeadTimeConfig.DeadTime = 0;
  sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
  sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
  sBreakDeadTimeConfig.BreakFilter = 0;
  sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
  sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
  sBreakDeadTimeConfig.Break2Filter = 0;
  sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
  if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM1_Init 2 */

  /* USER CODE END TIM1_Init 2 */
  HAL_TIM_MspPostInit(&htim1);

}


To start timer:

  /* Camera clock start */
  HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1);



Yes, it's the same question