Mercurial > public > ostc4
annotate Small_CPU/Src/baseCPU2.c @ 118:ee7f2cd9b9b4 FlipDisplay
Enlarge text limits to get string displayed completly
author | Ideenmodellierer |
---|---|
date | Sun, 06 Jan 2019 22:31:45 +0100 |
parents | 68181cd61f20 |
children | 6347a86caa18 |
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 | |
89 | 156 uint8_t hasExternalClock(void) { |
157 if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF)) | |
158 return 1; | |
159 else | |
160 return 0; | |
38 | 161 } |
162 | |
163 // SHALL LOAD AT 0x08000000 + 0x00005000 = 0x08005000. | |
164 // See CPU2-RTE.ld | |
100 | 165 const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") ))= { |
166 .versionFirst = 1, | |
167 .versionSecond = 5, | |
103
f5d2f02dc73f
Generalize TEXT of pressure unit
Dmitry Romanov <kitt@bk.ru>
parents:
100
diff
changeset
|
168 .versionThird = 1, |
100 | 169 .versionBeta = 0, |
38 | 170 |
89 | 171 /* 4 bytes with trailing 0 */ |
100 | 172 .signature = "mh", |
38 | 173 |
100 | 174 .release_year = 18, |
175 .release_month = 7, | |
176 .release_day = 29, | |
177 .release_sub = 0, | |
38 | 178 |
89 | 179 /* max 48 with trailing 0 */ |
180 //release_info ="12345678901234567890123456789012345678901" | |
181 .release_info = "compass stuff", | |
38 | 182 |
89 | 183 /* for safety reasons and coming functions */ |
184 .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND, | |
185 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ | |
186 .magic[3] = FIRMWARE_MAGIC_END }; | |
38 | 187 |
89 | 188 uint8_t firmwareVersionHigh(void) { |
189 return cpu2_FirmwareData.versionFirst; | |
38 | 190 } |
191 | |
89 | 192 uint8_t firmwareVersionLow(void) { |
193 return cpu2_FirmwareData.versionSecond; | |
38 | 194 } |
195 | |
196 /** @addtogroup OSTC4 | |
197 * @{ | |
198 */ | |
199 | |
200 /** @addtogroup CPU2 | |
201 * @{ | |
202 */ | |
203 | |
204 /* Private typedef -----------------------------------------------------------*/ | |
205 /* Private define ------------------------------------------------------------*/ | |
206 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 | |
207 #define BUTTON_OSTC_GPIO_PORT GPIOA | |
208 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
209 #define BUTTON_OSTC_IRQn EXTI0_IRQn | |
210 | |
211 #define BUTTON_TEST_GPIO_PIN GPIO_PIN_3 | |
212 #define BUTTON_TEST_GPIO_PORT GPIOA | |
213 #define BUTTON_TEST_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE() | |
214 #define BUTTON_TEST_IRQn EXTI3_IRQn | |
215 | |
216 #define WIRELSS_RISING_GPIO_PIN GPIO_PIN_1 | |
217 #define WIRELSS_RISING_GPIO_PORT GPIOA | |
218 #define WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
219 #define WIRELSS_RISING_IRQn EXTI1_IRQn | |
220 | |
221 #define WIRELSS_FALLING_GPIO_PIN GPIO_PIN_2 | |
222 #define WIRELSS_FALLING_GPIO_PORT GPIOA | |
223 #define WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
224 #define WIRELSS_FALLING_IRQn EXTI2_IRQn | |
225 | |
226 #define WIRELSS_POWER_GPIO_PIN GPIO_PIN_12 | |
227 #define WIRELSS_POWER_GPIO_PORT GPIOB | |
228 #define WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() | |
229 | |
230 /* Private macro -------------------------------------------------------------*/ | |
231 | |
232 /* Private variables ---------------------------------------------------------*/ | |
233 uint32_t global_test_time_counter = 0; | |
234 SBackup backup; | |
235 | |
236 /* Private function prototypes -----------------------------------------------*/ | |
237 static void EXTI_Wakeup_Button_Init(void); | |
238 static void EXTI_Wakeup_Button_DeInit(void); | |
239 | |
240 static void EXTI_Test_Button_Init(void); | |
241 static void EXTI_Test_Button_DeInit(void); | |
242 | |
243 static void MX_EXTI_wireless_Init(void); | |
244 static void MX_EXTI_wireless_DeInit(void); | |
245 | |
246 //static void EXTILine01_Button_DeInit(void); | |
247 static void GPIO_LED_Init(void); | |
248 static void GPIO_Power_MainCPU_Init(void); | |
249 static void GPIO_Power_MainCPU_ON(void); | |
250 static void GPIO_Power_MainCPU_OFF(void); | |
251 | |
252 void GPIO_test_I2C_lines(void); | |
253 | |
254 //void sleep_test(void); | |
255 void sleep_prepare(void); | |
256 | |
257 void SystemClock_Config(void); | |
258 void SystemClock_Config_HSI(void); | |
259 void SystemClock_Config_HSE(void); | |
260 void SYSCLKConfig_STOP_HSI(void); | |
261 void SYSCLKConfig_STOP_HSE(void); | |
262 | |
263 void GPIO_new_DEBUG_Init(void); | |
264 void GPIO_new_DEBUG_LOW(void); | |
265 void GPIO_new_DEBUG_HIGH(void); | |
266 | |
267 #define REGULAR_RUN | |
268 | |
89 | 269 int __io_putchar(int ch) { |
270 ITM_SendChar(ch); | |
271 return ch; | |
38 | 272 } |
273 | |
274 /* Private functions ---------------------------------------------------------*/ | |
275 | |
276 /** | |
277 * @brief Main program | |
278 * @param None | |
279 * @retval None | |
280 */ | |
281 | |
89 | 282 int main(void) { |
283 HAL_Init(); | |
284 SystemClock_Config(); | |
38 | 285 |
89 | 286 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
287 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK); | |
288 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); | |
38 | 289 |
89 | 290 MX_RTC_init(); |
291 GPIO_LED_Init(); | |
292 GPIO_new_DEBUG_Init(); // added 170322 hw | |
293 initGlobals(); | |
38 | 294 |
89 | 295 printf("CPU2-RTE running...\n"); |
38 | 296 |
89 | 297 MX_I2C1_Init(); |
298 if (global.I2C_SystemStatus != HAL_OK) { | |
299 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { | |
300 MX_I2C1_TestAndClear(); // do it a second time | |
301 } | |
302 MX_I2C1_Init(); | |
303 } | |
38 | 304 |
89 | 305 //dangerous: TM_OTP_Write(0,0, 0x01); |
38 | 306 #ifdef REGULAR_RUN |
89 | 307 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); |
308 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
309 if (global.I2C_SystemStatus != HAL_OK) { | |
310 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { | |
311 MX_I2C1_TestAndClear(); // do it a second time | |
312 } | |
313 MX_I2C1_Init(); | |
314 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); | |
315 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
316 } | |
38 | 317 |
89 | 318 global.dataSendToMaster.sensorErrors = |
319 global.sensorError[SENSOR_PRESSURE_ID]; | |
320 init_surface_ring(); | |
321 init_battery_gas_gauge(); | |
322 HAL_Delay(10); | |
323 battery_gas_gauge_get_data(); | |
38 | 324 // battery_gas_gauge_set(0); |
325 | |
89 | 326 global.lifeData.battery_voltage = get_voltage(); |
327 global.lifeData.battery_charge = get_charge(); | |
328 copyBatteryData(); | |
38 | 329 |
89 | 330 MX_SPI3_Init(); |
331 if (!scheduleSetButtonResponsiveness()) { | |
332 HAL_Delay(1); | |
333 scheduleSetButtonResponsiveness(); // init | |
334 HAL_Delay(1); | |
335 if (!scheduleSetButtonResponsiveness()) // send again, if problem it's not my problem here. | |
336 { | |
337 HAL_Delay(1); | |
338 scheduleSetButtonResponsiveness(); // init | |
339 HAL_Delay(1); | |
340 } | |
341 } | |
38 | 342 |
89 | 343 ADCx_Init(); |
344 GPIO_Power_MainCPU_Init(); | |
345 global.mode = MODE_POWERUP; | |
38 | 346 #else |
89 | 347 init_pressure(); |
348 init_surface_ring(); | |
38 | 349 |
89 | 350 ADCx_Init(); |
351 GPIO_Power_MainCPU_Init(); | |
352 global.mode = MODE_TEST; | |
38 | 353 #endif |
89 | 354 while (1) { |
355 printf("Global mode = %d\n", global.mode); | |
38 | 356 |
89 | 357 switch (global.mode) { |
358 case MODE_POWERUP: | |
359 case MODE_BOOT: | |
360 // ReInit_battery_charger_status_pins(); | |
361 compass_init(0, 7); | |
362 accelerator_init(); | |
363 wireless_init(); | |
364 if (global.mode == MODE_BOOT) { | |
365 GPIO_Power_MainCPU_OFF(); | |
366 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); | |
367 GPIO_Power_MainCPU_ON(); | |
368 } | |
369 SPI_synchronize_with_Master(); | |
370 MX_DMA_Init(); | |
371 MX_SPI1_Init(); | |
372 MX_EXTI_wireless_Init(); | |
104 | 373 // SPI_Start_single_TxRx_with_Master(); |
89 | 374 EXTI_Test_Button_Init(); |
375 | |
376 /* | |
377 uint8_t dataWireless[64]; | |
378 while(1) | |
379 { | |
380 wireless_evaluate_and_debug(dataWireless,64); | |
381 } | |
382 */ | |
383 global.mode = MODE_SURFACE; | |
384 break; | |
38 | 385 |
89 | 386 case MODE_CALIB: |
90 | 387 scheduleCompassCalibrationMode(); |
89 | 388 break; |
389 | |
390 case MODE_SURFACE: | |
391 scheduleSurfaceMode(); | |
392 break; | |
38 | 393 |
89 | 394 case MODE_TEST: |
395 break; | |
38 | 396 |
89 | 397 case MODE_DIVE: |
90 | 398 backup.no_fly_time_minutes = global.no_fly_time_minutes; |
399 backup.seconds_since_last_dive = global.seconds_since_last_dive; | |
400 | |
401 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive, | |
402 global.seconds_since_last_dive ); | |
403 global.no_fly_time_minutes = 0; | |
404 global.lifeData.dive_time_seconds = 0; | |
405 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
406 scheduleDiveMode(); | |
407 // done now in scheduler prior to change mode: global.seconds_since_last_dive = 1; | |
408 | |
409 if( global.lifeData.dive_time_seconds > 60 ) | |
410 { | |
411 //No Fly time 60% of desaturationtime after dive | |
412 global.no_fly_time_minutes = decom_calc_desaturation_time( | |
413 global.lifeData.tissue_nitrogen_bar, | |
414 global.lifeData.tissue_helium_bar, | |
415 global.lifeData.pressure_surface_bar ) * 60 / 100; | |
416 if( global.no_fly_time_minutes < (24 * 60) ) | |
417 global.no_fly_time_minutes = 24 * 60; | |
418 } | |
419 else | |
420 { | |
421 global.no_fly_time_minutes = backup.no_fly_time_minutes; | |
422 global.seconds_since_last_dive = backup.seconds_since_last_dive; | |
423 } | |
424 | |
425 global.lifeData.dive_time_seconds = 0; | |
426 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
427 global.lifeData.counterSecondsShallowDepth = 0; | |
428 | |
429 backup.no_fly_time_minutes = 0; | |
430 backup.seconds_since_last_dive = 0; | |
89 | 431 break; |
38 | 432 |
89 | 433 case MODE_SHUTDOWN: |
434 HAL_Delay(200); | |
435 global.mode = MODE_SLEEP; | |
436 MX_SPI3_Init(); | |
437 break; | |
438 | |
439 case MODE_SLEEP: | |
440 /* | |
441 sleep_prepare(); | |
442 scheduleSleepMode_test(); | |
443 */ | |
444 /* | |
445 GPIO_Power_MainCPU_OFF(); | |
446 EXTI_Test_Button_DeInit(); | |
447 EXTI_Wakeup_Button_Init(); | |
448 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); | |
449 */ | |
450 EXTI_Test_Button_DeInit(); | |
451 MX_EXTI_wireless_DeInit(); | |
452 if (hasExternalClock()) | |
453 SystemClock_Config_HSI(); | |
454 sleep_prepare(); | |
38 | 455 |
89 | 456 GPIO_LED_Init(); |
38 | 457 |
89 | 458 scheduleSleepMode(); |
459 if (hasExternalClock()) | |
460 SystemClock_Config_HSE(); | |
461 GPIO_LED_Init(); | |
462 EXTI_Wakeup_Button_DeInit(); | |
463 ADCx_Init(); | |
464 GPIO_Power_MainCPU_Init(); | |
465 GPIO_Power_MainCPU_ON(); | |
466 compass_init(0, 7); | |
467 accelerator_init(); | |
468 wireless_init(); | |
105 | 469 // SPI_synchronize_with_Master(); TODO: REMOVE |
89 | 470 MX_DMA_Init(); |
471 MX_SPI1_Init(); | |
472 MX_EXTI_wireless_Init(); | |
104 | 473 // SPI_Start_single_TxRx_with_Master(); |
89 | 474 |
475 // EXTILine0_Button_DeInit(); not now, later after testing | |
476 break; | |
477 } | |
478 } | |
38 | 479 } |
480 | |
481 /** @brief Button feedback - EXTI line detection callbacks | |
482 * @param GPIO_Pin: Specifies the pins connected EXTI line | |
483 * @retval None | |
484 */ | |
89 | 485 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
38 | 486 |
89 | 487 if (GPIO_Pin == WIRELSS_RISING_GPIO_PIN) { |
488 wireless_trigger_RisingEdgeSilence(); | |
489 } | |
38 | 490 |
89 | 491 else |
38 | 492 |
89 | 493 if (GPIO_Pin == WIRELSS_FALLING_GPIO_PIN) { |
494 wireless_trigger_FallingEdgeSignalHigh(); | |
495 } | |
38 | 496 |
89 | 497 else |
38 | 498 |
89 | 499 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { |
500 if (global.mode == MODE_SLEEP) { | |
501 global.mode = MODE_BOOT; | |
502 } | |
503 } | |
38 | 504 |
89 | 505 else |
38 | 506 |
89 | 507 if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) { |
508 if (!global.demo_mode && (global.mode == MODE_SURFACE)) { | |
509 global.demo_mode = 1; | |
510 global.mode = MODE_DIVE; | |
511 } else if (global.demo_mode && (global.mode == MODE_DIVE) | |
512 && (global.lifeData.dive_time_seconds > 10)) { | |
513 global.demo_mode = 0; | |
514 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
515 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
516 } | |
517 } | |
38 | 518 } |
519 | |
520 /** | |
521 * @brief System Clock Configuration | |
522 * The system Clock is configured as follow : | |
523 * System Clock source = PLL (HSI) | |
524 * SYSCLK(Hz) = 100 MHz | |
525 * HCLK(Hz) = 100 MHz | |
526 * AHB Prescaler = 1 | |
527 * APB1 Prescaler = 2 | |
528 * APB2 Prescaler = 1 | |
529 * HSI Frequency(Hz) = 16 MHz | |
530 * PLL_M = 16 | |
531 * PLL_N = 400 | |
532 * PLL_P = 4 | |
533 * PLL_Q = 7 // no USB | |
534 * VDD(V) = 3.3 | |
535 * Main regulator output voltage = Scale1 mode | |
536 * Flash Latency(WS) = 3 | |
537 * @param None | |
538 * @retval None | |
539 */ | |
540 | |
89 | 541 void SystemClock_Config(void) { |
542 if (hasExternalClock()) | |
543 SystemClock_Config_HSE(); | |
544 else | |
545 SystemClock_Config_HSI(); | |
38 | 546 } |
547 | |
89 | 548 void SYSCLKConfig_STOP(void) { |
549 SYSCLKConfig_STOP_HSI(); | |
38 | 550 } |
551 | |
89 | 552 void SystemClock_Config_HSE(void) { |
553 RCC_OscInitTypeDef RCC_OscInitStruct; | |
554 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
38 | 555 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; |
556 | |
89 | 557 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); |
38 | 558 |
89 | 559 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); |
38 | 560 |
89 | 561 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; |
562 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
563 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
564 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
565 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
566 RCC_OscInitStruct.PLL.PLLM = 8; | |
567 RCC_OscInitStruct.PLL.PLLN = 320; | |
568 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
569 RCC_OscInitStruct.PLL.PLLQ = 4; | |
570 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 571 |
89 | 572 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
573 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
574 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
575 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
576 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
577 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
578 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 579 |
580 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
581 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
582 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
583 | |
584 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); | |
585 | |
586 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); | |
587 | |
89 | 588 /* SysTick_IRQn interrupt configuration */ |
38 | 589 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
590 } | |
591 | |
89 | 592 void SystemClock_Config_HSI(void) { |
593 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
594 RCC_OscInitTypeDef RCC_OscInitStruct; | |
38 | 595 |
89 | 596 /* Enable Power Control clock */ |
597 __HAL_RCC_PWR_CLK_ENABLE(); | |
38 | 598 |
89 | 599 /* The voltage scaling allows optimizing the power consumption when the device is |
600 clocked below the maximum system frequency, to update the voltage scaling value | |
601 regarding system frequency refer to product datasheet. */ | |
602 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); | |
38 | 603 |
89 | 604 /* Enable HSI Oscillator and activate PLL with HSI as source */ |
605 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
606 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
607 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
608 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
609 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
610 RCC_OscInitStruct.PLL.PLLM = 16; | |
611 RCC_OscInitStruct.PLL.PLLN = 320; | |
612 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
613 RCC_OscInitStruct.PLL.PLLQ = 4; | |
614 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 615 |
89 | 616 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
617 clocks dividers */ | |
618 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
619 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | |
620 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
621 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
622 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
623 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
624 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 625 } |
626 /* | |
627 RCC_OscInitTypeDef RCC_OscInitStruct; | |
628 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
629 | |
630 __HAL_RCC_PWR_CLK_ENABLE(); | |
631 | |
632 //__PWR_CLK_ENABLE(); | |
633 | |
634 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); | |
635 | |
636 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE; | |
637 RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
638 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
639 RCC_OscInitStruct.HSICalibrationValue = 16; | |
640 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
641 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
642 RCC_OscInitStruct.PLL.PLLM = 16; | |
643 RCC_OscInitStruct.PLL.PLLN = 320; | |
644 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
645 RCC_OscInitStruct.PLL.PLLQ = 4; | |
646 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
647 | |
648 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; | |
649 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
650 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
651 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
652 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
653 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
654 } | |
655 | |
656 static void RtcClock_Config(void) | |
657 { | |
658 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; | |
659 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
660 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
661 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
662 } | |
663 */ | |
664 | |
665 /** | |
666 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL | |
667 * and select PLL as system clock source. | |
668 * @param None | |
669 * @retval None | |
670 */ | |
89 | 671 void SYSCLKConfig_STOP_HSE(void) { |
672 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
673 RCC_OscInitTypeDef RCC_OscInitStruct; | |
674 uint32_t pFLatency = 0; | |
38 | 675 |
89 | 676 /* Get the Oscillators configuration according to the internal RCC registers */ |
677 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 678 |
89 | 679 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
680 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
681 RCC_OscInitStruct.HSIState = RCC_HSE_ON; | |
682 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
683 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 684 |
89 | 685 /* Get the Clocks configuration according to the internal RCC registers */ |
686 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 687 |
89 | 688 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
689 clocks dividers */ | |
690 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
691 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
692 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 693 } |
694 | |
89 | 695 void SYSCLKConfig_STOP_HSI(void) { |
696 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
697 RCC_OscInitTypeDef RCC_OscInitStruct; | |
698 uint32_t pFLatency = 0; | |
38 | 699 |
89 | 700 /* Get the Oscillators configuration according to the internal RCC registers */ |
701 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 702 |
89 | 703 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
704 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
705 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
706 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
707 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
708 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 709 |
89 | 710 /* Get the Clocks configuration according to the internal RCC registers */ |
711 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 712 |
89 | 713 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
714 clocks dividers */ | |
715 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
716 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
717 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 718 } |
719 | |
720 /** | |
721 * @brief SYSTICK callback | |
722 * @param None | |
723 * @retval None | |
724 */ | |
89 | 725 void HAL_SYSTICK_Callback(void) { |
726 HAL_IncTick(); | |
38 | 727 } |
728 | |
729 /** | |
730 * @brief Configures GPIO for LED | |
731 * Might move with STM32Cube usage | |
732 * @param None | |
733 * @retval None | |
734 */ | |
735 /* | |
736 void GPIO_test_I2C_lines(void) | |
737 { | |
738 GPIO_InitTypeDef GPIO_InitStructure; | |
739 __GPIOB_CLK_ENABLE(); | |
740 GPIO_InitStructure.Pin = GPIO_PIN_8; | |
741 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
742 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
743 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
744 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
745 GPIO_InitStructure.Pin = GPIO_PIN_9; | |
746 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
747 | |
748 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET); | |
749 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET); | |
750 HAL_Delay(10); | |
751 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET); | |
752 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | |
753 HAL_Delay(10); | |
754 } | |
755 */ | |
756 | |
89 | 757 static void GPIO_LED_Init(void) { |
758 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 759 |
89 | 760 __GPIOC_CLK_ENABLE(); |
761 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
762 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
763 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
764 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
765 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | |
38 | 766 } |
767 | |
89 | 768 void GPIO_new_DEBUG_Init(void) { |
38 | 769 #ifdef DEBUG_PIN_ACTIVE |
89 | 770 GPIO_InitTypeDef GPIO_InitStructure; |
38 | 771 |
89 | 772 __GPIOC_CLK_ENABLE(); |
773 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
774 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
775 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
776 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
777 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
38 | 778 #endif |
779 } | |
780 | |
89 | 781 void GPIO_new_DEBUG_LOW(void) { |
38 | 782 #ifdef DEBUG_PIN_ACTIVE |
89 | 783 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); |
38 | 784 #endif |
785 } | |
786 | |
89 | 787 void GPIO_new_DEBUG_HIGH(void) { |
38 | 788 #ifdef DEBUG_PIN_ACTIVE |
89 | 789 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); |
38 | 790 #endif |
791 } | |
792 | |
89 | 793 static void GPIO_Power_MainCPU_Init(void) { |
794 GPIO_InitTypeDef GPIO_InitStructure; | |
795 __GPIOC_CLK_ENABLE(); | |
796 GPIO_InitStructure.Pin = GPIO_PIN_0; | |
797 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
798 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
799 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
800 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | |
801 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); | |
38 | 802 } |
803 | |
89 | 804 static void GPIO_Power_MainCPU_ON(void) { |
805 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); | |
38 | 806 } |
807 | |
89 | 808 static void GPIO_Power_MainCPU_OFF(void) { |
809 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_SET); | |
38 | 810 } |
811 | |
812 /** | |
813 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | |
814 * @param None | |
815 * @retval None | |
816 */ | |
817 | |
89 | 818 static void EXTI_Wakeup_Button_Init(void) { |
819 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 820 |
89 | 821 __HAL_RCC_GPIOA_CLK_ENABLE(); |
822 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE(); | |
823 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | |
824 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
825 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
826 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | |
38 | 827 |
89 | 828 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0); |
829 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn); | |
38 | 830 } |
831 | |
89 | 832 static void EXTI_Wakeup_Button_DeInit(void) { |
833 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 834 |
89 | 835 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
836 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
837 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
38 | 838 |
89 | 839 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; |
840 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | |
841 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn); | |
38 | 842 } |
843 | |
89 | 844 static void EXTI_Test_Button_Init(void) { |
845 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 846 |
89 | 847 BUTTON_TEST_GPIO_CLK_ENABLE(); |
848 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | |
849 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
850 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
851 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | |
852 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0); | |
853 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn); | |
38 | 854 } |
855 | |
89 | 856 static void EXTI_Test_Button_DeInit(void) { |
857 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 858 |
89 | 859 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
860 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
861 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
38 | 862 |
89 | 863 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; |
864 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | |
865 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn); | |
38 | 866 } |
867 | |
89 | 868 static void MX_EXTI_wireless_Init(void) { |
869 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 870 |
89 | 871 WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE(); |
872 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; | |
873 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
874 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
875 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure); | |
876 HAL_GPIO_WritePin( WIRELSS_POWER_GPIO_PORT, WIRELSS_POWER_GPIO_PIN, | |
877 GPIO_PIN_SET); | |
38 | 878 |
89 | 879 WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE(); |
880 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; | |
881 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
882 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
883 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure); | |
38 | 884 |
89 | 885 HAL_NVIC_SetPriority( WIRELSS_RISING_IRQn, 0x02, 0); |
886 HAL_NVIC_EnableIRQ( WIRELSS_RISING_IRQn); | |
38 | 887 |
89 | 888 WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE(); |
889 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; | |
890 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
891 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
892 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure); | |
38 | 893 |
89 | 894 HAL_NVIC_SetPriority( WIRELSS_FALLING_IRQn, 0x02, 0); |
895 HAL_NVIC_EnableIRQ( WIRELSS_FALLING_IRQn); | |
38 | 896 |
897 } | |
898 | |
89 | 899 static void MX_EXTI_wireless_DeInit(void) { |
900 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 901 |
89 | 902 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
903 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
904 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
38 | 905 |
89 | 906 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; |
907 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure); | |
38 | 908 |
89 | 909 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; |
910 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure); | |
38 | 911 |
89 | 912 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; |
913 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure); | |
38 | 914 |
89 | 915 HAL_NVIC_DisableIRQ( WIRELSS_RISING_IRQn); |
916 HAL_NVIC_DisableIRQ( WIRELSS_FALLING_IRQn); | |
38 | 917 } |
918 | |
919 /* NUCLEO C 13 | |
920 KEY_BUTTON_GPIO_CLK_ENABLE(); | |
921 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
922 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
923 GPIO_InitStructure.Pin = KEY_BUTTON_PIN; | |
924 HAL_GPIO_Init(KEY_BUTTON_GPIO_PORT, &GPIO_InitStructure); | |
925 HAL_NVIC_SetPriority(KEY_BUTTON_EXTI_IRQn, 2, 0); | |
926 HAL_NVIC_EnableIRQ(KEY_BUTTON_EXTI_IRQn); | |
927 */ | |
928 | |
929 /** | |
930 * @brief Wake Up Timer callback | |
931 * @param hrtc: RTC handle | |
932 * @retval None | |
933 */ | |
934 | |
935 /* | |
936 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) | |
937 { | |
938 static uint8_t uwCounter = 0; | |
939 uwCounter = 1; | |
940 } | |
941 */ | |
942 | |
89 | 943 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 944 |
945 } | |
946 | |
89 | 947 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 948 |
949 } | |
950 | |
89 | 951 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 952 |
953 } | |
954 | |
89 | 955 void sleep_prepare(void) { |
956 EXTI_Wakeup_Button_Init(); | |
957 /* | |
958 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
959 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
960 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
961 */ | |
962 compass_sleep(); | |
963 HAL_Delay(100); | |
964 accelerator_sleep(); | |
965 HAL_Delay(100); | |
38 | 966 |
89 | 967 I2C_DeInit(); |
968 MX_SPI_DeInit(); | |
969 MX_SPI3_DeInit(); | |
970 ADCx_DeInit(); | |
38 | 971 |
89 | 972 GPIO_InitTypeDef GPIO_InitStruct; |
38 | 973 |
89 | 974 __HAL_RCC_GPIOA_CLK_ENABLE(); |
975 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
976 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
977 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
38 | 978 |
89 | 979 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
980 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
981 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
982 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
983 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 984 #ifdef DEBUGMODE |
89 | 985 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ |
38 | 986 #endif |
89 | 987 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
38 | 988 |
89 | 989 GPIO_InitStruct.Pin = |
990 GPIO_PIN_All | |
991 ^ ( GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_14 | |
992 | GPIO_PIN_15); /* power off & charger in & charge out & OSC32*/ | |
993 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); | |
38 | 994 |
89 | 995 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); |
38 | 996 #ifdef DEBUGMODE |
89 | 997 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ |
38 | 998 #endif |
89 | 999 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct); |
38 | 1000 |
89 | 1001 GPIO_InitStruct.Pin = GPIO_PIN_All; |
1002 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 1003 |
89 | 1004 GPIO_Power_MainCPU_OFF(); |
38 | 1005 |
1006 #ifndef DEBUGMODE | |
89 | 1007 __HAL_RCC_GPIOB_CLK_DISABLE(); |
38 | 1008 #endif |
89 | 1009 __HAL_RCC_GPIOH_CLK_DISABLE(); |
38 | 1010 |
89 | 1011 HAL_Delay(1000); |
38 | 1012 } |
1013 | |
1014 /* | |
1015 void sleep_test(void) | |
1016 { | |
1017 GPIO_InitTypeDef GPIO_InitStruct; | |
1018 | |
1019 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
1020 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
1021 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
1022 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
1023 | |
1024 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
1025 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
1026 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
1027 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
1028 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); | |
1029 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
1030 | |
1031 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_15 | GPIO_PIN_14); | |
1032 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
1033 | |
1034 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | |
1035 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
1036 | |
1037 GPIO_Power_MainCPU_OFF(); | |
1038 | |
1039 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
1040 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
1041 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
1042 | |
1043 // __HAL_RCC_GPIOA_CLK_DISABLE(); | |
1044 __HAL_RCC_GPIOB_CLK_DISABLE(); | |
1045 // __HAL_RCC_GPIOC_CLK_DISABLE(); | |
1046 __HAL_RCC_GPIOH_CLK_DISABLE(); | |
1047 | |
1048 | |
1049 HAL_Delay(5000); | |
1050 while(1) | |
1051 { | |
1052 RTC_StopMode_2seconds(); | |
1053 HAL_Delay(200); | |
1054 } | |
1055 } | |
1056 */ | |
1057 | |
1058 #ifdef USE_FULL_ASSERT | |
1059 | |
1060 /** | |
1061 * @brief Reports the name of the source file and the source line number | |
1062 * where the assert_param error has occurred. | |
1063 * @param file: pointer to the source file name | |
1064 * @param line: assert_param error line source number | |
1065 * @retval None | |
1066 */ | |
1067 void assert_failed(uint8_t* file, uint32_t line) | |
1068 { | |
89 | 1069 /* User can add his own implementation to report the file name and line number, |
1070 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
38 | 1071 |
89 | 1072 /* Infinite loop */ |
1073 while (1) | |
1074 { | |
1075 } | |
38 | 1076 } |
1077 #endif | |
1078 | |
1079 /** | |
1080 * @} | |
1081 */ | |
104 | 1082 /** |
1083 * @brief This function handles SysTick Handler. | |
1084 * @param None | |
1085 * @retval None | |
1086 */ | |
38 | 1087 |
104 | 1088 /*TxRx only here. Every 100 ms.*/ |
1089 uint8_t ticks100ms=0; | |
1090 void SysTick_Handler(void) | |
1091 { | |
1092 HAL_IncTick(); | |
1093 if(ticks100ms<100){ | |
1094 ticks100ms++; | |
1095 }else | |
1096 { | |
1097 ticks100ms=0; | |
1098 SPI_Start_single_TxRx_with_Master(); | |
1099 } | |
1100 } | |
38 | 1101 /** |
1102 * @} | |
1103 */ | |
1104 | |
1105 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |