Mercurial > public > ostc4
annotate Small_CPU/Src/baseCPU2.c @ 82:a6f0881074a4 kittz
+i2c analog noise filtering
spi more stable
author | Dmitry Romanov <kitt@bk.ru> |
---|---|
date | Tue, 20 Nov 2018 12:08:19 +0300 |
parents | 6a6116d7b5bb |
children | e6abbef57475 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @copyright heinrichs weikamp | |
4 * @file base.c including main() | |
5 * @author heinrichs weikamp gmbh | |
6 * @date 15-Aug-2014 | |
7 * @version V1.0.3 | |
8 * @since 21-Nov-2014 | |
9 * @brief The beginning of it all. main() is part of this. | |
10 * + Do the inits for hardware | |
11 * + Do the inits for sub-systems like menu, dive screen etc. | |
12 * + Start IRQs | |
13 * + Start MainTasks not in IRQs | |
14 * @bug | |
15 * @warning | |
16 @verbatim | |
17 ============================================================================== | |
18 ##### What about hardware without 8 MHz oscilator ##### | |
19 ============================================================================== | |
20 [..] modify OTP Byte 1 at 0x1FFF7800 with ST-Link utility | |
21 | |
22 ============================================================================== | |
23 ##### Where is the RTE Firmware version ##### | |
24 ============================================================================== | |
25 [..] in baseCPU2.c <just here below :-> | |
26 | |
27 ============================================================================== | |
28 ##### What to do with the RTE Firmware version ##### | |
29 ============================================================================== | |
30 [..] change the values RTErequiredHigh and RTErequiredLow in settings.c | |
31 to start warning via the firmware if not updated | |
32 | |
33 ============================================================================== | |
34 ##### What it does ##### | |
35 ============================================================================== | |
36 [..] All realtime stuff und all what has to be done during sleep | |
37 | |
38 [..] RealTimeClock. The entire time and date handling (including divetime) | |
39 [..] Hardware control for pressure sensor, compass, battery monitor | |
40 [..] Calculations of tissue load, critical radius, otu, cns | |
41 [..] Switching off the power of the main CPU after request from it. | |
42 | |
43 ============================================================================== | |
44 ##### IRQs ##### | |
45 ============================================================================== | |
46 [..] The IRQs are are only used for SystemTick and SPI TransferComplete after | |
47 DMA data reception. | |
48 | |
49 [..] HAL_SPI_TxRxCpltCallback() restarts DMA and will call | |
50 scheduleSpecial_Evaluate_DataSendToSlave() only if it is not blocked | |
51 by I2C for example by setting global.dataSendToSlaveStopEval to 0. | |
52 If the evaluation is blocked it has to be tested and executed afterwards. | |
53 I2C is executed _without_ the usage of interrupts. | |
54 | |
55 ============================================================================== | |
56 ##### Main loop ##### | |
57 ============================================================================== | |
58 [..] is a combination of the while loop below in main.c and code in scheduler.c | |
59 It is similar to the DR5 code / logic - in contrast to the main CPU | |
60 Switching the state is done via global.mode | |
61 The loops in scheduler all run in the main execution thread without | |
62 any job stacks (like it was in the DR5). | |
63 | |
64 ============================================================================== | |
65 ##### Real Time Clock ##### | |
66 ============================================================================== | |
67 [..] Wehe sie zickt statt tickt! | |
68 The RTC is a seperate part of hardware inside the CPU and is not affected | |
69 by reset. Only power-on reset does change something. | |
70 This is fine but the RTC is vital for the Sleep mode as Wakeuptimer. | |
71 This is the only date/time system in the OSTC. The main CPU is passive. | |
72 Data transfer is done with localtime_rtc_tr und localtime_rtc_dr | |
73 in HAL_RTC format to the main CPU and as HAL_RTC structs the way back for | |
74 setting the actual time and date. | |
75 The RTC unit has 20 Byte of V_bat powered SRAM. It could be used | |
76 for something usefull in both CPUs. | |
77 | |
78 ============================================================================== | |
79 ##### File system ##### | |
80 ============================================================================== | |
81 [..] some files are used for both CPUs, like decom.c/.h, data_central.h, ... | |
82 | |
83 | |
84 ============================================================================== | |
85 ##### Unique device ID register (96 bits) ##### | |
86 ============================================================================== | |
87 [..] some files are used for both CPUs, like decom.c/.h, data_central.h, ... | |
88 | |
89 | |
90 ============================================================================== | |
91 ##### I2C ##### | |
92 ============================================================================== | |
93 [..] used for pressure, compass, (accelerator) and battery gauge | |
94 main cpu and pic (button) is spi | |
95 | |
96 | |
97 ============================================================================== | |
98 ##### Firmware Update Info ##### | |
99 ============================================================================== | |
100 V0.85 160531 scheduleCheck_pressure_reached_dive_mode_level() changes | |
101 160606 global.no_fly_time_minutes ist at least 24h after the dive | |
102 160613 ambient light fixed | |
103 160720 compass calib to Flash (8000 writes max. as erase has problems) | |
104 160829 do not reset main CPU on power on! | |
105 V0.91 161018 pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(); | |
106 V0.92+ 161020 global.sensorError[MAX_SENSORS] | |
107 fix missing init_pressure(); at powerUp of RTE | |
108 added HAL_StatusTypeDef for many functions in pressure.c | |
109 161024 no_fly_time_minutes Backup FIX | |
110 seconds_since_last_dive now related to RTC clock | |
111 161121 close to surface starts at 1 meter below last known surface pressure | |
112 161121 in surface mode dive mode starts @1 mtr difference if surface 880 mbar instead of 700 mbar before | |
113 V0.97+ 170213 added global.dataSendToSlave.diveModeInfo for DIVEMODE_Apnea | |
114 added global.dataSendToSlave.setEndDive | |
115 DIVEMODE_Apnea special in scheduler.c (ticksdiff >= 1000) -> no tissue, cns, otu, no change in noFly Time etc. | |
116 V0.99 170320 new HAL Driver Repository | |
117 V1.01 170509 old HAL Driver Repository | |
118 | |
119 @endverbatim | |
120 ****************************************************************************** | |
121 * @attention | |
122 * | |
123 * <h2><center>© COPYRIGHT(c) 2017 heinrichs weikamp</center></h2> | |
124 * | |
125 ****************************************************************************** | |
126 */ | |
127 | |
128 //#define DEBUG_PIN_ACTIVE | |
129 /* Includes ------------------------------------------------------------------*/ | |
130 | |
131 #include "baseCPU2.h" | |
132 | |
133 // From Small_CPU/Inc: | |
134 #include "dma.h" | |
135 #include "i2c.h" | |
136 #include "spi.h" | |
137 #include "rtc.h" | |
138 #include "adc.h" | |
139 #include "compass.h" | |
140 #include "pressure.h" | |
141 #include "batteryGasGauge.h" | |
142 #include "batteryCharger.h" | |
143 #include "scheduler.h" | |
144 #include "wireless.h" | |
145 #include "tm_stm32f4_otp.h" | |
146 | |
147 // From Common/Inc: | |
148 #include "calc_crush.h" | |
149 #include "decom.h" | |
150 #include "FirmwareData.h" | |
151 | |
152 // From Common/Drivers/ | |
153 #include "stm32f4xx_hal.h" | |
154 #include <stdio.h> | |
155 | |
156 uint8_t hasExternalClock(void) | |
157 { | |
158 if( (TM_OTP_Read( 0, 0 ) > 0) && (TM_OTP_Read( 0, 0 ) < 0xFF) ) | |
159 return 1; | |
160 else | |
161 return 0; | |
162 } | |
163 | |
164 // SHALL LOAD AT 0x08000000 + 0x00005000 = 0x08005000. | |
165 // See CPU2-RTE.ld | |
166 const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") )) | |
167 = | |
168 { | |
169 .versionFirst = 1, | |
82 | 170 .versionSecond = 5, |
171 .versionThird = 2, | |
55
a7683f9765da
Italian activated (needs some fine tuning), special characters (?,?,?,?,? and others) currently not working...
heinrichsweikamp
parents:
39
diff
changeset
|
172 .versionBeta = 0, |
38 | 173 |
174 /* 4 bytes with trailing 0 */ | |
55
a7683f9765da
Italian activated (needs some fine tuning), special characters (?,?,?,?,? and others) currently not working...
heinrichsweikamp
parents:
39
diff
changeset
|
175 .signature = "mh", |
38 | 176 |
39 | 177 .release_year = 18, |
178 .release_month = 7, | |
179 .release_day = 29, | |
38 | 180 .release_sub = 0, |
181 | |
182 /* max 48 with trailing 0 */ | |
183 //release_info ="12345678901234567890123456789012345678901" | |
184 .release_info = "compass stuff", | |
185 | |
186 /* for safety reasons and coming functions */ | |
187 .magic[0] = FIRMWARE_MAGIC_FIRST, | |
188 .magic[1] = FIRMWARE_MAGIC_SECOND, | |
189 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ | |
190 .magic[3] = FIRMWARE_MAGIC_END | |
191 }; | |
192 | |
193 uint8_t firmwareVersionHigh(void) | |
194 { | |
195 return cpu2_FirmwareData.versionFirst; | |
196 } | |
197 | |
198 uint8_t firmwareVersionLow(void) | |
199 { | |
200 return cpu2_FirmwareData.versionSecond; | |
201 } | |
202 | |
203 /** @addtogroup OSTC4 | |
204 * @{ | |
205 */ | |
206 | |
207 /** @addtogroup CPU2 | |
208 * @{ | |
209 */ | |
210 | |
211 /* Private typedef -----------------------------------------------------------*/ | |
212 /* Private define ------------------------------------------------------------*/ | |
213 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 | |
214 #define BUTTON_OSTC_GPIO_PORT GPIOA | |
215 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
216 #define BUTTON_OSTC_IRQn EXTI0_IRQn | |
217 | |
218 #define BUTTON_TEST_GPIO_PIN GPIO_PIN_3 | |
219 #define BUTTON_TEST_GPIO_PORT GPIOA | |
220 #define BUTTON_TEST_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE() | |
221 #define BUTTON_TEST_IRQn EXTI3_IRQn | |
222 | |
223 #define WIRELSS_RISING_GPIO_PIN GPIO_PIN_1 | |
224 #define WIRELSS_RISING_GPIO_PORT GPIOA | |
225 #define WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
226 #define WIRELSS_RISING_IRQn EXTI1_IRQn | |
227 | |
228 #define WIRELSS_FALLING_GPIO_PIN GPIO_PIN_2 | |
229 #define WIRELSS_FALLING_GPIO_PORT GPIOA | |
230 #define WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
231 #define WIRELSS_FALLING_IRQn EXTI2_IRQn | |
232 | |
233 #define WIRELSS_POWER_GPIO_PIN GPIO_PIN_12 | |
234 #define WIRELSS_POWER_GPIO_PORT GPIOB | |
235 #define WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() | |
236 | |
237 /* Private macro -------------------------------------------------------------*/ | |
238 | |
239 /* Private variables ---------------------------------------------------------*/ | |
240 uint32_t global_test_time_counter = 0; | |
241 SBackup backup; | |
242 | |
243 /* Private function prototypes -----------------------------------------------*/ | |
244 static void EXTI_Wakeup_Button_Init(void); | |
245 static void EXTI_Wakeup_Button_DeInit(void); | |
246 | |
247 static void EXTI_Test_Button_Init(void); | |
248 static void EXTI_Test_Button_DeInit(void); | |
249 | |
250 static void MX_EXTI_wireless_Init(void); | |
251 static void MX_EXTI_wireless_DeInit(void); | |
252 | |
253 //static void EXTILine01_Button_DeInit(void); | |
254 static void GPIO_LED_Init(void); | |
255 static void GPIO_Power_MainCPU_Init(void); | |
256 static void GPIO_Power_MainCPU_ON(void); | |
257 static void GPIO_Power_MainCPU_OFF(void); | |
258 | |
259 void GPIO_test_I2C_lines(void); | |
260 | |
261 //void sleep_test(void); | |
262 void sleep_prepare(void); | |
263 | |
264 void SystemClock_Config(void); | |
265 void SystemClock_Config_HSI(void); | |
266 void SystemClock_Config_HSE(void); | |
267 void SYSCLKConfig_STOP_HSI(void); | |
268 void SYSCLKConfig_STOP_HSE(void); | |
269 | |
270 void GPIO_new_DEBUG_Init(void); | |
271 void GPIO_new_DEBUG_LOW(void); | |
272 void GPIO_new_DEBUG_HIGH(void); | |
273 | |
274 #define REGULAR_RUN | |
275 | |
276 int __io_putchar(int ch) | |
277 { | |
278 ITM_SendChar( ch ); | |
279 return ch; | |
280 } | |
281 | |
282 /* Private functions ---------------------------------------------------------*/ | |
283 | |
284 /** | |
285 * @brief Main program | |
286 * @param None | |
287 * @retval None | |
288 */ | |
289 | |
290 int main(void) | |
291 { | |
292 HAL_Init(); | |
293 SystemClock_Config(); | |
294 | |
295 HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq() / 1000 ); | |
296 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK ); | |
297 HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 ); | |
298 | |
299 MX_RTC_init(); | |
300 GPIO_LED_Init(); | |
301 GPIO_new_DEBUG_Init(); // added 170322 hw | |
302 initGlobals(); | |
303 | |
304 printf("CPU2-RTE running...\n"); | |
305 | |
306 MX_I2C1_Init(); | |
307 if( global.I2C_SystemStatus != HAL_OK ) | |
308 { | |
309 if( MX_I2C1_TestAndClear() == GPIO_PIN_RESET ) | |
310 { | |
311 MX_I2C1_TestAndClear(); // do it a second time | |
312 } | |
313 MX_I2C1_Init(); | |
314 } | |
315 | |
316 //dangerous: TM_OTP_Write(0,0, 0x01); | |
317 #ifdef REGULAR_RUN | |
318 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); | |
319 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
320 if( global.I2C_SystemStatus != HAL_OK ) | |
321 { | |
322 if( MX_I2C1_TestAndClear() == GPIO_PIN_RESET ) | |
323 { | |
324 MX_I2C1_TestAndClear(); // do it a second time | |
325 } | |
326 MX_I2C1_Init(); | |
327 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); | |
328 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
329 } | |
330 | |
331 global.dataSendToMaster.sensorErrors = | |
332 global.sensorError[SENSOR_PRESSURE_ID]; | |
333 init_surface_ring(); | |
334 init_battery_gas_gauge(); | |
335 HAL_Delay( 10 ); | |
336 battery_gas_gauge_get_data(); | |
337 // battery_gas_gauge_set(0); | |
338 | |
339 global.lifeData.battery_voltage = get_voltage(); | |
340 global.lifeData.battery_charge = get_charge(); | |
341 copyBatteryData(); | |
342 | |
343 MX_SPI3_Init(); | |
344 if( !scheduleSetButtonResponsiveness() ) | |
345 { | |
346 HAL_Delay( 1 ); | |
347 scheduleSetButtonResponsiveness(); // init | |
348 HAL_Delay( 1 ); | |
349 if( !scheduleSetButtonResponsiveness() ) // send again, if problem it's not my problem here. | |
350 { | |
351 HAL_Delay( 1 ); | |
352 scheduleSetButtonResponsiveness(); // init | |
353 HAL_Delay( 1 ); | |
354 } | |
355 } | |
356 | |
357 ADCx_Init(); | |
358 GPIO_Power_MainCPU_Init(); | |
359 global.mode = MODE_POWERUP; | |
360 #else | |
361 init_pressure(); | |
362 init_surface_ring(); | |
363 | |
364 ADCx_Init(); | |
365 GPIO_Power_MainCPU_Init(); | |
366 global.mode = MODE_TEST; | |
367 #endif | |
368 while( 1 ) | |
369 { | |
370 printf("Global mode = %d\n", global.mode); | |
371 | |
372 switch( global.mode ) | |
373 { | |
374 case MODE_POWERUP: | |
375 case MODE_BOOT: | |
376 // ReInit_battery_charger_status_pins(); | |
377 compass_init( 0, 7 ); | |
378 accelerator_init(); | |
379 wireless_init(); | |
380 if( global.mode == MODE_BOOT ) | |
381 { | |
382 GPIO_Power_MainCPU_OFF(); | |
383 HAL_Delay( 100 ); // for GPIO_Power_MainCPU_ON(); | |
384 GPIO_Power_MainCPU_ON(); | |
385 } | |
386 SPI_synchronize_with_Master(); | |
387 MX_DMA_Init(); | |
388 MX_SPI1_Init(); | |
389 MX_EXTI_wireless_Init(); | |
390 SPI_Start_single_TxRx_with_Master(); | |
391 EXTI_Test_Button_Init(); | |
392 | |
393 /* | |
394 uint8_t dataWireless[64]; | |
395 while(1) | |
396 { | |
397 wireless_evaluate_and_debug(dataWireless,64); | |
398 } | |
399 */ | |
400 global.mode = MODE_SURFACE; | |
401 break; | |
402 | |
403 case MODE_CALIB: | |
404 scheduleCompassCalibrationMode(); | |
405 break; | |
406 | |
407 case MODE_SURFACE: | |
408 scheduleSurfaceMode(); | |
409 break; | |
410 | |
411 case MODE_TEST: | |
412 GPIO_Power_MainCPU_ON(); | |
413 SPI_synchronize_with_Master(); | |
414 MX_DMA_Init(); | |
415 MX_SPI1_Init(); | |
416 // MX_EXTI_wireless_Init(); | |
417 SPI_Start_single_TxRx_with_Master(); | |
418 // EXTI_Test_Button_Init(); | |
419 | |
420 scheduleTestMode(); | |
421 break; | |
422 | |
423 case MODE_DIVE: | |
424 backup.no_fly_time_minutes = global.no_fly_time_minutes; | |
425 backup.seconds_since_last_dive = global.seconds_since_last_dive; | |
426 | |
427 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive, | |
428 global.seconds_since_last_dive ); | |
429 global.no_fly_time_minutes = 0; | |
430 global.lifeData.dive_time_seconds = 0; | |
431 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
432 scheduleDiveMode(); | |
433 // done now in scheduler prior to change mode: global.seconds_since_last_dive = 1; | |
434 | |
435 if( global.lifeData.dive_time_seconds > 60 ) | |
436 { | |
437 //No Fly time 60% of desaturationtime after dive | |
438 global.no_fly_time_minutes = decom_calc_desaturation_time( | |
439 global.lifeData.tissue_nitrogen_bar, | |
440 global.lifeData.tissue_helium_bar, | |
441 global.lifeData.pressure_surface_bar ) * 60 / 100; | |
442 if( global.no_fly_time_minutes < (24 * 60) ) | |
443 global.no_fly_time_minutes = 24 * 60; | |
444 } | |
445 else | |
446 { | |
447 global.no_fly_time_minutes = backup.no_fly_time_minutes; | |
448 global.seconds_since_last_dive = backup.seconds_since_last_dive; | |
449 } | |
450 | |
451 global.lifeData.dive_time_seconds = 0; | |
452 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
453 global.lifeData.counterSecondsShallowDepth = 0; | |
454 | |
455 backup.no_fly_time_minutes = 0; | |
456 backup.seconds_since_last_dive = 0; | |
457 break; | |
458 | |
459 case MODE_SHUTDOWN: | |
460 HAL_Delay( 200 ); | |
461 global.mode = MODE_SLEEP; | |
462 MX_SPI3_Init(); | |
463 break; | |
464 | |
465 case MODE_SLEEP: | |
466 /* | |
467 sleep_prepare(); | |
468 scheduleSleepMode_test(); | |
469 */ | |
470 /* | |
471 GPIO_Power_MainCPU_OFF(); | |
472 EXTI_Test_Button_DeInit(); | |
473 EXTI_Wakeup_Button_Init(); | |
474 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); | |
475 */ | |
476 EXTI_Test_Button_DeInit(); | |
477 MX_EXTI_wireless_DeInit(); | |
478 if( hasExternalClock() ) | |
479 SystemClock_Config_HSI(); | |
480 sleep_prepare(); | |
481 | |
482 GPIO_LED_Init(); | |
483 | |
484 scheduleSleepMode(); | |
485 if( hasExternalClock() ) | |
486 SystemClock_Config_HSE(); | |
487 GPIO_LED_Init(); | |
488 EXTI_Wakeup_Button_DeInit(); | |
489 ADCx_Init(); | |
490 GPIO_Power_MainCPU_Init(); | |
491 GPIO_Power_MainCPU_ON(); | |
492 compass_init( 0, 7 ); | |
493 accelerator_init(); | |
494 wireless_init(); | |
495 SPI_synchronize_with_Master(); | |
496 MX_DMA_Init(); | |
497 MX_SPI1_Init(); | |
498 MX_EXTI_wireless_Init(); | |
499 SPI_Start_single_TxRx_with_Master(); | |
500 | |
501 // EXTILine0_Button_DeInit(); not now, later after testing | |
502 break; | |
503 } | |
504 } | |
505 } | |
506 | |
507 /** @brief Button feedback - EXTI line detection callbacks | |
508 * @param GPIO_Pin: Specifies the pins connected EXTI line | |
509 * @retval None | |
510 */ | |
511 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | |
512 { | |
513 | |
514 if( GPIO_Pin == WIRELSS_RISING_GPIO_PIN ) | |
515 { | |
516 wireless_trigger_RisingEdgeSilence(); | |
517 } | |
518 | |
519 else | |
520 | |
521 if( GPIO_Pin == WIRELSS_FALLING_GPIO_PIN ) | |
522 { | |
523 wireless_trigger_FallingEdgeSignalHigh(); | |
524 } | |
525 | |
526 else | |
527 | |
528 if( GPIO_Pin == BUTTON_OSTC_GPIO_PIN ) | |
529 { | |
530 if( global.mode == MODE_SLEEP ) | |
531 { | |
532 global.mode = MODE_BOOT; | |
533 } | |
534 } | |
535 | |
536 else | |
537 | |
538 if( GPIO_Pin == BUTTON_TEST_GPIO_PIN ) | |
539 { | |
540 if( !global.demo_mode && (global.mode == MODE_SURFACE) ) | |
541 { | |
542 global.demo_mode = 1; | |
543 global.mode = MODE_DIVE; | |
544 } | |
545 else if( global.demo_mode && (global.mode == MODE_DIVE) | |
546 && (global.lifeData.dive_time_seconds > 10) ) | |
547 { | |
548 global.demo_mode = 0; | |
549 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
550 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
551 } | |
552 } | |
553 } | |
554 | |
555 /** | |
556 * @brief System Clock Configuration | |
557 * The system Clock is configured as follow : | |
558 * System Clock source = PLL (HSI) | |
559 * SYSCLK(Hz) = 100 MHz | |
560 * HCLK(Hz) = 100 MHz | |
561 * AHB Prescaler = 1 | |
562 * APB1 Prescaler = 2 | |
563 * APB2 Prescaler = 1 | |
564 * HSI Frequency(Hz) = 16 MHz | |
565 * PLL_M = 16 | |
566 * PLL_N = 400 | |
567 * PLL_P = 4 | |
568 * PLL_Q = 7 // no USB | |
569 * VDD(V) = 3.3 | |
570 * Main regulator output voltage = Scale1 mode | |
571 * Flash Latency(WS) = 3 | |
572 * @param None | |
573 * @retval None | |
574 */ | |
575 | |
576 void SystemClock_Config(void) | |
577 { | |
578 if( hasExternalClock() ) | |
579 SystemClock_Config_HSE(); | |
580 else | |
581 SystemClock_Config_HSI(); | |
582 } | |
583 | |
584 void SYSCLKConfig_STOP(void) | |
585 { | |
586 SYSCLKConfig_STOP_HSI(); | |
587 } | |
588 | |
589 void SystemClock_Config_HSE(void) | |
590 { | |
591 RCC_OscInitTypeDef RCC_OscInitStruct; | |
592 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
593 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; | |
594 | |
595 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); | |
596 | |
597 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE2 ); | |
598 | |
599 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; | |
600 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
601 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
602 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
603 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
604 RCC_OscInitStruct.PLL.PLLM = 8; | |
605 RCC_OscInitStruct.PLL.PLLN = 320; | |
606 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
607 RCC_OscInitStruct.PLL.PLLQ = 4; | |
608 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
609 | |
610 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | |
611 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
612 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
613 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
614 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
615 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
616 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_2 ); | |
617 | |
618 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
619 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
620 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
621 | |
622 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); | |
623 | |
624 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); | |
625 | |
626 /* SysTick_IRQn interrupt configuration */ | |
627 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); | |
628 } | |
629 | |
630 void SystemClock_Config_HSI(void) | |
631 { | |
632 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
633 RCC_OscInitTypeDef RCC_OscInitStruct; | |
634 | |
635 /* Enable Power Control clock */ | |
636 __HAL_RCC_PWR_CLK_ENABLE(); | |
637 | |
638 /* The voltage scaling allows optimizing the power consumption when the device is | |
639 clocked below the maximum system frequency, to update the voltage scaling value | |
640 regarding system frequency refer to product datasheet. */ | |
641 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE2 ); | |
642 | |
643 /* Enable HSI Oscillator and activate PLL with HSI as source */ | |
644 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
645 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
646 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
647 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
648 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
649 RCC_OscInitStruct.PLL.PLLM = 16; | |
650 RCC_OscInitStruct.PLL.PLLN = 320; | |
651 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
652 RCC_OscInitStruct.PLL.PLLQ = 4; | |
653 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
654 | |
655 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 | |
656 clocks dividers */ | |
657 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
658 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | |
659 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
660 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
661 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
662 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
663 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_2 ); | |
664 } | |
665 /* | |
666 RCC_OscInitTypeDef RCC_OscInitStruct; | |
667 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
668 | |
669 __HAL_RCC_PWR_CLK_ENABLE(); | |
670 | |
671 //__PWR_CLK_ENABLE(); | |
672 | |
673 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); | |
674 | |
675 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE; | |
676 RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
677 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
678 RCC_OscInitStruct.HSICalibrationValue = 16; | |
679 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
680 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
681 RCC_OscInitStruct.PLL.PLLM = 16; | |
682 RCC_OscInitStruct.PLL.PLLN = 320; | |
683 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
684 RCC_OscInitStruct.PLL.PLLQ = 4; | |
685 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
686 | |
687 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; | |
688 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
689 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
690 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
691 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
692 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
693 } | |
694 | |
695 static void RtcClock_Config(void) | |
696 { | |
697 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; | |
698 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
699 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
700 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
701 } | |
702 */ | |
703 | |
704 /** | |
705 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL | |
706 * and select PLL as system clock source. | |
707 * @param None | |
708 * @retval None | |
709 */ | |
710 void SYSCLKConfig_STOP_HSE(void) | |
711 { | |
712 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
713 RCC_OscInitTypeDef RCC_OscInitStruct; | |
714 uint32_t pFLatency = 0; | |
715 | |
716 /* Get the Oscillators configuration according to the internal RCC registers */ | |
717 HAL_RCC_GetOscConfig( &RCC_OscInitStruct ); | |
718 | |
719 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ | |
720 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
721 RCC_OscInitStruct.HSIState = RCC_HSE_ON; | |
722 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
723 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
724 | |
725 /* Get the Clocks configuration according to the internal RCC registers */ | |
726 HAL_RCC_GetClockConfig( &RCC_ClkInitStruct, &pFLatency ); | |
727 | |
728 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 | |
729 clocks dividers */ | |
730 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
731 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
732 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, pFLatency ); | |
733 } | |
734 | |
735 void SYSCLKConfig_STOP_HSI(void) | |
736 { | |
737 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
738 RCC_OscInitTypeDef RCC_OscInitStruct; | |
739 uint32_t pFLatency = 0; | |
740 | |
741 /* Get the Oscillators configuration according to the internal RCC registers */ | |
742 HAL_RCC_GetOscConfig( &RCC_OscInitStruct ); | |
743 | |
744 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ | |
745 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
746 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
747 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
748 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
749 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
750 | |
751 /* Get the Clocks configuration according to the internal RCC registers */ | |
752 HAL_RCC_GetClockConfig( &RCC_ClkInitStruct, &pFLatency ); | |
753 | |
754 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 | |
755 clocks dividers */ | |
756 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
757 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
758 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, pFLatency ); | |
759 } | |
760 | |
761 /** | |
762 * @brief SYSTICK callback | |
763 * @param None | |
764 * @retval None | |
765 */ | |
766 void HAL_SYSTICK_Callback(void) | |
767 { | |
768 HAL_IncTick(); | |
769 } | |
770 | |
771 /** | |
772 * @brief Configures GPIO for LED | |
773 * Might move with STM32Cube usage | |
774 * @param None | |
775 * @retval None | |
776 */ | |
777 /* | |
778 void GPIO_test_I2C_lines(void) | |
779 { | |
780 GPIO_InitTypeDef GPIO_InitStructure; | |
781 __GPIOB_CLK_ENABLE(); | |
782 GPIO_InitStructure.Pin = GPIO_PIN_8; | |
783 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
784 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
785 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
786 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
787 GPIO_InitStructure.Pin = GPIO_PIN_9; | |
788 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
789 | |
790 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET); | |
791 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET); | |
792 HAL_Delay(10); | |
793 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET); | |
794 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | |
795 HAL_Delay(10); | |
796 } | |
797 */ | |
798 | |
799 static void GPIO_LED_Init(void) | |
800 { | |
801 GPIO_InitTypeDef GPIO_InitStructure; | |
802 | |
803 __GPIOC_CLK_ENABLE(); | |
804 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
805 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
806 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
807 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
808 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure ); | |
809 } | |
810 | |
811 void GPIO_new_DEBUG_Init(void) | |
812 { | |
813 #ifdef DEBUG_PIN_ACTIVE | |
814 GPIO_InitTypeDef GPIO_InitStructure; | |
815 | |
816 __GPIOC_CLK_ENABLE(); | |
817 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
818 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
819 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
820 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
821 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
822 #endif | |
823 } | |
824 | |
825 void GPIO_new_DEBUG_LOW(void) | |
826 { | |
827 #ifdef DEBUG_PIN_ACTIVE | |
828 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); | |
829 #endif | |
830 } | |
831 | |
832 void GPIO_new_DEBUG_HIGH(void) | |
833 { | |
834 #ifdef DEBUG_PIN_ACTIVE | |
835 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); | |
836 #endif | |
837 } | |
838 | |
839 static void GPIO_Power_MainCPU_Init(void) | |
840 { | |
841 GPIO_InitTypeDef GPIO_InitStructure; | |
842 __GPIOC_CLK_ENABLE(); | |
843 GPIO_InitStructure.Pin = GPIO_PIN_0; | |
844 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
845 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
846 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
847 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure ); | |
848 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET ); | |
849 } | |
850 | |
851 static void GPIO_Power_MainCPU_ON(void) | |
852 { | |
853 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET ); | |
854 } | |
855 | |
856 static void GPIO_Power_MainCPU_OFF(void) | |
857 { | |
858 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_SET ); | |
859 } | |
860 | |
861 /** | |
862 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | |
863 * @param None | |
864 * @retval None | |
865 */ | |
866 | |
867 static void EXTI_Wakeup_Button_Init(void) | |
868 { | |
869 GPIO_InitTypeDef GPIO_InitStructure; | |
870 | |
871 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
872 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE(); | |
873 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | |
874 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
875 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
876 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure ); | |
877 | |
878 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0 ); | |
879 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn ); | |
880 } | |
881 | |
882 static void EXTI_Wakeup_Button_DeInit(void) | |
883 { | |
884 GPIO_InitTypeDef GPIO_InitStructure; | |
885 | |
886 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; | |
887 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
888 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
889 | |
890 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | |
891 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure ); | |
892 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn ); | |
893 } | |
894 | |
895 static void EXTI_Test_Button_Init(void) | |
896 { | |
897 GPIO_InitTypeDef GPIO_InitStructure; | |
898 | |
899 BUTTON_TEST_GPIO_CLK_ENABLE(); | |
900 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | |
901 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
902 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
903 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure ); | |
904 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0 ); | |
905 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn ); | |
906 } | |
907 | |
908 static void EXTI_Test_Button_DeInit(void) | |
909 { | |
910 GPIO_InitTypeDef GPIO_InitStructure; | |
911 | |
912 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; | |
913 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
914 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
915 | |
916 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | |
917 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure ); | |
918 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn ); | |
919 } | |
920 | |
921 static void MX_EXTI_wireless_Init(void) | |
922 { | |
923 GPIO_InitTypeDef GPIO_InitStructure; | |
924 | |
925 WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE(); | |
926 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; | |
927 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
928 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
929 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure ); | |
930 HAL_GPIO_WritePin( WIRELSS_POWER_GPIO_PORT, WIRELSS_POWER_GPIO_PIN, | |
931 GPIO_PIN_SET ); | |
932 | |
933 WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE(); | |
934 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; | |
935 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
936 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
937 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure ); | |
938 | |
939 HAL_NVIC_SetPriority( WIRELSS_RISING_IRQn, 0x02, 0 ); | |
940 HAL_NVIC_EnableIRQ( WIRELSS_RISING_IRQn ); | |
941 | |
942 WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE(); | |
943 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; | |
944 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
945 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
946 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure ); | |
947 | |
948 HAL_NVIC_SetPriority( WIRELSS_FALLING_IRQn, 0x02, 0 ); | |
949 HAL_NVIC_EnableIRQ( WIRELSS_FALLING_IRQn ); | |
950 | |
951 } | |
952 | |
953 static void MX_EXTI_wireless_DeInit(void) | |
954 { | |
955 GPIO_InitTypeDef GPIO_InitStructure; | |
956 | |
957 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; | |
958 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
959 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
960 | |
961 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; | |
962 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure ); | |
963 | |
964 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; | |
965 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure ); | |
966 | |
967 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; | |
968 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure ); | |
969 | |
970 HAL_NVIC_DisableIRQ( WIRELSS_RISING_IRQn ); | |
971 HAL_NVIC_DisableIRQ( WIRELSS_FALLING_IRQn ); | |
972 } | |
973 | |
974 /* NUCLEO C 13 | |
975 KEY_BUTTON_GPIO_CLK_ENABLE(); | |
976 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
977 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
978 GPIO_InitStructure.Pin = KEY_BUTTON_PIN; | |
979 HAL_GPIO_Init(KEY_BUTTON_GPIO_PORT, &GPIO_InitStructure); | |
980 HAL_NVIC_SetPriority(KEY_BUTTON_EXTI_IRQn, 2, 0); | |
981 HAL_NVIC_EnableIRQ(KEY_BUTTON_EXTI_IRQn); | |
982 */ | |
983 | |
984 /** | |
985 * @brief Wake Up Timer callback | |
986 * @param hrtc: RTC handle | |
987 * @retval None | |
988 */ | |
989 | |
990 /* | |
991 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) | |
992 { | |
993 static uint8_t uwCounter = 0; | |
994 uwCounter = 1; | |
995 } | |
996 */ | |
997 | |
998 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) | |
999 { | |
1000 | |
1001 } | |
1002 | |
1003 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) | |
1004 { | |
1005 | |
1006 } | |
1007 | |
1008 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) | |
1009 { | |
1010 | |
1011 } | |
1012 | |
1013 void sleep_prepare(void) | |
1014 { | |
1015 EXTI_Wakeup_Button_Init(); | |
1016 /* | |
1017 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
1018 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
1019 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
1020 */ | |
1021 compass_sleep(); | |
1022 HAL_Delay( 100 ); | |
1023 accelerator_sleep(); | |
1024 HAL_Delay( 100 ); | |
1025 | |
1026 I2C_DeInit(); | |
1027 MX_SPI_DeInit(); | |
1028 MX_SPI3_DeInit(); | |
1029 ADCx_DeInit(); | |
1030 | |
1031 GPIO_InitTypeDef GPIO_InitStruct; | |
1032 | |
1033 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
1034 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
1035 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
1036 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
1037 | |
1038 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
1039 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
1040 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
1041 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
1042 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct ); | |
1043 #ifdef DEBUGMODE | |
1044 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ | |
1045 #endif | |
1046 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct ); | |
1047 | |
1048 GPIO_InitStruct.Pin = GPIO_PIN_All | |
1049 ^ ( GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_14 | GPIO_PIN_15); /* power off & charger in & charge out & OSC32*/ | |
1050 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct ); | |
1051 | |
1052 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | |
1053 #ifdef DEBUGMODE | |
1054 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ | |
1055 #endif | |
1056 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct ); | |
1057 | |
1058 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
1059 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct ); | |
1060 | |
1061 GPIO_Power_MainCPU_OFF(); | |
1062 | |
1063 #ifndef DEBUGMODE | |
1064 __HAL_RCC_GPIOB_CLK_DISABLE(); | |
1065 #endif | |
1066 __HAL_RCC_GPIOH_CLK_DISABLE(); | |
1067 | |
1068 HAL_Delay( 1000 ); | |
1069 } | |
1070 | |
1071 /* | |
1072 void sleep_test(void) | |
1073 { | |
1074 GPIO_InitTypeDef GPIO_InitStruct; | |
1075 | |
1076 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
1077 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
1078 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
1079 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
1080 | |
1081 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
1082 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
1083 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
1084 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
1085 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); | |
1086 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
1087 | |
1088 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_15 | GPIO_PIN_14); | |
1089 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
1090 | |
1091 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | |
1092 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
1093 | |
1094 GPIO_Power_MainCPU_OFF(); | |
1095 | |
1096 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
1097 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
1098 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
1099 | |
1100 // __HAL_RCC_GPIOA_CLK_DISABLE(); | |
1101 __HAL_RCC_GPIOB_CLK_DISABLE(); | |
1102 // __HAL_RCC_GPIOC_CLK_DISABLE(); | |
1103 __HAL_RCC_GPIOH_CLK_DISABLE(); | |
1104 | |
1105 | |
1106 HAL_Delay(5000); | |
1107 while(1) | |
1108 { | |
1109 RTC_StopMode_2seconds(); | |
1110 HAL_Delay(200); | |
1111 } | |
1112 } | |
1113 */ | |
1114 | |
1115 #ifdef USE_FULL_ASSERT | |
1116 | |
1117 /** | |
1118 * @brief Reports the name of the source file and the source line number | |
1119 * where the assert_param error has occurred. | |
1120 * @param file: pointer to the source file name | |
1121 * @param line: assert_param error line source number | |
1122 * @retval None | |
1123 */ | |
1124 void assert_failed(uint8_t* file, uint32_t line) | |
1125 { | |
1126 /* User can add his own implementation to report the file name and line number, | |
1127 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
1128 | |
1129 /* Infinite loop */ | |
1130 while (1) | |
1131 { | |
1132 } | |
1133 } | |
1134 #endif | |
1135 | |
1136 /** | |
1137 * @} | |
1138 */ | |
1139 | |
1140 /** | |
1141 * @} | |
1142 */ | |
1143 | |
1144 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |