2021-04-07 06:17 PM
I generate the STM32 Project and define each PIN.
PIN1:GPIO_Output
PIN4:TIM2_CH1
PIN7:SYS_SWDIO
PIN8:SYS_SWCLK
And I let a code below run but it do not reach "while".
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET);
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_Delay(10);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
I run and investigate the code in step, and the code jumps to "Reset_Handler:" at the line "__HAL_TIM_ENABLE(htim);" in the API "HAL_TIM_PWM_Start".
The code repeats execution and reset. The GPIO pin is as above.
If I comment out "HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);" in the above code, it reach "while" successfully. The GPIO pin is as follows.
I set my project as default except for each PIN and TIM2. I set TIM2 Channel1 to "PWM Generation CH1".
Do I miss any necessary setting?