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