cancel
Showing results for 
Search instead for 
Did you mean: 

TIM6 Configuration STM32G4

tomm5771
Associate III

I am having trouble configuring my TIM6 to toggle a GPIO pin every 1 usec. I am using the HSI at 16MHz as the source for AHB bus clocks, which TIM6 is on. 

The following is my System Clock configuration:

void SystemClock_Config(void)

{

LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);

while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_0)

{

}

LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);

LL_RCC_HSI_Enable();

/* Wait till HSI is ready */

while(LL_RCC_HSI_IsReady() != 1)

{

}

 

LL_RCC_HSI_SetCalibTrimming(64);

LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);

/* Wait till System clock is ready */

while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)

{

}

 

/* Set AHB prescaler*/

LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);

LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);

LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);

LL_SetSystemCoreClock(16000000);

 

/* Update the time base */

if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK)

{

Error_Handler();

}

}

 

I am then configuring TIM6 with the following:

static void MX_TIM6_Init(void)

{

 

/* USER CODE BEGIN TIM6_Init 0 */

 

/* USER CODE END TIM6_Init 0 */

 

LL_TIM_InitTypeDef TIM_InitStruct = {0};

 

/* Peripheral clock enable */

LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6);

 

/* TIM6 interrupt Init */

NVIC_SetPriority(TIM6_DAC_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));

NVIC_EnableIRQ(TIM6_DAC_IRQn);

 

/* USER CODE BEGIN TIM6_Init 1 */

 

/* USER CODE END TIM6_Init 1 */

TIM_InitStruct.Prescaler = 16 - 1;

TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;

TIM_InitStruct.Autoreload = 1;

LL_TIM_Init(TIM6, &TIM_InitStruct);

LL_TIM_EnableARRPreload(TIM6);

LL_TIM_SetTriggerOutput(TIM6, LL_TIM_TRGO_UPDATE);

LL_TIM_DisableMasterSlaveMode(TIM6);

LL_TIM_EnableIT_UPDATE(TIM6);

/* USER CODE BEGIN TIM6_Init 2 */

 

/* USER CODE END TIM6_Init 2 */

 

}

 

The GPIO is not toggling every usec as I expect it to. Is there something wrong with my configuration?

1 REPLY 1

You are trying to run interrupts at an irrationally high rate.

JW

PS. When posting code, please use the </> icon at top of the editor.