Problem blink led ''STM32F4 DISCOVERY''
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 06:35 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 09:32 AM
EVERYTHING IS WRONG.
Why you dont use cmsis headers (with vendor file). MISING VOLATILE in pointer and delay.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 10:28 AM
hahaha as I imagined !
I am at the beginning and then I would not use the ready-made libraries . you could direct me to the right path :D ?? thanksbest regards- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 11:27 AM
Download Cube for STM32F4.
IN STM32Cube_FW_F4_V1.11.0\Drivers\CMSIS\Device\ST\STM32F4xx\Include you will find header with registers. In \STM32Cube_FW_F4_V1.11.0\Drivers\CMSIS\Include You will find CMSIS packege. Include this to your project and use. ALL yours macro are wrong.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 12:08 PM
ok i had seen something, so I can not edit registers directly with pointers in C ?
many thanks.best regards- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 12:33 PM
Of course you can, but why?
Still using this headers will edit register by pointers, but why you want write what is already written and tested? Plus struct representetion gives you addressing advantages. Code will be more readable. And you will not create address, bit position mistakes.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 12:58 PM
Sure is undoubtedly efficient use the ready-made libraries , but as mentioned I am beginning , and starting from below I much help . How could I change the above code to make it work?
apart the setting of the macro and some errors, something is missing?best regards- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 01:08 PM
I assume that LED is on PA12.
void delay(uint32_t cnt) { for(volatile uint32_t i;i<cnt;i++); } void main(void){ RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; RCC->AHB1ENR; // dummy read check in errata. GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER12)) | GPIO_MODER_MODER12_0; while(1) { GPIOA->BSRR = 1<<12; delay(100); GPIOA->BSRR = 1<<(12+16); delay(100); } }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 01:15 PM
Eclipse have the best proposal engine. ctrl+space shortcut.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-04-23 02:32 PM
the code does not seem to properly reset the register, and then stays on the led
