AnsweredAssumed Answered

STM32F205 TIM1 Problem

Question asked by hebbeler.tim on Aug 22, 2015
Latest reply on Sep 3, 2015 by Nesrine M
Hello,

I have a problem with my initalisiation code for an STM32F205RB Microcontroller.
I want to use four PWM Output Channels on the TIM1, but only the Channel 4 work properly. The other channels do not seem to be properly connected.
E.g the channel 3 is switching but only with an peak-to-peak of 0.3 V. I think the PA10 is not set as Pull-Push, more like an high impendance state.

When I set the Pins PA8 to PA11 as an GPIO then they work correctly.

I use the STM32CubeF2 and the Microcontroller work with 3.3 V and 100 MHz.

I hope anyone can help me or can reproduce that behavior.

001.#include "stm32f2xx_hal.h"
002. 
003.TIM_HandleTypeDef htim1;
004. 
005.uint32_t foo=0;
006. 
007.static void SystemClock_Config(void)
008.{
009. 
010.    RCC_ClkInitTypeDef RCC_ClkInitStruct;
011.    RCC_OscInitTypeDef RCC_OscInitStruct;
012. 
013.    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
014.    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
015.    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
016.    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
017.    RCC_OscInitStruct.PLL.PLLM = 4;
018.    RCC_OscInitStruct.PLL.PLLN = 200;
019.    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
020.    RCC_OscInitStruct.PLL.PLLQ = 4;
021.    HAL_RCC_OscConfig(&RCC_OscInitStruct);
022. 
023.    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
024.                                  |RCC_CLOCKTYPE_PCLK2;
025.    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
026.    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
027.    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
028.    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
029.    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
030. 
031. 
032.    __GPIOC_CLK_ENABLE();
033.    __GPIOH_CLK_ENABLE();
034.    __GPIOA_CLK_ENABLE();
035.    __GPIOB_CLK_ENABLE();
036.    __GPIOD_CLK_ENABLE();
037. 
038. 
039.}
040. 
041.int main()
042.{
043.    HAL_Init();
044. 
045.    /* Configure the system clock */
046.    SystemClock_Config();
047. 
048. 
049.    TIM_OC_InitTypeDef sConfigOC;
050. 
051. 
052.    htim1.Instance = TIM1;
053.    htim1.Init.Prescaler = 0;
054.    htim1.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED1;
055.    htim1.Init.Period = 4000;
056.    htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV2;
057.    htim1.Init.RepetitionCounter = 0;
058.    HAL_TIM_PWM_Init(&htim1);
059. 
060.    sConfigOC.OCMode = TIM_OCMODE_PWM1;
061.    sConfigOC.Pulse = 2000;
062.    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
063.    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
064.    sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
065.    HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1);
066.    HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2);
067.    HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3);
068.    HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_4);
069. 
070.    HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);
071.    HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2);
072.    HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_3);
073.    HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4);
074. 
075.    while(1)
076.    {
077.        foo++;
078.    }
079. 
080. 
081.}
082. 
083.void SysTick_Handler()
084.{
085. 
086.}
087. 
088. 
089.void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_base)
090.{
091. 
092.    GPIO_InitTypeDef GPIO_InitStruct;
093.    if(htim_base->Instance==TIM1)
094.    {
095.        /* Peripheral clock enable */
096.        __TIM1_CLK_ENABLE();
097. 
098.        /**TIM1 GPIO Configuration
099.        PA8     ------> TIM1_CH1
100.        PA9     ------> TIM1_CH2
101.        PA10     ------> TIM1_CH3
102.        PA11     ------> TIM1_CH4
103.        */
104.        GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11;
105.        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
106.        GPIO_InitStruct.Pull = GPIO_NOPULL;
107.        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
108.        GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
109.        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
110. 
111.    }
112. 
113.}

Outcomes