Skip to main content
Visitor II
October 9, 2024
Question

LED won't blink (Timer with PWM)

  • October 9, 2024
  • 2 replies
  • 624 views

Hi could somebody please help me with this: i am a beginner ,i have set the Timer_init and Gpio_init with bare Metal 
i'm working in STM32F429ZIT and i'm aiming to control GPIO pins PG13 and PG14 using the PWM channels with two channel each for every LED 
but the LEDs on PG13 and PG14 aren’t blinking
i debugged the Leds, they are working correctly but when it comes to use PWM nothing appears 
here's the code :

 

#include "stm32f4xx.h"

void GPIO_Config(void);
void TIM_Config(void);

int main(void)
{
GPIO_Config();
TIM_Config();

while (1)
{

}
}

void GPIO_Config(void)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOGEN;

GPIOG->MODER &= ~((0x3 << (13 * 2)) | (0x3 << (14 * 2)));
GPIOG->MODER |= ((0x1 << (13 * 2)) | (0x1 << (14 * 2)));

GPIOG->AFR[1] |= ((0x2 << (4 * (13 - 8))) | (0x2 << (4 * (14 - 8))));
}

void TIM_Config(void)
{
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;

TIM4->PSC = 8400 - 1;
TIM4->ARR = 1000 - 1;

TIM4->CCMR1 |= (0x6 << 4);
TIM4->CCMR1 |= (1 << 3);
TIM4->CCER |= TIM_CCER_CC1E;
TIM4->CCR1 = 300;

TIM4->CCMR1 |= (0x6 << 12);
TIM4->CCMR1 |= (1 << 11);
TIM4->CCER |= TIM_CCER_CC2E;
TIM4->CCR2 = 700;

TIM4->CR1 |= TIM_CR1_CEN;
}

 

 

    This topic has been closed for replies.

    2 replies

    Super User
    October 9, 2024

    PG13 and PG14 are not TIM4_CH1 and TIM4_CH2.

    waclawekjan_0-1728481411347.png

     

    JW

    Super User
    October 9, 2024

    Welcome to the forum.

    Please see the Posting Tips for how to properly post source code:

    https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

     


    @firassaabd wrote:

     i am a beginner


    Just a beginner with STM32, or a beginner with microcontrollers in general? Or with programming in general?

     


    @firassaabd wrote:

    i have set the Timer_init and Gpio_init with bare Metal 


    Seems a bit advanced to start with.

    Before doing that, have you got an LED blinking using just simple loop delays?

    Have you tried configuring this with CubeMX - even if only to get a known-working point of reference?