AnsweredAssumed Answered

STM32F3xx device driver / lib lack

Question asked by o gaste on May 23, 2017
Latest reply on May 24, 2017 by o gaste

I dont know I must be wrong but I didn't find function call to change the dutycycle of a pwm

so I wrote this and I added it to stm32F3xx_hal_tim.c

  * @brief  Set the PWM DutyCycle.
  * @param  htim: TIM handle
  * @param  Channel: TIM Channels to setted
  *          This parameter can be one of the following values:
  *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
  *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
  *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
  *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
    * @param  v: value of dutycycle
  * @retval HAL status
HAL_StatusTypeDef HAL_TIM_PWM_SetDutyCyle(TIM_HandleTypeDef *htim, uint32_t Channel, float v)

  /* Check the parameters */
    if(v<0 || v>1)
        return HAL_ERROR;
  htim->State = HAL_TIM_STATE_BUSY;

  switch (Channel)
    case TIM_CHANNEL_1:
      /* Set the CCR */
      htim->Instance->CCR1 = htim->Instance->ARR*v;

    case TIM_CHANNEL_2:
      /* Set the CCR */
      htim->Instance->CCR2 = htim->Instance->ARR*v;

    case TIM_CHANNEL_3:
      /* Set the CCR */
      htim->Instance->CCR3 = htim->Instance->ARR*v;

    case TIM_CHANNEL_4:
            /* Set the CCR */
      htim->Instance->CCR4 = htim->Instance->ARR*v;

  htim->State = HAL_TIM_STATE_READY;
  return HAL_OK;

and the function prototype in the include stm32f3xx_hal_tim.h in the TIM_Exported_Functions_Group3 group


** @addtogroup TIM_Exported_Functions_Group3
 * @{
/* Timer PWM functions *********************************************************/
HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim);
HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim);
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim);
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim);
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIM_PWM_SetDutyCyle(TIM_HandleTypeDef *htim, uint32_t Channel, float v);
/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
/* Non-Blocking mode: DMA */
HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  * @}

I dont know if I'm wrong to post that here or even if it will interest someone but if it helps I will be happy

good works everyone