This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

My first STM32 code - please criticize me

I have just wrote my first code on STM32 using Keil software - blinking LED. It combines a fragments from different sources so it can look really horrible. Please criticize me so I can learn how to write proper code and don't learn stupid habits.

Thank you!

#include "stm32f30x.h"

void SysTick_Handler(void);
void TimingDelay_Decrement(void);
void Delay(__IO uint32_t nTime);

static __IO uint32_t TimingDelay;

int main(void)
{
  RCC->AHBENR  |=  ((1UL << 21) );                  // Enable GPIOE clock??
  GPIOE->MODER |= (1 << 2*8);                       // PIN 9 as output

//GPIOE->BSRR = 1 << 9;                             // LED ON
//GPIOE->BSRR = 1 << 9 << 16;                       // LED OFF
//GPIOE->BRR = 1 << 9;                              // LED OFF

    if (SysTick_Config(SystemCoreClock / 1000))
    {
    /* Capture error */
    while (1);
  }

    while(1)
    {
        GPIOE->BSRR = 1 << 8;
        Delay(50);
        GPIOE->BRR = 1 << 8;
        Delay(50);
    }
}

void SysTick_Handler(void)
{
  TimingDelay_Decrement();
}

void Delay(__IO uint32_t nTime)
{
  TimingDelay = nTime;

  while(TimingDelay != 0);
}

void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }

}

Why I have to enable GPIOE clock? And what's the difference between "1UL << 21" and "1 << 21"?

0