2019-09-13 02:43 AM
Hi,
I have generated the code for PWM generation using STM32 CubeMX and it is working fine on B-l072Z-lrwan1.
But when I was trying to integrate same code with the existing Ping Pong example, I was not getting any PWM signal on respective pin. I have also configure the pin according to timer and channel with the help of datasheet and also check the alternate function for the pin.
I have tried different Timers but I am not getting any PWM signal at output.
Can anyone tell me, why this is happening?
2019-09-13 02:47 AM
2019-09-13 03:02 AM
Rest of all code is executing well except PWM.
I am generating PWM on PB5 so Green LED Should be dim, but it remains off all the time.
2019-09-13 03:20 AM
Read out and check/post content of relevant GPIO and timer registers.
JW
2019-09-13 04:43 AM
Registers configuration is right because the same configuration individually works fine but not with Ping Pong code.
I can't understand what is the problem ?
Below is the way I configured the registers and pin for PWM.
void PWM_LED_Init(Led_TypeDef Led)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable the GPIO_LED Clock */
LEDx_GPIO_CLK_ENABLE( Led );
/* Configure the GPIO_LED pin */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_TIM3;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
void MX_TIM2_Init(int8_t value)
{
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim2.Instance = TIM3;
htim2.Init.Prescaler = 4;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 100;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = value;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
}
2019-09-13 05:19 AM
I don't use Cube.
Can you please read out and check/post the content of the relevant GPIO and TIM registers?
JW
2019-09-13 05:22 AM
2019-09-13 05:51 AM
I am using TIM3 only.
2019-09-13 08:41 AM
2019-09-13 10:01 PM
This is given in datasheet.