2024-06-06 10:00 AM - last edited on 2024-06-06 11:34 AM by Tesla DeLorean
void Clock_Config(void)
{
RCC->CR |=(RCC_CR_HSEON);
while(!((RCC->CR) & (RCC_CR_HSERDY)));
RCC->APB1ENR |= (1<<28);
PWR->CR |= 1<<14;
FLASH->ACR |= (1<<8)|(1<<9)|(1<<10)|(2<<0);
RCC->CFGR|=RCC_CFGR_HPRE_DIV1;
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
RCC->PLLCFGR |= (0<<16)|(4<<0)|(180<<6)|(RCC_PLLCFGR_PLLSRC_HSE);
RCC->CR |=(RCC_CR_PLLON);
while(!((RCC->CR) & (RCC_CR_PLLRDY)));
RCC->CFGR |=(RCC_CFGR_SW_PLL);
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL);
}
void Timer_Config(void)
{
RCC->APB2ENR|=(1<<0);
TIM1->PSC=180-1;
TIM1->ARR=0xffff;
TIM1->CR1|=1<<0;
while (!((TIM1->SR)& (1<<0)));
}
void Delay_µs(int µs)
{
TIM1->CNT=0;
while (TIM1->CNT<µs);
}
void Delay_ms (int ms)
{
for (uint16_t counter=0;counter<ms;counter++)
{
Delay_µs(1000);
}
}
void GPIOxConfig(void)
{
RCC->AHB1ENR |=(1<<6);
GPIOG->MODER|=(1<<26)|(1<<28);
GPIOG->OTYPER&=~(0<<13)|~(1<<14);
GPIOG->OSPEEDR |=(2<<26) | (2<<28) ;
GPIOG->PUPDR&=~((1<<26) | (1<<28));
}
Solved! Go to Solution.
2024-06-07 07:33 AM
Have the STM32 print out the AHB, and APB clocks.
Inspect the internal frequencies via PA8 MCO pin on a scope.
2024-06-06 11:31 AM - edited 2024-06-06 11:36 AM
>> i am a beginner
Ok, but this communicates no information about what you do know, or if you're just 14. Register level coding does imply some reading / interpretation of the technical manual.
TIM1 / APB2 is likely not clocking at 180 MHz, but a fraction of that. So perhaps 90 or 45 MHz ? Check the divider settings and Clock Tree, in this context.
Also Toggling will further half the frequency (double the period) of a blinking LED
APB1 DIV4 is 45 MHz, TIMCLK= APB1*2, so 90 MHz
So 1000 delay is 2 seconds, LED ON at 4 second interval ?
2024-06-07 06:49 AM
i checked the Clock tree, the APB2 bus is working on 180 Mhz , and in the Timer configuration in PSC register i wrote 180-1, that means 180Mhz divided by 180 is 1Mhz which is 1 tick in on microsecond
2024-06-07 07:33 AM
Have the STM32 print out the AHB, and APB clocks.
Inspect the internal frequencies via PA8 MCO pin on a scope.