STM32F103C8T6
Timers->TIM1
Clock Source -> Intemal Clock   
Channel1  -> PWM Generation CH1  输出脚是 PA8
往中下方看
Prescaler(PSC-16 bits value) -> 8-1    //8M的
Counter Period (AutoReload R....)   -> 500-1
PWM Generation Channel1 下面的 Mode -> PWM mode 2
CH Polarity ->High 
保存生成代码
int main(void) {
	uint8_t dir = 1; //方向
	uint16_t val = 250;  //ccr 的值
//在 MX_TIM1_Init(); 下面
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
	while (1) {
		if (dir == 1) {
			val++;
		} else {
			val--;
		}
		if (val >= 300) {
			dir = 0;
		}
		if (val == 0) {
			dir = 1;
		}

		__HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,val);
		HAL_Delay(10);
		/* USER CODE END WHILE */

		/* USER CODE BEGIN 3 */
	}


