STM32 Ride7 Einstieg

OP #2488115
Lesenswert?

Hallo,

ich bin nun schon ewig im Internet mit Google etc. unterwegs und finde 
aber keine brauchbaren Howto´s in deutsch oder englisch, die einem den 
Einstieg in die Programmierung der STM32F Prozessoren mithilfe von Ride 
geben. Könnt ihr mir da welche Tipps geben ?
Gast #2488424
Lesenswert?

Weißt Du, ich möchte es nur mal schaffen, einen einzigen Ausgang, an dem 
eine der 4 Leds angschlossen sind, zu initialisieren und zum Leuchten zu 
bringen. Mehr sollte das erste, selbstgeschriebene Programm nicht 
können. Habe es mittlerweile geschafft, die Demosoftware Beispiele von 
ST draufzuspielen und zu testen.
OP #2488708
Lesenswert?

Ok,

dass ich die LEDS zum leuchten bringen kann, eine nach der anderen habe 
ich mittlerweile geschafft. Jetzt möchte ich, dass ich eine einzelne LED 
mit dem Taster, der an PB9 hängt, ein und ausschalten kann. Wie geht man 
da sinnvollerweise vor. Habe mal den Taster so initialisiert:
1
   //Tasterinitialisierung
2
   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;   
3
   //GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
4
   //GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13;
5
   GPIO_Init(GPIOB, &GPIO_InitStructure);
6
   //GPIO_Init(GPIOC, &GPIO_InitStructure);
7

8
   // LED Ports definieren
9
   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_7 |   GPIO_Pin_13;   
10
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
11
   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
12

13
   GPIO_Init(GPIOD, &GPIO_InitStructure);
14

15
    while(1)
16
        
17
    {
18

19
      if (ReadValue == 1)
20
          
21
            GPIO_SetBits(GPIOD, GPIO_Pin_7); //, GPIO_SetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);


Ist dieser Ansatz zu gebrauchen, oder eher nicht ?
#2488807
Lesenswert?

1
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // GPIO A Takt freigeben
2
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // GPIO B Takt freigeben
3
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); // GPIO C Takt freigeben
4
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); // GPIO D Takt freigeben
5

6
// ... usw.
OP #2488845
Lesenswert?

1
void RCC_Configuration(void)
2
{     
3
   // The maximum frequency of the AHB and the APB2 domains is 72 MHz
4
   // The maximum allowed frequency of the APB1 domain is 36 MHz
5

6
   ErrorStatus       HSEStartUpStatus;
7
   
8
   RCC_DeInit();                                              // RCC system reset(for debug purpose)
9
   
10
   
11
   RCC_HSEConfig(RCC_HSE_ON);                                 // Enable HSE
12
   HSEStartUpStatus = RCC_WaitForHSEStartUp();                // Wait till HSE is ready
13

14
   if(HSEStartUpStatus == SUCCESS)
15
   {    
16
      FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);   // Enable Prefetch Buffer    
17
      FLASH_SetLatency(FLASH_Latency_2);                      // Flash 2 wait state   
18
      RCC_HCLKConfig(RCC_SYSCLK_Div1);                        // HCLK = SYSCLK    
19
      RCC_PCLK2Config(RCC_HCLK_Div1);                         // PCLK2 = HCLK    // ABP2 max 72 MHz         !!! WICHTIG
20
      RCC_PCLK1Config(RCC_HCLK_Div2);                         // PCLK1 = HCLK/2  // ABP1 max 36 MHz         !!! WICHTIG
21
      RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_3);    // PLLCLK = 25MHz * 3 = 75 MHz                !!! WICHTIG
22
      RCC_PLLCmd(ENABLE);                                     // Enable PLL
23
      
24
      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);     // Wait till PLL is ready
25
        
26
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);              // Select PLL as system clock source
27
      
28
      while(RCC_GetSYSCLKSource() != 0x08);                   // Wait till PLL is used as system clock source               
29
   }
30

31

32
}
33

34
   /* Configure all the GPIOA in Input Floating mode */
35
   GPIO_InitTypeDef  GPIO_InitStructure;
36

37

38

39
   //RCC->APB2ENR |= RCC_APB2ENR_IOPBEN| RCC_APB2ENR_AFIOEN;                      // clock für PortB
40
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOB , ENABLE);

scheint aber eingschalten zu sein der Takt, oder irre ich mich da ? Für 
Port D, sowohl als auch für Port B....
OP #2489020
Lesenswert?

1
    while(1)
2
        
3
    {
4

5
      if (ReadValue == 1)
6
          
7
            GPIO_SetBits(GPIOD, GPIO_Pin_7);
8
           
9
         else
10
            GPIO_ResetBits(GPIOD, GPIO_Pin_7);
11
    }

