Program that generates a 1KHz signal 50% duty cycle in pin A8 using timer TIM1 channel 1, since the PWM depends on the TIM timer, we need to configured the signal period which is basically the timer timeout, and then and this is important the duty cycle, duty cycles a configured in the Timer channels, for this case we are using the channel 1 of timer 1, and a DC of 50%

#include "bsp.h"

TIM_HandleTypeDef TimHandle;    /*TIM control structure*/
TIM_OC_InitTypeDef sConfig;     /*PWM channel structure*/

int main( void )
{
    HAL_Init();  /*Init library*/

    /* Config TIM1 to generate a signal with a 1ms/1KHz period*/
    TimHandle.Instance       = TIM1;
    TimHandle.Init.Prescaler = 10;
    TimHandle.Init.Period    = 1600;
    TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
    HAL_TIM_PWM_Init(&TimHandle);

    /* Config PWM channel with high polarity at 50% duty cycle */
    sConfig.OCMode     = TIM_OCMODE_PWM1;
    sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfig.OCFastMode = TIM_OCFAST_DISABLE;
    sConfig.Pulse = TimHandle.Init.Period / 2;
    HAL_TIM_PWM_ConfigChannel( &TimHandle, &sConfig, TIM_CHANNEL_1 );
    
    /*start the pwm signal on pin C8*/
    HAL_TIM_PWM_Start( &TimHandle, TIM_CHANNEL_1 );

    while(1)
    {
       
    }
}

msps.c

/*function called by HAL_TIM_PWM_Init to configure the slected pins as PWM outputs*/
void HAL_TIM_PWM_MspInit( TIM_HandleTypeDef *htim )
{
    GPIO_InitTypeDef   GPIO_InitStruct;

    __TIM1_CLK_ENABLE();  /*eneable clock in TIM1*/
    __GPIOC_CLK_ENABLE(); /*eneable clock on port C*/

    /*config pin C8 in altern mode 2 as TIM1_CH1*/
    GPIO_InitStruct.Pin = GPIO_PIN_8; 
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
    HAL_GPIO_Init( GPIOC, &GPIO_InitStruct );
}