Skip to main content
SVair
Associate II
November 12, 2020
Question

Hi, I am using STM32L010C6 and I'd like to generate a PWM signal on PA0.

  • November 12, 2020
  • 3 replies
  • 2458 views

 I have configured the peripheral with STM0693W000005B931QAC.pngCube, as shown in the picture, but I have no output signal on the pin. I can see the TIM2_CNT is working and the CCR1 contains the coorect value

This topic has been closed for replies.

3 replies

SVair
SVairAuthor
Associate II
November 12, 2020

And the firmware use the instructions:

MX_TIM2_Init();

HAL_TIM_PWM_Start (&htim2, HAL_TIM_ACTIVE_CHANNEL_1);

but nothing happens on the pin. If I simply configure PA0 as a output push-pull it works, sothere are not hardware problems.

TDK
Super User
November 12, 2020

You have an invalid value for the last argument to HAL_TIM_PWM_Start. It should be TIM_CHANNEL_1.

/**
 * @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
 * @retval HAL status
 */
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
{

"If you feel a post has answered your question, please click ""Accept as Solution""."
SVair
SVairAuthor
Associate II
November 12, 2020

Hi, I made the correction you suggested but the result is the same.

I tried to change the setting of PA0 to open drain with pull-up but it still does'nt work and remains low.

Instead loading the PWM Output example for STM32L053 nucleo boards it works very well. I have checked that the configuration made in the example is slightly different from the code generated by MX.

waclawek.jan
Super User
November 13, 2020

Read out and check/post TIM and relevant GPIO registers content.

JW

SVair
SVairAuthor
Associate II
November 16, 2020

Hi, I think I found the bug, the generated code of the PA0 did't comprehend the setting of alternate function, see the code as it was generated:

oid HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(htim->Instance==TIM2)

 {

 /* USER CODE BEGIN TIM2_MspPostInit 0 */

 /* USER CODE END TIM2_MspPostInit 0 */

  __HAL_RCC_GPIOA_CLK_ENABLE();

  /**TIM2 GPIO Configuration

  PA0   ------> TIM2_CH1

  */

  GPIO_InitStruct.Pin = GPIO_PIN_0;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /* USER CODE BEGIN TIM2_MspPostInit 1 */

 /* USER CODE END TIM2_MspPostInit 1 */

 }

}

The raw:

GPIO_InitStruct.Alternate = GPIO_AF2_TIM2;

was missed.

Stefano