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