+Zivadin Despotovic Here's the code. Check also the example contained in the stdPeriph example folder. It handles the commutation in a in a slightly different but better way. In my application i was forced by other requirements to commutate the motor in this way


void Six_Step_Drive::init()
{
 tim1_handle.Instance = TIM1;
 tim1_handle.Init.Prescaler = 0;
 tim1_handle.Init.Period = (SystemCoreClock / pwm_freq_) - 1; //ARR
 tim1_handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 tim1_handle.Init.RepetitionCounter = 0;
 tim1_handle.Init.CounterMode = TIM_COUNTERMODE_UP;

 if (HAL_TIM_PWM_Init(&tim1_handle) != HAL_OK) {
  info::error();
 }

 /* ******* other code ************ */

 oc_config_struct.OCPolarity = TIM_OCPOLARITY_HIGH;
 oc_config_struct.OCNPolarity = TIM_OCNPOLARITY_LOW;
 oc_config_struct.OCIdleState = TIM_OCIDLESTATE_SET;
 oc_config_struct.OCNIdleState = TIM_OCNIDLESTATE_SET;
 oc_config_struct.OCFastMode = TIM_OCFAST_DISABLE;

 // set OC1, OC2, OC3 channels:
 // start in timing mode, pwm will be enabled later
 oc_config_struct.OCMode = TIM_OCMODE_TIMING;
 // Start with 50% dc (i = 0) oc_config_struct.Pulse will be set later
 oc_config_struct.Pulse = (tim1_handle.Init.Period / 2) - 1;
 set_duty_cycle(parameters::motor::initial_duty_cycle);


 if (HAL_TIM_OC_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_1) != HAL_OK) {
  info::error();
 }

 if (HAL_TIM_OC_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_2) != HAL_OK) {
  info::error();
 }

 if (HAL_TIM_OC_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_3) != HAL_OK) {
  info::error();
 }

 /* ********* other code ********** */

 // Enable Tim1 software triggered commutation event
 HAL_TIMEx_ConfigCommutationEvent(&tim1_handle, TIM_TS_ITR1, TIM_COMMUTATION_SOFTWARE);
}


void Six_Step_Drive::step()
{
 // Duty cycle modification becomes effective only on
 // commutation to ensures that all three (two active)
 // phases will have the same duty cycle
 oc_config_struct.Pulse = pulse_ccr_;

 switch (step_) {

  case Steps::ONE_DNS:

   /*  Channel1 */
   oc_config_struct.OCMode = TIM_OCMODE_PWM1;
   /* OC1: (phase A : Drive) */
   oc_config_struct.OCPolarity = TIM_OCPOLARITY_HIGH;
   HAL_TIM_PWM_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_1);
   HAL_TIMEx_ConfigBreakDeadTime(&tim1_handle, &bdt_config_struct);
   HAL_TIM_PWM_Start(&tim1_handle, TIM_CHANNEL_1);
   /* OC1N: (NReset A : High (disable)) */
   HAL_TIMEx_PWMN_Stop(&tim1_handle, TIM_CHANNEL_1);

   /* Channel2 */
   oc_config_struct.OCMode = TIM_OCMODE_PWM1;
   /* OC2: (phase B : NDrive) */
   oc_config_struct.OCPolarity = TIM_OCPOLARITY_LOW;
   HAL_TIM_PWM_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_2);
   HAL_TIM_PWM_Start(&tim1_handle, TIM_CHANNEL_2);
   /* OC2N: (NReset B : High (disable)) */
   HAL_TIMEx_PWMN_Stop(&tim1_handle, TIM_CHANNEL_2);

   /*  Channel 3 */
   oc_config_struct.OCMode = TIM_OCMODE_INACTIVE;
   /* OC3: (phase C : Sense (hi-Z) */
   oc_config_struct.OCPolarity = TIM_OCPOLARITY_HIGH;
   HAL_TIM_OC_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_3);
   HAL_TIM_OC_Start(&tim1_handle, TIM_CHANNEL_3);
   /* OC3N (NReset C : Low (enable)) */
   HAL_TIMEx_OCN_Start(&tim1_handle, TIM_CHANNEL_3);

   step_ = Steps::TWO_DSN;
   break;

  case Steps::TWO_DSN:

   /*  Channel1 */
   oc_config_struct.OCMode = TIM_OCMODE_PWM1;
   /* OC1: (phase A : Drive) */
   oc_config_struct.OCPolarity = TIM_OCPOLARITY_HIGH;
   HAL_TIM_PWM_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_1);
   HAL_TIM_PWM_Start(&tim1_handle, TIM_CHANNEL_1);
   /* OC1N: (NReset A : High (disable)) */
   HAL_TIMEx_PWMN_Stop(&tim1_handle, TIM_CHANNEL_1);

   /*  Channel2 */
   oc_config_struct.OCMode = TIM_OCMODE_INACTIVE;
   /* OC2: (phase B : Sense (hi-Z)) */
   oc_config_struct.OCPolarity = TIM_OCPOLARITY_HIGH;
   HAL_TIM_OC_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_2);
   HAL_TIM_OC_Start(&tim1_handle, TIM_CHANNEL_2);
   /* OC2N: (NReset B : Low (enable)) */
   HAL_TIMEx_OCN_Start(&tim1_handle, TIM_CHANNEL_2);

   /*  Channel3 */
   oc_config_struct.OCMode = TIM_OCMODE_PWM1;
   /* OC3: (phase C : NDrive) */
   oc_config_struct.OCPolarity = TIM_OCPOLARITY_LOW;
   HAL_TIM_PWM_ConfigChannel(&tim1_handle, &oc_config_struct, TIM_CHANNEL_3);
   HAL_TIM_PWM_Start(&tim1_handle, TIM_CHANNEL_3);
   /* OC3N: (NReset C : High (disable)) */
   HAL_TIMEx_PWMN_Stop(&tim1_handle, TIM_CHANNEL_3);

   step_ = Steps::THREE_SDN;
   break;

  /* ******* OTHER CASES ************ */

 }

 // Issue a commutation event to let the the configuration become effective
 HAL_TIM_GenerateEvent(&tim1_handle, TIM_EventSource_COM);

}?