Da der Taster 0 aktiv zu sein scheint, geht bei nichtbetätgtem Taster 
mal die LED an. mach ich bei READValue == 0 bleibt sie demzufolge aus. 
Aber wenn ich den Taster drücke oder loslasse, ändert sich halt immer 
noch nichts...
OP #2489118
Lesenswert?

1
    while(1)
2
        
3
    {
4
          int ReadValue;
5
      // Variable für bessere Übersicht festlegen
6
      ReadValue = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9);
7

8
      if (ReadValue == 1)
9
          
10
            GPIO_SetBits(GPIOD, GPIO_Pin_7);//, GPIO_ResetBits(GPIOD, GPIO_Pin_7);// , GPIO_ResetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
11
      else
12
            GPIO_ResetBits(GPIOD, GPIO_Pin_7);

geht irgendwie immer noch nicht.......
OP #2489220
Lesenswert?

das ist das Programm von einem Codebeispiel.......
1
/* Includes ------------------------------------------------------------------*/
2
#include "stm32f10x_conf.h"
3
#include <stdio.h>
4
#include <time.h>
5

6
/** @addtogroup Template_Project
7
  * @{
8
  */
9

10
/* Private typedef -----------------------------------------------------------*/
11
/* Private define ------------------------------------------------------------*/
12
/* Private macro -------------------------------------------------------------*/
13
/* Private variables ---------------------------------------------------------*/
14
volatile unsigned short TimerVar;
15

16
/* Private function prototypes -----------------------------------------------*/
17
void NVIC_Configuration(void);
18
void RCC_Configuration(void);
19
void IO_Configuration(void);
20

21
  int ReadValue;
22

23
/* Private functions ---------------------------------------------------------*/
24

25
/**
26
  * @brief  Main program.
27
  * @param  None
28
  * @retval None
29
  */
30
int main(void)
31
{
32
    int x,anzahl;
33
    anzahl = 40;
34
    
35
   RCC_Configuration();    // es muss richtige Definition in stm32f10x.h einkommentiert sein (STM32F10X_MD)
36
   IO_Configuration ();
37
   //NVIC_Configuration();
38
   
39
   SysTick_Config(75000);      // ruft in cyklischen Abständen eine ISR auf (1ms)
40

41
   // LED 3 und 4 leuchten immer
42

43

44
 /*   Infinite loop 
45
   while (1)
46
   {
47
    
48
        GPIO_ResetBits(GPIOD, GPIO_Pin_13);
49
        int start;
50
        start = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13);
51
        if (start == 1)
52
            {
53
                GPIO_SetBits(GPIOD, GPIO_Pin_13);
54
            
55
        
56
            }
57
   
58
   do  { 
59
   GPIO_SetBits(GPIOD, GPIO_Pin_3);
60
   }while(anzahl < 40);*/
61
       
62
   //for (x=1;x=anzahl;x++)
63
   //for (x=1;x=anzahl;x++);   
64
   /*GPIO_ResetBits(GPIOD, GPIO_Pin_3);
65
   GPIO_SetBits(GPIOD, GPIO_Pin_4);
66
   GPIO_SetBits(GPIOD, GPIO_Pin_3);
67
   GPIO_SetBits(GPIOD, GPIO_Pin_13);*/
68
    //warte(100);
69
   //GPIO_SetBits(GPIOD, GPIO_Pin_7);
70
   //GPIO_SetBits(GPIOD, GPIO_Pin_13);
71

72
      
73
      // Wenn Taster B3 nicht betätigt leuchtet LED4,
74
      // Reset von LED3 damit immer nur eine der beiden LEDs leuchtet
75
    
76

77

78

79
   // while(1)
80
        
81
    //{
82
        
83
      // Variable für bessere Übersicht festlegen
84
      ReadValue = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9);
85

86
      if (ReadValue == 1)
87
          
88
            GPIO_SetBits(GPIOD, GPIO_Pin_7);//, GPIO_ResetBits(GPIOD, GPIO_Pin_7);// , GPIO_ResetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
89
      else
90
            GPIO_ResetBits(GPIOD, GPIO_Pin_7);
91
   //wait(100);
92
     /*  if (ReadValue == 1)
93
            GPIO_ResetBits(GPIOD, GPIO_Pin_7);// , GPIO_SetBits(GPIOD, GPIO_Pin_3) , GPIO_ResetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
94
      
95
      if (ReadValue == 1)
96
            GPIO_ResetBits(GPIOD, GPIO_Pin_4) , GPIO_ResetBits(GPIOD, GPIO_Pin_3) , GPIO_SetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
97
      else  GPIO_SetBits(GPIOD, GPIO_Pin_3) , GPIO_ResetBits(GPIOD, GPIO_Pin_4);
98
          
99
      if (ReadValue == 1)
100
          
101
            GPIO_SetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
102
      
103
      else GPIO_SetBits(GPIOD, GPIO_Pin_13) , GPIO_ResetBits(GPIOD, GPIO_Pin_7);
104
          
105
     */
