Forum: Mikrocontroller und Digitale Elektronik STM32F030 will nicht aufwachen


von Markus A. (Firma: SturiaTronic Projektmanagement) (markus0x0101)


Lesenswert?

Hallo zusammen
Ich bin neu unterwegs mit dem STM32F.
Meine Firmware läuft eigentlich ganz gut. Auch in den STOP Mode kann ich 
wechseln. Aber aufwecken geht leider nicht mehr.

Der Interrupt zum Aufwecken funktioniert wenn ich die SwitchDeviceOff() 
Funktion nicht ausführe.

Aber sobald ich sie aktiviere geht nichts mehr weiter.
Die Stromaufnahme ist im Stop Mode ca 20uA. Wennich dann den Switch 
betätige steigt sie auf 500uA an aber es ändert sich sonst nichts.

Im Web habe ich gesucht und einiges ausprobiert aber ohne Erfolg.

1
//***************************************************************************
2
//*  Includes
3
//***************************************************************************
4
#include "stm32f0xx_hal.h"
5
#include "Main.h"
6
#include "Definition_App.h"
7
#include "Definition_Board.h"
8
#include "controlunit.h"
9
10
//***************************************************************************
11
//*  File Global Variable Definitions
12
//***************************************************************************
13
14
15
//***************************************************************************
16
//*  Init
17
//***************************************************************************
18
GPIO_InitTypeDef           GPIO_InitStruct;
19
s_heat_pack                heat_pack;
20
21
//***************************************************************************
22
//*  System Clock Config
23
//***************************************************************************
24
void SystemClock_Config(void)
25
{
26
27
  RCC_OscInitTypeDef RCC_OscInitStruct;
28
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
29
30
    /**Initializes the CPU, AHB and APB busses clocks 
31
    */
32
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
33
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
34
  RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
35
  RCC_OscInitStruct.HSICalibrationValue = 16;
36
  RCC_OscInitStruct.HSI14CalibrationValue = 16;
37
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
38
  HAL_RCC_OscConfig(&RCC_OscInitStruct);
39
40
    /**Initializes the CPU, AHB and APB busses clocks 
41
    */
42
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
43
                              |RCC_CLOCKTYPE_PCLK1;
44
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
45
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
46
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
47
48
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
49
50
    /**Configure the Systick interrupt time 
51
    */
52
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
53
54
    /**Configure the Systick 
55
    */
56
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
57
58
  /* SysTick_IRQn interrupt configuration */
59
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
60
}
61
62
63
64
//***************************************************************************
65
//*  GPIO Init
66
//***************************************************************************
67
void MX_GPIO_Init(void)
68
{
69
70
   // GPIO Ports Clock Enable
71
   __HAL_RCC_GPIOA_CLK_ENABLE();
72
   __HAL_RCC_GPIOB_CLK_ENABLE();
73
   
74
75
   // Configure GPIO pin Output Level
76
   HAL_GPIO_WritePin(GPIOA, LED_RED_Pin|HEAT_CHARGE_Pin|LED_1_Pin|LED_2_Pin|LED_GREEN_Pin, GPIO_PIN_RESET);
77
78
   // Configure GPIO pins : LED_RED_Pin HEAT_CHARGE_Pin LED_1_Pin LED_2_Pin LED_GREEN_Pin
79
   GPIO_InitStruct.Pin = LED_RED_Pin|HEAT_CHARGE_Pin|LED_1_Pin|LED_2_Pin|LED_GREEN_Pin;
80
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
81
   GPIO_InitStruct.Pull = GPIO_NOPULL;
82
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
83
   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
84
85
   // Configure GPIO pin : SWITCH_Pin
86
   GPIO_InitStruct.Pin = SWITCH_Pin;
87
   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
88
   GPIO_InitStruct.Pull = GPIO_NOPULL;
89
   HAL_GPIO_Init(SWITCH_GPIO_Port, &GPIO_InitStruct);
90
91
   // Switch OFF LED
92
   LED_Off(LED_1);
93
  LED_Off(LED_2);
94
  LED_Off(LED_Green);
95
   LED_Off(LED_Red);
96
   
97
}
98
99
//***************************************************************************
100
//*  Init Interrupt
101
//***************************************************************************
102
void Init_interrupt(void)
103
{
104
   // Configure GPIO pin : SWITCH_Pin
105
   GPIO_InitStruct.Pin = SWITCH_Pin;
106
   GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
107
   GPIO_InitStruct.Pull = GPIO_NOPULL;
108
   HAL_GPIO_Init(SWITCH_GPIO_Port, &GPIO_InitStruct);
109
110
   /* EXTI interrupt init*/
111
   HAL_NVIC_SetPriority(EXTI0_1_IRQn, 3, 0);
112
   HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
113
   
114
   HAL_PWR_DisableSleepOnExit();
115
 
116
}   
117
118
//***************************************************************************
119
//*  SysTick_Handler
120
//*  occurs every 1ms
121
//***************************************************************************
122
void SysTick_Handler(void)
123
{
124
125
  static uint16_t Timer10msTicks = 0;
126
  static uint16_t Timer100msTicks = 0;
127
  static uint16_t msOddEven = 1;
128
129
  
130
  
131
// ms Odd or Even
132
  if (msOddEven == 0)     // ms is even
133
  {
134
    msOddEven = 1;
135
  } else                  // ms is odd
136
  {
137
    msOddEven = 0;
138
  }
139
140
// 10ms Counter
141
  Timer10msTicks++;                
142
  if(Timer10msTicks >= 10)        
143
  {
144
145
    Timer10msTicks = 0;  
146
  }
147
  
148
// 100ms Counter  
149
  Timer100msTicks++;              
150
  if(Timer100msTicks >= 100)      
151
  {
152
      //SwitchDeviceOff();
153
    Timer100msTicks = 0;  
154
     
155
  }
156
157
158
159
}
160
161
162
163
164
//***************************************************************************
165
//*  LED ON Function
166
//***************************************************************************
167
void LED_On(uint32_t led)
168
{
169
   switch(led)
170
   {
171
      case LED_1:
172
         HAL_GPIO_WritePin(GPIOA,LED_1_Pin,GPIO_PIN_RESET);
173
      break;
174
      case LED_2:
175
         HAL_GPIO_WritePin(GPIOA,LED_2_Pin,GPIO_PIN_RESET);
176
      break;
177
      case LED_Green:
178
//         HAL_GPIO_WritePin(GPIOA,LED_GREEN_Pin,GPIO_PIN_RESET);
179
      break;
180
      case LED_Red:
181
         HAL_GPIO_WritePin(GPIOA,LED_RED_Pin,GPIO_PIN_RESET);
182
      break;
183
            
184
      default:
185
      break;    
186
   }
187
}
188
189
//***************************************************************************
190
//*  LED OFF Function
191
//***************************************************************************
192
void LED_Off(uint32_t led)
193
{
194
   switch(led)
195
   {
196
      case LED_1:
197
         HAL_GPIO_WritePin(GPIOA,LED_1_Pin,GPIO_PIN_SET);
198
      break;
199
      case LED_2:
200
         HAL_GPIO_WritePin(GPIOA,LED_2_Pin,GPIO_PIN_SET);
201
      break;
202
      case LED_Green:
203
//         HAL_GPIO_WritePin(GPIOA,LED_GREEN_Pin,GPIO_PIN_SET);
204
      break;
205
      case LED_Red:
206
         HAL_GPIO_WritePin(GPIOA,LED_RED_Pin,GPIO_PIN_SET);
207
      break;
208
            
209
      default:
210
      break;    
211
   }
212
}
213
214
215
216
217
//***************************************************************************
218
//*  Main Function
219
//***************************************************************************
220
int main(void)
221
{
222
   // Local Variables
223
224
225
   // MCU Configuration
226
227
   // Reset of all peripherals, Initializes the Flash interface and the Systick.
228
   HAL_Init();
229
230
   // Configure the system clock
231
   SystemClock_Config();
232
233
   // Initialize all configured peripherals
234
   MX_GPIO_Init();
235
236
 
237
   Init_interrupt();
238
239
   while(1)
240
   {
241
242
    
243
   } // infinite loop
244
245
}
246
247
248
/**
249
* @brief This function handles EXTI line 0 and 1 interrupts.
250
*/
251
void EXTI0_1_IRQHandler(void)
252
{
253
254
   DEBUG;   // Toggle DEBUG LED
255
   HAL_GPIO_EXTI_IRQHandler(SWITCH_Pin);
256
257
}
258
259
//***************************************************************************
260
//*  Switch Device OFF
261
//***************************************************************************
262
void SwitchDeviceOff(void)
263
{
264
  heat_pack.shut_off_timer=0;
265
   heat_pack.Heat_Step=0;
266
   HeatFetOff();
267
   LED_Off(LED_1);
268
  LED_Off(LED_2);
269
  LED_Off(LED_Green);
270
   LED_Off(LED_Red);
271
272
   __HAL_RCC_ADC1_CLK_DISABLE();
273
   Init_interrupt();
274
   
275
   HAL_SuspendTick();
276
   HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);   // Enter STOP Mode
