Mercurial > public > ostc4
annotate Small_CPU/Src/baseCPU2.c @ 295:718e5feded62
Merged in janlmulder/ostc4/div-fixes-6 (pull request #23)
Cleanup VPM, NDL to 240 min, and more cleanup
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Mon, 13 May 2019 13:37:34 +0000 |
parents | 733877ab87d9 |
children | d4d8d717e9a7 |
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, | |
280
ae27d6185d51
Make RTE show as 1.8.0 beta, add update files for testing purposes
heinrichsweikamp
parents:
274
diff
changeset
|
165 .versionSecond = 8, |
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, |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
173 .release_month = 5, |
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
174 .release_day = 6, |
100 | 175 .release_sub = 0, |
38 | 176 |
89 | 177 /* max 48 with trailing 0 */ |
178 //release_info ="12345678901234567890123456789012345678901" | |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
179 .release_info = "stable May'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 |
89 | 305 MX_I2C1_Init(); |
306 if (global.I2C_SystemStatus != HAL_OK) { | |
307 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { | |
308 MX_I2C1_TestAndClear(); // do it a second time | |
309 } | |
310 MX_I2C1_Init(); | |
311 } | |
38 | 312 |
89 | 313 //dangerous: TM_OTP_Write(0,0, 0x01); |
38 | 314 #ifdef REGULAR_RUN |
89 | 315 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); |
316 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
317 if (global.I2C_SystemStatus != HAL_OK) { | |
318 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { | |
319 MX_I2C1_TestAndClear(); // do it a second time | |
320 } | |
321 MX_I2C1_Init(); | |
322 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); | |
323 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
324 } | |
38 | 325 |
89 | 326 global.dataSendToMaster.sensorErrors = |
327 global.sensorError[SENSOR_PRESSURE_ID]; | |
328 init_surface_ring(); | |
329 init_battery_gas_gauge(); | |
330 HAL_Delay(10); | |
331 battery_gas_gauge_get_data(); | |
38 | 332 // battery_gas_gauge_set(0); |
333 | |
89 | 334 global.lifeData.battery_voltage = get_voltage(); |
335 global.lifeData.battery_charge = get_charge(); | |
336 copyBatteryData(); | |
38 | 337 |
89 | 338 MX_SPI3_Init(); |
339 if (!scheduleSetButtonResponsiveness()) { | |
340 HAL_Delay(1); | |
341 scheduleSetButtonResponsiveness(); // init | |
342 HAL_Delay(1); | |
343 if (!scheduleSetButtonResponsiveness()) // send again, if problem it's not my problem here. | |
344 { | |
345 HAL_Delay(1); | |
346 scheduleSetButtonResponsiveness(); // init | |
347 HAL_Delay(1); | |
348 } | |
349 } | |
38 | 350 |
89 | 351 ADCx_Init(); |
352 GPIO_Power_MainCPU_Init(); | |
353 global.mode = MODE_POWERUP; | |
38 | 354 #else |
89 | 355 init_pressure(); |
356 init_surface_ring(); | |
38 | 357 |
89 | 358 ADCx_Init(); |
359 GPIO_Power_MainCPU_Init(); | |
360 global.mode = MODE_TEST; | |
38 | 361 #endif |
89 | 362 while (1) { |
120 | 363 /* printf("Global mode = %d\n", global.mode); */ |
38 | 364 |
89 | 365 switch (global.mode) { |
366 case MODE_POWERUP: | |
367 case MODE_BOOT: | |
368 // ReInit_battery_charger_status_pins(); | |
369 compass_init(0, 7); | |
370 accelerator_init(); | |
181 | 371 |
89 | 372 if (global.mode == MODE_BOOT) { |
373 GPIO_Power_MainCPU_OFF(); | |
374 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); | |
375 GPIO_Power_MainCPU_ON(); | |
376 } | |
377 SPI_synchronize_with_Master(); | |
378 MX_DMA_Init(); | |
379 MX_SPI1_Init(); | |
134
0586ae83a243
Removed cyclic (by timer) send on slave side
Ideenmodellierer
parents:
120
diff
changeset
|
380 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ |
207 | 381 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
89 | 382 EXTI_Test_Button_Init(); |
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 if (hasExternalClock()) | |
452 SystemClock_Config_HSI(); | |
453 sleep_prepare(); | |
38 | 454 |
89 | 455 GPIO_LED_Init(); |
38 | 456 |
89 | 457 scheduleSleepMode(); |
458 if (hasExternalClock()) | |
459 SystemClock_Config_HSE(); | |
460 GPIO_LED_Init(); | |
461 EXTI_Wakeup_Button_DeInit(); | |
462 ADCx_Init(); | |
463 GPIO_Power_MainCPU_Init(); | |
464 GPIO_Power_MainCPU_ON(); | |
465 compass_init(0, 7); | |
466 accelerator_init(); | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
467 SPI_synchronize_with_Master(); |
89 | 468 MX_DMA_Init(); |
469 MX_SPI1_Init(); | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
470 SPI_Start_single_TxRx_with_Master(); |
89 | 471 |
472 // EXTILine0_Button_DeInit(); not now, later after testing | |
473 break; | |
474 } | |
120 | 475 |
476 #ifdef DEBUG_RUNTIME | |
477 HAL_RTC_GetTime(&RTCHandle, &Stime, RTC_FORMAT_BCD); | |
478 | |
479 if(lastsecond == 0xFF) | |
480 { | |
481 measurementindex = 0; | |
482 loopcnt[measurementindex] = 0; | |
483 lastsecond = Stime.Seconds; | |
484 } | |
485 loopcnt[measurementindex]++; | |
486 | |
487 if(lastsecond != Stime.Seconds) | |
488 { | |
489 measurementindex++; | |
490 if (measurementindex == MEASURECNT) measurementindex = 0; | |
491 loopcnt[measurementindex] = 0; | |
492 lastsecond = Stime.Seconds; | |
493 if(measurementindex +1 < MEASURECNT) loopcnt[measurementindex +1] = 0xffff; /* helps to identify the latest value */ | |
494 } | |
495 #endif | |
89 | 496 } |
38 | 497 } |
498 | |
499 /** @brief Button feedback - EXTI line detection callbacks | |
500 * @param GPIO_Pin: Specifies the pins connected EXTI line | |
501 * @retval None | |
502 */ | |
89 | 503 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
38 | 504 |
89 | 505 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { |
506 if (global.mode == MODE_SLEEP) { | |
507 global.mode = MODE_BOOT; | |
508 } | |
509 } | |
510 else | |
511 if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) { | |
512 if (!global.demo_mode && (global.mode == MODE_SURFACE)) { | |
513 global.demo_mode = 1; | |
514 global.mode = MODE_DIVE; | |
515 } else if (global.demo_mode && (global.mode == MODE_DIVE) | |
516 && (global.lifeData.dive_time_seconds > 10)) { | |
517 global.demo_mode = 0; | |
518 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
519 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
520 } | |
521 } | |
38 | 522 } |
523 | |
524 /** | |
525 * @brief System Clock Configuration | |
526 * The system Clock is configured as follow : | |
527 * System Clock source = PLL (HSI) | |
528 * SYSCLK(Hz) = 100 MHz | |
529 * HCLK(Hz) = 100 MHz | |
530 * AHB Prescaler = 1 | |
531 * APB1 Prescaler = 2 | |
532 * APB2 Prescaler = 1 | |
533 * HSI Frequency(Hz) = 16 MHz | |
534 * PLL_M = 16 | |
535 * PLL_N = 400 | |
536 * PLL_P = 4 | |
537 * PLL_Q = 7 // no USB | |
538 * VDD(V) = 3.3 | |
539 * Main regulator output voltage = Scale1 mode | |
540 * Flash Latency(WS) = 3 | |
541 * @param None | |
542 * @retval None | |
543 */ | |
544 | |
89 | 545 void SystemClock_Config(void) { |
546 if (hasExternalClock()) | |
547 SystemClock_Config_HSE(); | |
548 else | |
549 SystemClock_Config_HSI(); | |
38 | 550 } |
551 | |
89 | 552 void SYSCLKConfig_STOP(void) { |
553 SYSCLKConfig_STOP_HSI(); | |
38 | 554 } |
555 | |
89 | 556 void SystemClock_Config_HSE(void) { |
557 RCC_OscInitTypeDef RCC_OscInitStruct; | |
558 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
38 | 559 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; |
560 | |
89 | 561 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); |
38 | 562 |
89 | 563 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); |
38 | 564 |
89 | 565 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; |
566 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
567 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
568 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
569 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
570 RCC_OscInitStruct.PLL.PLLM = 8; | |
571 RCC_OscInitStruct.PLL.PLLN = 320; | |
572 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
573 RCC_OscInitStruct.PLL.PLLQ = 4; | |
574 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 575 |
89 | 576 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
577 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
578 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
579 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
580 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
581 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
582 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 583 |
584 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
585 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
586 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
587 | |
588 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); | |
589 | |
590 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); | |
591 | |
89 | 592 /* SysTick_IRQn interrupt configuration */ |
38 | 593 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
594 } | |
595 | |
89 | 596 void SystemClock_Config_HSI(void) { |
597 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
598 RCC_OscInitTypeDef RCC_OscInitStruct; | |
38 | 599 |
89 | 600 /* Enable Power Control clock */ |
601 __HAL_RCC_PWR_CLK_ENABLE(); | |
38 | 602 |
89 | 603 /* The voltage scaling allows optimizing the power consumption when the device is |
604 clocked below the maximum system frequency, to update the voltage scaling value | |
605 regarding system frequency refer to product datasheet. */ | |
606 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); | |
38 | 607 |
89 | 608 /* Enable HSI Oscillator and activate PLL with HSI as source */ |
609 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
610 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
611 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
612 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
613 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
614 RCC_OscInitStruct.PLL.PLLM = 16; | |
615 RCC_OscInitStruct.PLL.PLLN = 320; | |
616 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
617 RCC_OscInitStruct.PLL.PLLQ = 4; | |
618 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 619 |
89 | 620 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
621 clocks dividers */ | |
622 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
623 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | |
624 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
625 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
626 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
627 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
628 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 629 } |
630 /* | |
631 RCC_OscInitTypeDef RCC_OscInitStruct; | |
632 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
633 | |
634 __HAL_RCC_PWR_CLK_ENABLE(); | |
635 | |
636 //__PWR_CLK_ENABLE(); | |
637 | |
638 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); | |
639 | |
640 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE; | |
641 RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
642 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
643 RCC_OscInitStruct.HSICalibrationValue = 16; | |
644 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
645 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
646 RCC_OscInitStruct.PLL.PLLM = 16; | |
647 RCC_OscInitStruct.PLL.PLLN = 320; | |
648 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
649 RCC_OscInitStruct.PLL.PLLQ = 4; | |
650 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
651 | |
652 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; | |
653 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
654 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
655 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
656 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
657 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
658 } | |
659 | |
660 static void RtcClock_Config(void) | |
661 { | |
662 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; | |
663 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
664 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
665 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
666 } | |
667 */ | |
668 | |
669 /** | |
670 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL | |
671 * and select PLL as system clock source. | |
672 * @param None | |
673 * @retval None | |
674 */ | |
89 | 675 void SYSCLKConfig_STOP_HSE(void) { |
676 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
677 RCC_OscInitTypeDef RCC_OscInitStruct; | |
678 uint32_t pFLatency = 0; | |
38 | 679 |
89 | 680 /* Get the Oscillators configuration according to the internal RCC registers */ |
681 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 682 |
89 | 683 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
684 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
685 RCC_OscInitStruct.HSIState = RCC_HSE_ON; | |
686 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
687 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 688 |
89 | 689 /* Get the Clocks configuration according to the internal RCC registers */ |
690 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 691 |
89 | 692 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
693 clocks dividers */ | |
694 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
695 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
696 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 697 } |
698 | |
89 | 699 void SYSCLKConfig_STOP_HSI(void) { |
700 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
701 RCC_OscInitTypeDef RCC_OscInitStruct; | |
702 uint32_t pFLatency = 0; | |
38 | 703 |
89 | 704 /* Get the Oscillators configuration according to the internal RCC registers */ |
705 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 706 |
89 | 707 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
708 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
709 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
710 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
711 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
712 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 713 |
89 | 714 /* Get the Clocks configuration according to the internal RCC registers */ |
715 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 716 |
89 | 717 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
718 clocks dividers */ | |
719 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
720 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
721 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 722 } |
723 | |
724 /** | |
725 * @brief SYSTICK callback | |
726 * @param None | |
727 * @retval None | |
728 */ | |
89 | 729 void HAL_SYSTICK_Callback(void) { |
730 HAL_IncTick(); | |
38 | 731 } |
732 | |
733 /** | |
734 * @brief Configures GPIO for LED | |
735 * Might move with STM32Cube usage | |
736 * @param None | |
737 * @retval None | |
738 */ | |
739 /* | |
740 void GPIO_test_I2C_lines(void) | |
741 { | |
742 GPIO_InitTypeDef GPIO_InitStructure; | |
743 __GPIOB_CLK_ENABLE(); | |
744 GPIO_InitStructure.Pin = GPIO_PIN_8; | |
745 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
746 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
747 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
748 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
749 GPIO_InitStructure.Pin = GPIO_PIN_9; | |
750 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
751 | |
752 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET); | |
753 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET); | |
754 HAL_Delay(10); | |
755 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET); | |
756 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | |
757 HAL_Delay(10); | |
758 } | |
759 */ | |
760 | |
89 | 761 static void GPIO_LED_Init(void) { |
762 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 763 |
89 | 764 __GPIOC_CLK_ENABLE(); |
765 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
766 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
767 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
768 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
769 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | |
38 | 770 } |
771 | |
89 | 772 void GPIO_new_DEBUG_Init(void) { |
38 | 773 #ifdef DEBUG_PIN_ACTIVE |
89 | 774 GPIO_InitTypeDef GPIO_InitStructure; |
38 | 775 |
89 | 776 __GPIOC_CLK_ENABLE(); |
777 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
778 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
779 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
780 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
781 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
38 | 782 #endif |
783 } | |
784 | |
89 | 785 void GPIO_new_DEBUG_LOW(void) { |
38 | 786 #ifdef DEBUG_PIN_ACTIVE |
89 | 787 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); |
38 | 788 #endif |
789 } | |
790 | |
89 | 791 void GPIO_new_DEBUG_HIGH(void) { |
38 | 792 #ifdef DEBUG_PIN_ACTIVE |
89 | 793 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); |
38 | 794 #endif |
795 } | |
796 | |
89 | 797 static void GPIO_Power_MainCPU_Init(void) { |
798 GPIO_InitTypeDef GPIO_InitStructure; | |
799 __GPIOC_CLK_ENABLE(); | |
800 GPIO_InitStructure.Pin = GPIO_PIN_0; | |
801 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
802 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
803 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
804 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | |
805 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); | |
38 | 806 } |
807 | |
89 | 808 static void GPIO_Power_MainCPU_ON(void) { |
809 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); | |
38 | 810 } |
811 | |
89 | 812 static void GPIO_Power_MainCPU_OFF(void) { |
813 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_SET); | |
38 | 814 } |
815 | |
816 /** | |
817 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | |
818 * @param None | |
819 * @retval None | |
820 */ | |
821 | |
89 | 822 static void EXTI_Wakeup_Button_Init(void) { |
823 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 824 |
89 | 825 __HAL_RCC_GPIOA_CLK_ENABLE(); |
826 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE(); | |
827 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | |
828 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
829 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
830 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | |
38 | 831 |
89 | 832 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0); |
833 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn); | |
38 | 834 } |
835 | |
89 | 836 static void EXTI_Wakeup_Button_DeInit(void) { |
837 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 838 |
89 | 839 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
840 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
841 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
38 | 842 |
89 | 843 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; |
844 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | |
845 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn); | |
38 | 846 } |
847 | |
89 | 848 static void EXTI_Test_Button_Init(void) { |
849 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 850 |
89 | 851 BUTTON_TEST_GPIO_CLK_ENABLE(); |
852 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | |
853 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
854 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
855 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | |
856 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0); | |
857 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn); | |
38 | 858 } |
859 | |
89 | 860 static void EXTI_Test_Button_DeInit(void) { |
861 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 862 |
89 | 863 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
864 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
865 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
38 | 866 |
89 | 867 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; |
868 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | |
869 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn); | |
38 | 870 } |
871 | |
872 /* NUCLEO C 13 | |
873 KEY_BUTTON_GPIO_CLK_ENABLE(); | |
874 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
875 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
876 GPIO_InitStructure.Pin = KEY_BUTTON_PIN; | |
877 HAL_GPIO_Init(KEY_BUTTON_GPIO_PORT, &GPIO_InitStructure); | |
878 HAL_NVIC_SetPriority(KEY_BUTTON_EXTI_IRQn, 2, 0); | |
879 HAL_NVIC_EnableIRQ(KEY_BUTTON_EXTI_IRQn); | |
880 */ | |
881 | |
882 /** | |
883 * @brief Wake Up Timer callback | |
884 * @param hrtc: RTC handle | |
885 * @retval None | |
886 */ | |
887 | |
888 /* | |
889 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) | |
890 { | |
891 static uint8_t uwCounter = 0; | |
892 uwCounter = 1; | |
893 } | |
894 */ | |
895 | |
89 | 896 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 897 |
898 } | |
899 | |
89 | 900 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 901 |
902 } | |
903 | |
89 | 904 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 905 |
906 } | |
907 | |
89 | 908 void sleep_prepare(void) { |
909 EXTI_Wakeup_Button_Init(); | |
910 /* | |
911 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
912 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
913 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
914 */ | |
915 compass_sleep(); | |
916 HAL_Delay(100); | |
917 accelerator_sleep(); | |
918 HAL_Delay(100); | |
38 | 919 |
89 | 920 I2C_DeInit(); |
921 MX_SPI_DeInit(); | |
922 MX_SPI3_DeInit(); | |
923 ADCx_DeInit(); | |
38 | 924 |
89 | 925 GPIO_InitTypeDef GPIO_InitStruct; |
38 | 926 |
89 | 927 __HAL_RCC_GPIOA_CLK_ENABLE(); |
928 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
929 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
930 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
38 | 931 |
89 | 932 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
933 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
934 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
935 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
936 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 937 #ifdef DEBUGMODE |
89 | 938 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ |
38 | 939 #endif |
89 | 940 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
38 | 941 |
89 | 942 GPIO_InitStruct.Pin = |
943 GPIO_PIN_All | |
944 ^ ( GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_14 | |
945 | GPIO_PIN_15); /* power off & charger in & charge out & OSC32*/ | |
946 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); | |
38 | 947 |
89 | 948 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); |
38 | 949 #ifdef DEBUGMODE |
89 | 950 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ |
38 | 951 #endif |
89 | 952 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct); |
38 | 953 |
89 | 954 GPIO_InitStruct.Pin = GPIO_PIN_All; |
955 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 956 |
89 | 957 GPIO_Power_MainCPU_OFF(); |
38 | 958 |
959 #ifndef DEBUGMODE | |
89 | 960 __HAL_RCC_GPIOB_CLK_DISABLE(); |
38 | 961 #endif |
89 | 962 __HAL_RCC_GPIOH_CLK_DISABLE(); |
38 | 963 |
89 | 964 HAL_Delay(1000); |
38 | 965 } |
966 | |
967 /* | |
968 void sleep_test(void) | |
969 { | |
970 GPIO_InitTypeDef GPIO_InitStruct; | |
971 | |
972 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
973 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
974 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
975 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
976 | |
977 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
978 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
979 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
980 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
981 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); | |
982 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
983 | |
984 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_15 | GPIO_PIN_14); | |
985 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
986 | |
987 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | |
988 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
989 | |
990 GPIO_Power_MainCPU_OFF(); | |
991 | |
992 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
993 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
994 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
995 | |
996 // __HAL_RCC_GPIOA_CLK_DISABLE(); | |
997 __HAL_RCC_GPIOB_CLK_DISABLE(); | |
998 // __HAL_RCC_GPIOC_CLK_DISABLE(); | |
999 __HAL_RCC_GPIOH_CLK_DISABLE(); | |
1000 | |
1001 | |
1002 HAL_Delay(5000); | |
1003 while(1) | |
1004 { | |
1005 RTC_StopMode_2seconds(); | |
1006 HAL_Delay(200); | |
1007 } | |
1008 } | |
1009 */ | |
1010 | |
1011 #ifdef USE_FULL_ASSERT | |
1012 | |
1013 /** | |
1014 * @brief Reports the name of the source file and the source line number | |
1015 * where the assert_param error has occurred. | |
1016 * @param file: pointer to the source file name | |
1017 * @param line: assert_param error line source number | |
1018 * @retval None | |
1019 */ | |
1020 void assert_failed(uint8_t* file, uint32_t line) | |
1021 { | |
89 | 1022 /* User can add his own implementation to report the file name and line number, |
1023 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
38 | 1024 |
89 | 1025 /* Infinite loop */ |
1026 while (1) | |
1027 { | |
1028 } | |
38 | 1029 } |
1030 #endif | |
1031 | |
1032 /** | |
1033 * @} | |
1034 */ | |
104 | 1035 /** |
1036 * @brief This function handles SysTick Handler. | |
1037 * @param None | |
1038 * @retval None | |
1039 */ | |
38 | 1040 |
104 | 1041 /*TxRx only here. Every 100 ms.*/ |
1042 uint8_t ticks100ms=0; | |
1043 void SysTick_Handler(void) | |
1044 { | |
1045 HAL_IncTick(); | |
1046 if(ticks100ms<100){ | |
1047 ticks100ms++; | |
1048 }else | |
1049 { | |
1050 ticks100ms=0; | |
1051 } | |
1052 } | |
38 | 1053 /** |
1054 * @} | |
1055 */ | |
1056 | |
1057 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |