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