/* USER CODE BEGIN 0 */ uint8_t receiveBuffer[BUFFER_UART_LEN]; #define BASE_FREQ 16000000 void runCmdFromUart(void){ uint32_t frequency = 0; uint32_t ARR_reg_val = 0; uint32_t PSC_reg_val = 7; if(receiveBuffer[0] == 'f'){ //frequency frequency += (receiveBuffer[1] - 0x30) *100000; frequency += (receiveBuffer[2] - 0x30) *10000; frequency += (receiveBuffer[3] - 0x30) *1000; frequency += (receiveBuffer[4] - 0x30) *100; frequency += (receiveBuffer[5] - 0x30) *10; frequency += receiveBuffer[6] - 0x30; if(frequency > 10000) PSC_reg_val = 0; else if(frequency > 100) PSC_reg_val = 7; else PSC_reg_val = 4095; ARR_reg_val = (BASE_FREQ/(PSC_reg_val+1))/frequency; LL_TIM_WriteReg(TIM1, PSC, PSC_reg_val); LL_TIM_WriteReg(TIM1, ARR, ARR_reg_val); LL_TIM_OC_SetCompareCH4(TIM1, (ARR_reg_val/2)); //50% PWM, 100 kHz } } /* USER CODE END 0 */