Skip to main content
Associate
June 6, 2024
Solved

LED Blink - STM32F429I-DISCOVERY TIM1

  • June 6, 2024
  • 3 replies
  • 1563 views
could somebody please help me with this: i am a beginner ,i have done the clock configuration and Timer configuration  for delay and also the GPIO configuration: the LED does blink but instead of 1s it takes like 4s , i have done a lot of research to find out where the problem might be, but found nothing i use STM32F429i discovery by the way . thank you and here is my code :

 

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));
}

 

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    Have the STM32 print out the AHB, and APB clocks.

    Inspect the internal frequencies via PA8 MCO pin on a scope.

    3 replies

    Tesla DeLorean
    Guru
    June 6, 2024

    >> 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 ?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Associate
    June 7, 2024

    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 STM32CubeMX Untitled__ STM32F429ZITx STM32F429I-DISC1 07.06.2024 15_42_38.png

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    June 7, 2024

    Have the STM32 print out the AHB, and APB clocks.

    Inspect the internal frequencies via PA8 MCO pin on a scope.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..