Dear friends,
I am working with STM32L152VD. my problem is that after setting system clock to MSI and setting PWM on TIM4 I see that system clock is much lower than expected.
void SetHSICLKToMSI(uint32_t freq,bool div2,bool With_RTC) { /* RCC system reset */ RCC_DeInit(); /* Flash 1 wait state */ FLASH_SetLatency(FLASH_Latency_0); /* Disable Prefetch Buffer */ FLASH_PrefetchBufferCmd(DISABLE); /* Disable 64-bit access */ FLASH_ReadAccess64Cmd(DISABLE); /* Disable FLASH during SLeep */ FLASH_SLEEPPowerDownCmd(ENABLE); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 3 (1.2V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) {} /* To configure the MSI frequency */ RCC_MSIRangeConfig(freq); /* Select MSI as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI); /* Wait till MSI is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x00) {} if (div2) { RCC_HCLKConfig(RCC_SYSCLK_Div2); } RCC_HSICmd(DISABLE); /* Disable HSE clock */ RCC_HSEConfig(RCC_HSE_OFF); /* Disable LSE clock */ if (! With_RTC) RCC_LSEConfig(RCC_LSE_OFF); /* Disable LSI clock */ RCC_LSICmd(DISABLE); }
I use below command but I get 5KHz insted of 32.5Khz !!
#define RCC_MSIRange_0 RCC_ICSCR_MSIRANGE_0 /*!< MSI = 65.536 KHz */ SetHSICLKToMSI(RCC_MSIRange_0,DIV2,RTC);
View all questions in Keil forum