I am trying to run a BLDC motor with TIM1 on STM32F401RE. I want to use a software commutation event with HAL drivers as is done in the "6step" examples. So far the call back is not working. Please tell me what I am missing. Thanks.
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
//TimHandle.Instance = TIM1;
HAL_TIMEx_ConfigCommutEvent_IT(&htim1, TIM_TS_NONE, TIM_COMMUTATION_SOFTWARE);
/* USER CODE END Init */
/////////////////////////////////////////////////////////////////////////////////////////
/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim){
if(htim->Instance == (TIM2)){
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_14);
HAL_TIM_GenerateEvent(&htim1, TIM_EventSource_COM);
//count++;
//BRG_switch(); //<-this call is working
}
//if(htim->Instance == (TIM1)){pwm++;}
}
void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim1){
count++;
BRG_switch(); //<-this call is not working!
}