cancel
Showing results for 
Search instead for 
Did you mean: 

Problem blink led ''STM32F4 DISCOVERY''

rs23
Associate II
Posted on April 23, 2016 at 15:35

Hello, I recently purchased the above development board and I am trying to program it. Following the reference manual I was able to write a small program to turn some LEDs, the problem is that once the code is compiled to ''C IDE'' and ''Eclipse'' and after the correct binary upload does not work. Someone more experienced can kindly help me out ?? the code is as follows.

#define RCC (unsigned int*) (0x40023830) //indirizzo base RCC ''Reset and Clock Control'' 0x40023800 + offset 0x30 per il bus AHB1
#define AHB1_ENR (unsigned int) (1<<3) //abilito il clock sul bus AHB1 per i pin GPIOD
#define ADDRESS_GPIOD (unsigned int) (0x40020C00) //registro base per i pin GPIOD
#define GPIOD_MODER (unsigned int*) (ADDRESS_GPIOD+0x00) //registro per la modalita I/O offset 0x00
#define GPIOD_OUT (unsigned int) (1<<30) 
#define GPIOD_OTYPER (unsigned int*) (ADDRESS_GPIOD+0x04) //registro per il tipo di I/0 offset 0x04
#define GPIOD_OSPEEDR (unsigned int*) (ADDRESS_GPIOD+0x08) //registro per la velocità I/0 offset 0x08
#define GPIOD_PUPDR (unsigned int*) (ADDRESS_GPIOD+0x0C) //registro Papp o Pulldown I/0 offset 0x0C
#define GPIOD_BSRR (unsigned int*) (ADDRESS_GPIOD+0x14) //registro per il set o il reset dell'I/0 offset 0x18
#define GPIOD12_ON (unsigned int) (1<<15) 
#define GPIOD12_OFF (unsigned int) (1<<28) 
void delays(int num) 
{ 
int count; 
for
(count
=
0
;count<
=
num;count
+
+
){} 
} 
int main(void) 
{ 
unsigned int 
*
REGpointer; 
REGpointer 
=
RCC; 
*
REGpointer |
=
AHB1_ENR; 
REGpointer 
=
GPIOD_MODER; 
*
REGpointer |
=
GPIOD_OUT; 
REGpointer 
=
GPIOD_OTYPER; 
*
REGpointer |
=
0
; 
REGpointer 
=
GPIOD_OSPEEDR; 
*
REGpointer |
=
0
; 
REGpointer 
=
GPIOD_PUPDR; 
*
REGpointer |
=
0
; 
REGpointer 
=
GPIOD_BSRR; 
while
(
1
) 
{ 
*
REGpointer |
=
GPIOD12_ON; 
delays(
1000
); 
*
REGpointer |
=
GPIOD12_OFF; 
delays(
1000
); 
} 
} 

Surely there is something wrong or incomplete. best regards
22 REPLIES 22
rs23
Associate II
Posted on April 24, 2016 at 19:26

it works now, I modified the function, with the type volatile.

#include <stm32f4xx.h>
void
ritardo(
volatile
uint64_t del)
{
volatile
uint32_t i = 0;
while
(i<del){i++;}
}
int
main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
RCC->AHB1ENR; 
// dummy read check in errata.
GPIOD->MODER |= (1<<24 | 1 << 26 | 1<<28 | 1<<30);
while
(1)
{
//volatile uint32_t i = 0;
GPIOD->BSRR = (1<<28 | 1<<29 | 1<<30 | 1<<31);
ritardo(100000);
//while(i<100000){i++;}
//i=0;
GPIOD->BSRR = (1<<12 | 1<<13 | 1<<14 | 1<<15);
//while(i<100000){i++;}
ritardo(100000);
}
}

Radosław
Senior II
Posted on April 24, 2016 at 19:27

Led was blinking but probably to quickly.  Delay besed on variable incrementation is not deterministing, Any operation (interrupt) will cause longer time, is oprimization dependent etc. But this code is only hello word type.

As you see this example use only GPIO.

rs23
Associate II
Posted on April 24, 2016 at 19:32

yes I agree , even if the code is simple i'm happy :D . I'm sorry for my english.