277
   HAL_ResumeTick();
278
   
279
   // Wake UP 
280
281
   // Reset of all peripherals, Initializes the Flash interface and the Systick.
282
   HAL_Init();
283
284
   // Configure the system clock
285
   SystemClock_Config();
286
287
   // Initialize all configured peripherals
288
   MX_GPIO_Init();
289
 
290
DEBUG;   
291
   
292
  heat_pack.Heat_Step = 0;
293
294
}

Hat wer von euch vieleicht eine Idee/ Tipp ?

Vielen Dank

von Markus A. (Firma: SturiaTronic Projektmanagement) (markus0x0101)


Lesenswert?

Kann es sein, dass das Problem darin liegt, dass ich nicht in der Main 
While  Schleife einschlafen lasse sinder irgendwo in einer unterfunktion 
im Systick ?

von Dr. Sommer (Gast)


Lesenswert?

Markus A. schrieb:
> sinder irgendwo in einer unterfunktion im Systick ?

Ja. Wie willst du auf Interrupts warten (WFI) wenn du bereits im 
Interrupt bist?

von Dr. Sommer (Gast)


Lesenswert?

Wenn du in der main in der Endlosschleife ein __WFI() einbaust wird der 
Stromverbrauch schon dramatisch sinken. Vielleicht brauchst du den Stop 
Mode dann gar nicht.

von Jim M. (turboj)


Lesenswert?

1
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

Schau mal im Handbuch/Refman nach ob er steigende/fallende Flanke ohne 
Takt erkennen kann. Ich kenne etliche µC die ohne aktives Taktsignal 
(aka Sleep Mode) nur noch "Leveled" Interrupts können. Denn etliche 
Flankentrigger-Implementationen benötigen ein Taktsignal.

Ansonsten mal schauen ob der Pin korrekt konfiguriert wurde, ich sehe 
hier beispielsweise keinen "AF" Mode. Ist der für externen Int nötig?

von Markus A. (Firma: SturiaTronic Projektmanagement) (markus0x0101)


Lesenswert?

Hallo zusammen

Das Projekt funktioniert nun.
Das schlafen legen in der Main While Schleife war die lösung.
Ich denke es war ein Nestet Interrupt Problem.
Das heisst .. schlafenlegen in einem Systick interrupt und auf einen 
anderen Interrupt warten ...

Danke für eure hilfe

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.