Skip to main content
Graduate
August 7, 2024
Solved

Problem on STM32F407 and 411 Discovery boards with TIM_CHANNEL_ALL

  • August 7, 2024
  • 1 reply
  • 1226 views

Hello all,

it seems that when starting a timer in PWM mode, using TIM_CHANNEL_ALL does not work. Everything works fine as long as I start the channels consecutively, (i.e. TIM_CHANNEL_1, then TIM_CHANNEL_2, etc.) but as soon as I change this to TIM_CHANNEL_ALL, the PWM output stops working. Has anyone else encountered this problem yet or am I doing something wrong?

regards
Herby

    This topic has been closed for replies.
    Best answer by TDK

    You're calling HAL_TIM_PWM_Start with TIM_CHANNEL_ALL?

    TIM_CHANNEL_ALL is not a valid argument for HAL_TIM_PWM_Start, per the source code. They need to be started one at a time.

    /**
     * @brief Starts the PWM signal generation.
     * @PAram htim TIM handle
     * @PAram Channel TIM Channels to be enabled
     * 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
     * @arg TIM_CHANNEL_5: TIM Channel 5 selected
     * @arg TIM_CHANNEL_6: TIM Channel 6 selected
     * @retval HAL status
     */
    HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
    {

     

    1 reply

    TDKAnswer
    Super User
    August 7, 2024

    You're calling HAL_TIM_PWM_Start with TIM_CHANNEL_ALL?

    TIM_CHANNEL_ALL is not a valid argument for HAL_TIM_PWM_Start, per the source code. They need to be started one at a time.

    /**
     * @brief Starts the PWM signal generation.
     * @PAram htim TIM handle
     * @PAram Channel TIM Channels to be enabled
     * 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
     * @arg TIM_CHANNEL_5: TIM Channel 5 selected
     * @arg TIM_CHANNEL_6: TIM Channel 6 selected
     * @retval HAL status
     */
    HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
    {

     

    herbertAuthor
    Graduate
    August 7, 2024

    Thank you, I was wrongly (read carelessly) assuming this works, being lured into the belief by the naming. A closer look into the HAL manual would have revealed the truth ...:face_with_rolling_eyes:

    Herbert

    Super User
    August 7, 2024

    The assert_param would also not be passing here. IF you've implemented USE_FULL_ASSERT, this would have been caught within the error handler. (If it's not implemented it just silently fails.)