STM32 CooCox LED blinkt nicht

Gast #3089586
Lesenswert?

Hallo,
ich bin hier gerade kurz vorm durchdrehen!!! Ich möchte gerade eine LED 
Blinken lassen in COOCOX dafür habe ich einen Code geschrieben, der auch 
funktioniert:
1
#include "stm32f4xx_conf.h"
2
#include "stm32f4xx.h"
3
#include "stm32f4xx_rcc.h"
4
#include "misc.h"
5
#include "stm32f4xx_gpio.h"
6
#include "stm32f4xx_spi.h"
7

8

9
uint32_t Ticks=0;
10

11

12
void SysTick_Handler(void){
13

14
  if (Ticks !=0)
15
    Ticks--;
16

17
  }
18

19
void Delay(uint16_t cycles ){
20

21
  Ticks = cycles;
22
  while (Ticks);
23
}
24

25

26

27
void GPIO_Conf(){
28

29
   GPIO_InitTypeDef GPIO_InitStructure;
30
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
31
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
32
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
33
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
34
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
35
    GPIO_Init(GPIOA, &GPIO_InitStructure);
36

37
}
38

39
int main(void)
40
{
41

42
    SystemInit();
43
    SysTick_Config(SystemCoreClock/ 1000);
44
    //GPIO_Conf();
45
    GPIO_InitTypeDef GPIO_InitStructure;
46
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
47
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
48
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
49
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
50
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
51
    GPIO_Init(GPIOA, &GPIO_InitStructure);
52

53
    while(1)
54
    {
55
        GPIO_WriteBit(GPIOA, GPIO_Pin_8, RESET);
56
        Delay(500);
57
        GPIO_WriteBit(GPIOA, GPIO_Pin_8, SET);
58
        Delay(500);
59

60
    }
61
}



Das komische ist jetzt, dass wenn ich die Initialisierung vom GPIO in 
eine Funktion auslagere, denn funktioniert es auf einmal nicht mehr...


1
#include "stm32f4xx_conf.h"
2
#include "stm32f4xx.h"
3
#include "stm32f4xx_rcc.h"
4
#include "misc.h"
5
#include "stm32f4xx_gpio.h"
6
#include "stm32f4xx_spi.h"
7

8

9
uint32_t Ticks=0;
10

11

12
void SysTick_Handler(void){
13

14
  if (Ticks !=0)
15
    Ticks--;
16

17
  }
18

19
void Delay(uint16_t cycles ){
20

21
  Ticks = cycles;
22
  while (Ticks);
23
}
24

25

26

27
void GPIO_Conf(){
28

29
    GPIO_InitTypeDef GPIO_InitStructure;
30
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
31
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
32
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
33
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
34
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
35
    GPIO_Init(GPIOA, &GPIO_InitStructure);
36

37
}
38

39
int main(void)
40
{
41

42
   SystemInit();
43
   SysTick_Config(SystemCoreClock/ 1000);
44
   GPIO_Conf();
45
   //GPIO_InitTypeDef GPIO_InitStructure;
46
   //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
47
    //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
48
    //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
49
    //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
50
    //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
51
    //GPIO_Init(GPIOA, &GPIO_InitStructure);
52

53
    while(1)
54
    {
55
        GPIO_WriteBit(GPIOA, GPIO_Pin_8, RESET);
56
        Delay(500);
57
        GPIO_WriteBit(GPIOA, GPIO_Pin_8, SET);
58
        Delay(500);
59

60
    }
61
}


Woran kann das liegen?
#3089842
Lesenswert?

GPIO_InitTypeDef GPIO_InitStructure ist eine lokale Variable innerhalb 
der Funktion GPIO_Conf(). Verlässt Du GPIO_Conf() wird GPIO_InitTypeDef 
GPIO_InitStructure wieder gelöscht. An GPIO_Init() übergibst du nur 
einen Zeiger.

Lege GPIO_InitTypeDef GPIO_InitStructure als globale Variable oder als 
dynamische Variable an.

Grüsse
Gast #3089851
Lesenswert?

Markus M. schrieb:
> GPIO_InitTypeDef GPIO_InitStructure ist eine lokale Variable innerhalb
> der Funktion GPIO_Conf(). Verlässt Du GPIO_Conf() wird GPIO_InitTypeDef
> GPIO_InitStructure wieder gelöscht. An GPIO_Init() übergibst du nur
> einen Zeiger.

Nur beim Verlassen von GPIO_Init() hat die Struktur ihre Schuldigkeit 
getan und wird nicht mehr gebraucht, das kann es also auch nicht sein.
Schonmal versucht im Debugger dadurch zu steppen?
Gast #3089885
Lesenswert?

Jo habe ich. GPIO_init wird aufgerufen und er landet auch in der 
Funktion in der stm32f4xx_gpio.c . Danach schaltet er den Pin 
abwechselnd High und Low.
Dass Ticks nicht Volatile ist, wird nicht der Fehler sein. Delay 
funktioniert ja.

Habe nochmal weiter herumgespielt. Es reicht schon wenn ich die 
gpioinitstructure nochmal in der Main deklariere und die gpio init 
nochmal außer Main aufrufe.
Gast #3089899
Lesenswert?

ich würde vermuten es liegt daran das du den GPIO_Mode nicht setzt. 
Damit wird wird der IO pin nicht definiert als Ausgang gesetzt, je 
nachdem was da im Speicher steht wo die Struktur landet.
Vor dem Setzen der Parameter sollte man auch void 
GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
aufrufen .
Gast #3089924
Lesenswert?

Jojo S. schrieb:
> ich würde vermuten es liegt daran das du den GPIO_Mode nicht setzt.
> Damit wird wird der IO pin nicht definiert als Ausgang gesetzt, je
> nachdem was da im Speicher steht wo die Struktur landet.
> Vor dem Setzen der Parameter sollte man auch void
> GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
> aufrufen .

alles klar... ich schäme mich jetzt mal und sag nichts mehr ^^

dabei hatte ich das ürsprünglich auch gemacht und irgendwann ist die 
zeile auf der strecke gblieben...


danke für die hilfe

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren