2020-11-12 02:19 AM
I have configured the peripheral with STMCube, 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
2020-11-12 02:27 AM
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.
2020-11-12 06:37 AM
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)
{
2020-11-12 06:57 AM
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.
2020-11-12 05:22 PM
Read out and check/post TIM and relevant GPIO registers content.
JW
2020-11-15 11:44 PM
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