title: No PWM Output On STM32
body: <p>No PWM output for a timer on a stm32f4discovery board whatsoever. Straight line on oscilloscope.</p>
  <p>Note: code was generated in Stm32cubeide except the &quot;user code&quot; part</p>
  <p><strong>Main Function</strong></p>
  <pre><code>int main(void)
  {
    HAL_Init();
    SystemClock_Config();
  
    MX_GPIO_Init();
    MX_TIM2_Init();
  
    /* USER CODE BEGIN 2 */
    HAL_TIM_PWM_Start(&amp;htim2,TIM_CHANNEL_1);
    /* USER CODE END 2 */
    while (1)
    {
    }
  }
  </code></pre>
  <p><strong>Initialization of TIM2</strong></p>
  <pre><code>static void MX_TIM2_Init(void) 
  {
    TIM_ClockConfigTypeDef sClockSourceConfig = {0};
    TIM_MasterConfigTypeDef sMasterConfig = {0};
    TIM_OC_InitTypeDef sConfigOC = {0};
  
    htim2.Instance = TIM2;
    htim2.Init.Prescaler = 0;
    htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim2.Init.Period = 100;
    htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
    if (HAL_TIM_Base_Init(&amp;htim2) != HAL_OK)
    {
      Error_Handler();
    }
    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
    if (HAL_TIM_ConfigClockSource(&amp;htim2, &amp;sClockSourceConfig) != HAL_OK)
    {
      Error_Handler();
    }
    if (HAL_TIM_PWM_Init(&amp;htim2) != HAL_OK)
    {
      Error_Handler();
    }
    sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
    sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
    if (HAL_TIMEx_MasterConfigSynchronization(&amp;htim2, &amp;sMasterConfig) != HAL_OK)
    {
      Error_Handler();
    }
    sConfigOC.OCMode = TIM_OCMODE_PWM1;
    sConfigOC.Pulse = 0;
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
    if (HAL_TIM_PWM_ConfigChannel(&amp;htim2, &amp;sConfigOC, TIM_CHANNEL_1) != HAL_OK)
    {
      Error_Handler();
    }
    HAL_TIM_MspPostInit(&amp;htim2);
  
  }
  
  </code></pre>
  <p>I've also tried instead of <code>HAL_TIM_PWM_Start</code>, <code>HAL_TIM_PWM_Start_IT</code>,and <code>HAL_TIM_PWM_Start_DMA</code></p>
  <p>Thanks</p>