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
Radosław
Senior II
Posted on April 23, 2016 at 23:57

Explein, be more specific.

rs23
Associate II
Posted on April 24, 2016 at 00:23

when you go to reset the registry BSRR Inside the loop  It is not reset and then the LED remains on . The delay does not work

Radosław
Senior II
Posted on April 24, 2016 at 13:45

Delay can be to short, then led blinks with to high frequency. BSRR usage is OK.

rs23
Associate II
Posted on April 24, 2016 at 15:34

as you can see in the picture,the LED is fixed.

I noticed that the new HAL libraries ,make use of an internal timer for the delay .

________________

Attachments :

CAM00561.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hzq4&d=%2Fa%2F0X0000000bQz%2FMbW1j3fRGsaH22OUns.kNzHnQrjrJDLjqz4IZjo1UEY&asPdf=false
Radosław
Senior II
Posted on April 24, 2016 at 15:48

increase delay value to 500000;

rs23
Associate II
Posted on April 24, 2016 at 16:58

I tried increasing the duration of the cycle, but the RESULT is the same . The problem seems to be in delay, maybe I have to use a internal timer

Radosław
Senior II
Posted on April 24, 2016 at 17:12

change delay function in main loop to:

for(volatile uint32_t i =0; i<100000;i++);

rs23
Associate II
Posted on April 24, 2016 at 18:23

I can not understand, with the for loop does not work ,but by changing the code in this way it works .

void

main(

void

){

RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;

RCC->AHB1ENR;

// dummy read check in errata.

GPIOD->MODER = (GPIOD->MODER & ~(GPIO_MODER_MODER12)) | GPIO_MODER_MODER12_0;

while

(1)

{

volatile

uint32_t i = 0;

GPIOD->BSRR = 1<<(12+16);

while

(i<1000000){i++;}

i=0;

GPIOD->BSRR = 1<<(12);

while

(i<1000000){i++;}

}

}

Furthermoreif I addthe same cycle ''WHILE''in a function not work.

Radosław
Senior II
Posted on April 24, 2016 at 18:41

This is clasic optimalisation problem. Sorry for incovinience.

I'm glad that now is working.  Try chainge wile loop of delay to for. loop conter should be defined outside loop(while or for).

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

In the future I will use the timer for delay . The register it seems not reset under the 100000 . In case I would like to create a library for a specific purpose how could I bet directly to the registers without making mistakes ? thanks for the support.