i tried to configure clock by writing code in its appropriate registers...
following is the clock configuration function
void SystemClockConfig(void){
#define PLLN 16
//using external clock source
RCC->CR |= RCC_CR_HSEON;
while(!(RCC->CR & RCC_CR_HSERDY));
//enabling power interface
RCC->APBENR1 |= RCC_APBENR1_PWREN;
//configuring voltage regulator to default 01
PWR->CR1 |= (0x1UL << PWR_CR1_VOS_Pos);
PWR->CR1 &= ~(0x2UL << PWR_CR1_VOS_Pos);//
//configure flash prefetch and latency
FLASH->ACR |= (FLASH_ACR_ICEN | FLASH_ACR_PRFTEN | FLASH_ACR_LATENCY_1);
//configuring prescalers for main clock and peripheral clocks
RCC->CFGR |= (RCC_CFGR_HPRE_0 | RCC_CFGR_PPRE_0);
//configure main PLL; PLLM, PLLN, PLLR
RCC->PLLCFGR |= ((PLLN<<8) | (RCC_PLLCFGR_PLLSRC));//
RCC->PLLCFGR &= ~RCC_PLLCFGR_PLLM;
RCC->PLLCFGR |= RCC_PLLCFGR_PLLREN;
RCC->PLLCFGR |= RCC_PLLCFGR_PLLR_0;
//enable PLL
RCC->CR |= RCC_CR_PLLON;
while(!(RCC->CR & RCC_CR_PLLRDY));
//set the clock source
RCC->CFGR |= RCC_CFGR_SW_1;
// while(!(RCC->CFGR & RCC_CFGR_SWS_1));
while(((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_1));
}
furthermore,
when the Xtal frequency is greyed out as <undefined> in the dialog Options for target - Target tab. so I am unable to set the clock frequency to 64mhz
in the main.c code when I try to include this clock configuration, it fails to make any changes to the code and the simple led blink program fails to execute after flashing
following is my main.c file
#include "stm32g071xx.h"
#include "RCC_CLock_Config.h"
void Timer6Config(void){
//enable Timer 6
RCC->APBENR1 |= (1<<4);
//setting prescaler
//64Mhz/64= 1Mhz -> 1us
TIM6->PSC |= 64-1;//The counter clock frequency CK_CNT is equal to fCK_PSC / (PSC[15:0] + 1).
TIM6->ARR |= 0xffff;
//enabling timer and waiting for flag to set
TIM6->CR1 |= (1<<0);//enable the counter
while(!(TIM6->SR& (1<<0)));
}
void Delay_us(uint16_t time_in_us){
TIM6->CNT = 0;
while(TIM6->CNT<time_in_us);
}
void Delay_ms(uint16_t time_in_ms){
TIM6->CNT=0;
for(uint16_t i=0; i<time_in_ms; i++){
Delay_us(1000);
}
}
//__attribute__((optimize("-O0")))
void Delay(uint32_t time){
while(time--);
}
void GPIO_Config(void){
RCC->IOPENR |= (1<<2);
GPIOC->MODER &= ~(1<<25);
}
int main(void){
//SystemClockConfig();
Timer6Config();
GPIO_Config();
while(1){
GPIOC->BSRR |= (1<<12);
Delay_ms(500);
GPIOC->BSRR |= (1<<12)<<16;
Delay_ms(500);
}
}
I am a beginner,
any help would be appreciated.....