106
   //}
107
}
108

109

110

111
void NVIC_Configuration(void)
112
{
113
   NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); 
114
}
115

116
void RCC_Configuration(void)
117
{     
118
   // The maximum frequency of the AHB and the APB2 domains is 72 MHz
119
   // The maximum allowed frequency of the APB1 domain is 36 MHz
120

121
   ErrorStatus       HSEStartUpStatus;
122
   
123
   RCC_DeInit();                                              // RCC system reset(for debug purpose)
124
   
125
   
126
   RCC_HSEConfig(RCC_HSE_ON);                                 // Enable HSE
127
   HSEStartUpStatus = RCC_WaitForHSEStartUp();                // Wait till HSE is ready
128

129
   if(HSEStartUpStatus == SUCCESS)
130
   {    
131
      FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);   // Enable Prefetch Buffer    
132
      FLASH_SetLatency(FLASH_Latency_2);                      // Flash 2 wait state   
133
      RCC_HCLKConfig(RCC_SYSCLK_Div1);                        // HCLK = SYSCLK    
134
      RCC_PCLK2Config(RCC_HCLK_Div1);                         // PCLK2 = HCLK    // ABP2 max 72 MHz         !!! WICHTIG
135
      RCC_PCLK1Config(RCC_HCLK_Div2);                         // PCLK1 = HCLK/2  // ABP1 max 36 MHz         !!! WICHTIG
136
      RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_3);    // PLLCLK = 25MHz * 3 = 75 MHz                !!! WICHTIG
137
      RCC_PLLCmd(ENABLE);                                     // Enable PLL
138
      
139
      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);     // Wait till PLL is ready
140
        
141
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);              // Select PLL as system clock source
142
      
143
      while(RCC_GetSYSCLKSource() != 0x08);                   // Wait till PLL is used as system clock source               
144
   }
145

146

147
}
148

149

150
void IO_Configuration(void)
151
{  
152
   /* Configure all the GPIOA in Input Floating mode */
153
   GPIO_InitTypeDef  GPIO_InitStructure;
154

155

156

157
   //RCC->APB2ENR |= RCC_APB2ENR_IOPBEN| RCC_APB2ENR_AFIOEN;                      // clock für PortB
158
   //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOB , ENABLE);
159
   
160

161
   
162
   // LED Ports definieren
163
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD , ENABLE);
164
   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_7 | GPIO_Pin_13;   
165
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
166
   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
167

168
   GPIO_Init(GPIOD, &GPIO_InitStructure);
169

170

171
   //Tasterinitialisierung
172
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
173
   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;   
174
   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
175
   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13;
176
   GPIO_Init(GPIOB, &GPIO_InitStructure);
177
   GPIO_Init(GPIOC, &GPIO_InitStructure);
178
  
179
   
180

181
/*
182
   GPIOB->CRL &= ~(GPIO_CRL_MODE4 | GPIO_CRL_CNF4);
183
   GPIOB->CRL &= ~(GPIO_CRL_MODE5 | GPIO_CRL_CNF5);
184
   GPIOB->CRL &= ~(GPIO_CRL_MODE6 | GPIO_CRL_CNF6);
185
   GPIOB->CRL &= ~(GPIO_CRL_MODE7 | GPIO_CRL_CNF7);
186

187
   
188
   GPIOB->CRL |= GPIO_CRL_MODE4
189
               | GPIO_CRL_MODE5
190
               | GPIO_CRL_MODE6
191
               | GPIO_CRL_MODE7;
192

193
   AFIO->MAPR &= ~AFIO_MAPR_SWJ_CFG;
194
   AFIO->MAPR |=  AFIO_MAPR_SWJ_CFG_1;
195
*/
196

197
}
198

199

200

201
#ifdef  USE_FULL_ASSERT
202

203

204
void assert_failed(uint8_t* file, uint32_t line)
205
{ 
206
  /* User can add his own implementation to report the file name and line number,
207
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
208

209
  /* Infinite loop */
210
  while (1)
211
  {
212
  }
213
}
214
#endif
215

216
/**
217
  * @}
218
  */
OP #2489405
Lesenswert?

oder mal ne ganz andere frage, vielleicht ist es besser, das projekt von 
grund auf neu zu schreiben. wenn ich in ride7 ein neues projekt erstelle 
ist mir schon klar, irgendwie muß ich dann noch eine neue source datei 
erstellen und zum schluss mit add item die main.c hinzufügen, oder ? 
aber wie schreibe ich die main.c ?

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