AnsweredAssumed Answered

So painful to get a LED to blink on the STM32 Discovery

Question asked by jack on Mar 8, 2011
Latest reply on Apr 18, 2011 by Clive One

Wow, I can't believe how painful it is to get an LED to blink on the Discovery board.
I am using keil UV4 32k limited edition. I can download and run the demo project just fine. But when I compile and debug/download teh following I got a dead board.

Any input is greatly appreciated!

#include "stm32f10x.h"          //ST standard periph file: DPAL layer = "Device Peripheral Access Layer"
                                //This header must come before the rest of the headers.   
#include "system_stm32f10x.h"   //ST standard: For SystemCoreClock and SystemInit
                                                                                
volatile uint32_t msTicks;                       // timeTicks counter used by SysTick Handler in stm32f10x_it.c JRH

__INLINE static void Delay (uint32_t dlyTicks)
{
  uint32_t curTicks = msTicks;                 

  while ((msTicks - curTicks) < dlyTicks);
}

__INLINE static void LED_Init(void)              //Configure the LED(s) PC9 = Green LED3 And PC8 = Blue LED4 JRH
{
  RCC->APB1ENR |= 0x10000000;                   //Power interface reset
  RCC->APB2ENR |= 0x10;                   //Enable GPIOC clock                
  GPIOC->CRH = 0x10;//GPIO_CRH_MODE9_1; //0x10 configure for output and speed 2Mhz JRH
}

__INLINE static void LED_On (uint32_t led)
{
  GPIOC->BSRR = 1<<9;//GPIO_ODR_ODR9;                 // Turn On  LED
}

__INLINE static void LED_Off (uint32_t led)
{                                             
  GPIOC->BRR = 1<<9;//GPIO_ODR_ODR9;                 // Turn Off LED
}

int main (void)
{
  if (SysTick_Config (SystemCoreClock / 1000))
  { /* Setup SysTick for 1 msec interrupts */
    ;                                            /* Handle Error */
    while (1);
  }
 
  LED_Init();                                  /* configure the LEDs */                           
 
   while(1)
  {
    LED_On (0x100);                              /* Turn  on the LED   */
    Delay (200);                                 /* delay  200 Msec    */
    LED_Off (0x100);                             /* Turn off the LED   */
    Delay (800);                                 /* delay  800 Msec    */
  }
}

Outcomes