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