초보의 아웅다웅 설계하기/STM32

STM32H743 LL_Driver Timer

로망와니 2019. 11. 10. 09:34

분주하는 부분에서 약간 헤맸습니다.

 

 

/*******************************************************************************
* Function Name : 
* Parameters    : None
* Return        : None
* Description   : 
DEBUGPRINT("%d \r\n", SystemCoreClock);//400000000
*******************************************************************************/
void Config_TIM(void)
{
uint32_t Prescaler;
Prescaler = (uint32_t)(SystemCoreClock / (2*1000000)) - 1;

Init_Timer(eTimer2, 1000000, eInterruptEnable, Prescaler);
}

 

/*******************************************************************************
* Function Name : 
* Parameters    : None
* Return        : 
* Description   : 
*******************************************************************************/

int Init_Timer(const uint8_t a_chTimer, const uint32_t a_nUs, const InterruptEnableState a_chInt, const uint32_t a_nPrescaler)
{
/* Initial autoreload value */
if(a_nPrescaler > 65536){
return 1;
}
  
  if(a_chTimer == 1){
  }  
  else if(a_chTimer == 2){
/* Enable the timer peripheral clock */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); 

/* Set counter mode */
/* Reset value is LL_TIM_COUNTERMODE_UP */
LL_TIM_SetCounterMode(TIM2, LL_TIM_COUNTERMODE_UP);

/* Set the pre-scaler value to have TIM2 counter clock equal to 10 kHz      */
LL_TIM_SetPrescaler(TIM2, a_nPrescaler);

// LL_TIM_SetClockDivision(TIM2, 64);

/* Set the auto-reload value to have an initial update event frequency of 10 Hz */
LL_TIM_SetAutoReload(TIM2, a_nUs);

    if(a_chInt == eInterruptEnable){
/* Enable the update interrupt */
LL_TIM_EnableIT_UPDATE(TIM2);

/* Configure the NVIC to handle TIM2 update interrupt */
NVIC_SetPriority(TIM2_IRQn, 0);
NVIC_EnableIRQ(TIM2_IRQn);
}
/* Enable counter */
LL_TIM_EnableCounter(TIM2);

/* Force update generation */
LL_TIM_GenerateEvent_UPDATE(TIM2);
  }

return 0;

}