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