AnsweredAssumed Answered

STM32CubeF4 OnePulse mode on TIMER12

Question asked by klimala.alan.001 on Apr 9, 2014
Latest reply on May 27, 2014 by viktor.pestov
Hi all,

I have been trying to configure TIM12 to work in OnePulse mode and I am not able to accomplish that. With elder version of device drivers I was able to achieve what I needed in such a way:
/** Create appropriate configuration structures. */
TIM_TimeBaseInitTypeDef xTimeBaseStructure;
TIM_OCInitTypeDef       xOCInitStructure;
 
/** Call timer's PINs configuration. */
prvConfigurePulseTimerPins();
 
/** Time base configuration */
xTimeBaseStructure.TIM_Period = 400;
xTimeBaseStructure.TIM_Prescaler = (uint16_t) ((SystemCoreClock / 2) / 40000000) - 1;
xTimeBaseStructure.TIM_ClockDivision = 0;
xTimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM12, &xTimeBaseStructure);
 
/** Timer PWM2 Mode configuration: Channel1 */
xOCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
xOCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
xOCInitStructure.TIM_Pulse = 1;
xOCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(fphTimersHal_PulseTimer, &xOCInitStructure);
 
/** One Pulse Mode selection */
TIM_SelectOnePulseMode(fphTimersHal_PulseTimer, TIM_OPMode_Single);
 
/** Slave Mode selection: Trigger Mode */
TIM_InternalClockConfig(fphTimersHal_PulseTimer);

And it was enough to force TIM12 to produce one pulse on its OC1 output after call:
TIM_Cmd(TIM12, ENABLE);

Now, with the new drivers (HAL) I am not able to achieve what I want. First of all, how to force timer to be triggered by internal clock in OPM? It seems that HAL_TIM_OnePulse_ConfigChannel() expects input and output channel to be passed. I have no input channel in my solution, so I tried to overcome that by such a code:
TIM_OC_InitTypeDef sConfigOC;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_ClockConfigTypeDef sClockSourceConfig;
 
/* Time base initialization. */
OnePulsOutputTimerHdlr.Instance = TIM12;
OnePulsOutputTimerHdlr.Init.Prescaler = (uint16_t) ((SystemCoreClock / 2)/ 40000000) - 1;
OnePulsOutputTimerHdlr.Init.CounterMode = TIM_COUNTERMODE_UP;
OnePulsOutputTimerHdlr.Init.Period = 400;
OnePulsOutputTimerHdlr.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_OnePulse_Init(&OnePulsOutputTimerHdlr, TIM_OPMODE_SINGLE);
 
/* Timer PWM2 Mode configuration: Channel 1 */
sConfigOC.OCMode = TIM_OCMODE_PWM2;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.Pulse = 1;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
HAL_TIM_PWM_ConfigChannel(&OnePulsOutputTimerHdlr, &sConfigOC,  TIM_CHANNEL_1);
 
/* Initialize master-slave mode. */
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC1;
HAL_TIMEx_MasterConfigSynchronization(&OnePulsOutputTimerHdlr,&sMasterConfig);

Having also MSP init prepared in such a way:
void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
{
    GPIO_InitTypeDef GPIO_InitStruct;
 
    if (htim->Instance == TIM12)
    {
        /* Enable the TIM12 clock */
        __TIM12_CLK_ENABLE();
 
        /* Enable GPIO Port channel1 Clock */
        __GPIOB_CLK_ENABLE();
 
        /* TIM12 GPIO Configuration */
        /* PB14  ------> TIM8_CH1  */
        GPIO_InitStruct.Pin = GPIO_PIN_14;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
        GPIO_InitStruct.Alternate = GPIO_AF9_TIM14;
        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    }
}

After I call:

HAL_TIM_OnePulse_Start(&OnePulsOutputTimerHdlr, TIM_CHANNEL_1);

Nothing happens... Any ideas?

ps. Of course OnePulsOutputTimerHdlr is a global variable.

Outcomes