Mercurial > public > ostc4
annotate Small_CPU/Src/baseCPU2.c @ 935:f2494a708f52 Evo_2_23
Added unit files for GPIO:
The new gpios need to be accessed from severall units. That's why the current, static implementation in the baseCPU did not fit. To enable global usage of the function they have been moved into new source / header file
author | Ideenmodellierer |
---|---|
date | Sun, 08 Dec 2024 21:59:22 +0100 |
parents | effadaa3a1f7 |
children | 3029f0332f4f |
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" | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
533
diff
changeset
|
144 #include "externalInterface.h" |
662 | 145 #include "uart.h" |
922 | 146 #include "uart_Internal.h" |
889 | 147 #include "GNSS.h" |
148 | |
38 | 149 |
150 // From Common/Inc: | |
151 #include "calc_crush.h" | |
152 #include "decom.h" | |
153 #include "FirmwareData.h" | |
154 | |
155 // From Common/Drivers/ | |
156 #include <stdio.h> | |
157 | |
889 | 158 |
433 | 159 uint8_t coldstart __attribute__((section (".noinit"))); |
160 | |
89 | 161 uint8_t hasExternalClock(void) { |
162 if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF)) | |
163 return 1; | |
164 else | |
165 return 0; | |
38 | 166 } |
167 | |
168 // SHALL LOAD AT 0x08000000 + 0x00005000 = 0x08005000. | |
169 // See CPU2-RTE.ld | |
100 | 170 const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") ))= { |
728
5143e927219f
Added sensor map to Firmware <=> RTE inferface:
Ideenmodellierer
parents:
713
diff
changeset
|
171 .versionFirst = 3, |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
890
diff
changeset
|
172 .versionSecond = 4, |
762 | 173 .versionThird = 0, |
843 | 174 .versionBeta = 1, |
38 | 175 |
89 | 176 /* 4 bytes with trailing 0 */ |
100 | 177 .signature = "mh", |
38 | 178 |
762 | 179 .release_year = 23, |
818 | 180 .release_month = 9, |
181 .release_day = 14, | |
100 | 182 .release_sub = 0, |
38 | 183 |
89 | 184 /* max 48 with trailing 0 */ |
185 //release_info ="12345678901234567890123456789012345678901" | |
768 | 186 .release_info = "stable April 2023", |
38 | 187 |
89 | 188 /* for safety reasons and coming functions */ |
189 .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND, | |
190 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ | |
433 | 191 .magic[3] = FIRMWARE_MAGIC_END |
192 }; | |
193 | |
38 | 194 |
89 | 195 uint8_t firmwareVersionHigh(void) { |
196 return cpu2_FirmwareData.versionFirst; | |
38 | 197 } |
198 | |
89 | 199 uint8_t firmwareVersionLow(void) { |
200 return cpu2_FirmwareData.versionSecond; | |
38 | 201 } |
202 | |
203 /** @addtogroup OSTC4 | |
204 * @{ | |
205 */ | |
206 | |
207 /** @addtogroup CPU2 | |
208 * @{ | |
209 */ | |
210 | |
211 /* Private typedef -----------------------------------------------------------*/ | |
212 /* Private define ------------------------------------------------------------*/ | |
213 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 | |
214 #define BUTTON_OSTC_GPIO_PORT GPIOA | |
215 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
216 #define BUTTON_OSTC_IRQn EXTI0_IRQn | |
217 | |
880 | 218 #define VIBRATION_CONTROL_PIN GPIO_PIN_3 /* PortA */ |
219 #define LED_CONTROL_PIN_RED GPIO_PIN_2 /* PortA */ | |
220 #define LED_CONTROL_PIN_GREEN GPIO_PIN_1 /* PortA */ | |
662 | 221 #define MAINCPU_CONTROL_PIN GPIO_PIN_0 /* PortC */ |
887 | 222 #define GPS_POWER_CONTROL_PIN GPIO_PIN_15 /* PortB */ |
223 #define GPS_BCKP_CONTROL_PIN GPIO_PIN_14 /* PortB */ | |
662 | 224 |
38 | 225 /* Private macro -------------------------------------------------------------*/ |
226 | |
227 /* Private variables ---------------------------------------------------------*/ | |
228 uint32_t global_test_time_counter = 0; | |
229 SBackup backup; | |
230 | |
231 /* Private function prototypes -----------------------------------------------*/ | |
232 static void EXTI_Wakeup_Button_Init(void); | |
233 static void EXTI_Wakeup_Button_DeInit(void); | |
234 | |
880 | 235 static void GPIO_LEDs_VIBRATION_Init(void); |
38 | 236 static void GPIO_Power_MainCPU_Init(void); |
237 static void GPIO_Power_MainCPU_ON(void); | |
238 static void GPIO_Power_MainCPU_OFF(void); | |
922 | 239 #ifdef ENABLE_GPIO_V2 |
880 | 240 static void GPIO_LED_RED_OFF(void); |
241 static void GPIO_LED_RED_ON(void); | |
242 static void GPIO_LED_GREEN_OFF(void); | |
243 static void GPIO_LED_GREEN_ON(void); | |
244 static void GPIO_VIBRATION_OFF(void); | |
245 static void GPIO_VIBRATION_ON(void); | |
887 | 246 static void GPIO_GPS_OFF(void); |
247 static void GPIO_GPS_ON(void); | |
248 static void GPIO_GPS_BCKP_OFF(void); | |
249 static void GPIO_GPS_BCKP_ON(void); | |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
250 #endif |
183 | 251 #ifdef DEBUG_I2C_LINES |
38 | 252 void GPIO_test_I2C_lines(void); |
183 | 253 #endif |
38 | 254 |
255 void sleep_prepare(void); | |
256 | |
257 void SystemClock_Config(void); | |
258 void SystemClock_Config_HSI(void); | |
259 void SystemClock_Config_HSE(void); | |
260 void SYSCLKConfig_STOP_HSI(void); | |
261 void SYSCLKConfig_STOP_HSE(void); | |
262 | |
263 void GPIO_new_DEBUG_Init(void); | |
264 void GPIO_new_DEBUG_LOW(void); | |
265 void GPIO_new_DEBUG_HIGH(void); | |
266 | |
267 #define REGULAR_RUN | |
268 | |
89 | 269 int __io_putchar(int ch) { |
270 ITM_SendChar(ch); | |
271 return ch; | |
38 | 272 } |
273 | |
274 /* Private functions ---------------------------------------------------------*/ | |
275 | |
276 /** | |
277 * @brief Main program | |
278 * @param None | |
279 * @retval None | |
280 */ | |
120 | 281 /* #define DEBUG_RUNTIME TRUE */ |
282 #ifdef DEBUG_RUNTIME | |
283 #define MEASURECNT 60 /* number of measuremets to be stored */ | |
284 static uint32_t loopcnt[MEASURECNT]; | |
285 extern RTC_HandleTypeDef RTCHandle; | |
286 #endif | |
38 | 287 |
89 | 288 int main(void) { |
120 | 289 |
290 #ifdef DEBUG_RUNTIME | |
291 RTC_TimeTypeDef Stime; | |
292 uint8_t measurementindex = 0; | |
293 uint8_t lastsecond = 0xFF; | |
294 #endif | |
295 | |
917
0d6c4b40fae4
Bugfix external interface power up after sleep:
Ideenmodellierer
parents:
909
diff
changeset
|
296 uint8_t extInterfaceActive = 0; |
0d6c4b40fae4
Bugfix external interface power up after sleep:
Ideenmodellierer
parents:
909
diff
changeset
|
297 |
89 | 298 HAL_Init(); |
299 SystemClock_Config(); | |
38 | 300 |
89 | 301 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
302 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK); | |
303 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); | |
38 | 304 |
89 | 305 MX_RTC_init(); |
880 | 306 GPIO_LEDs_VIBRATION_Init(); |
89 | 307 GPIO_new_DEBUG_Init(); // added 170322 hw |
308 initGlobals(); | |
38 | 309 |
120 | 310 /* printf("CPU2-RTE running...\n"); */ |
38 | 311 |
329 | 312 HAL_Delay(100); |
313 | |
89 | 314 MX_I2C1_Init(); |
329 | 315 if (global.I2C_SystemStatus != HAL_OK) |
316 { | |
89 | 317 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { |
318 MX_I2C1_TestAndClear(); // do it a second time | |
319 } | |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
320 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
321 I2C_DeInit(); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
322 HAL_Delay(100); |
89 | 323 MX_I2C1_Init(); |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
324 HAL_Delay(100); |
89 | 325 } |
38 | 326 |
329 | 327 |
328 | |
89 | 329 //dangerous: TM_OTP_Write(0,0, 0x01); |
38 | 330 #ifdef REGULAR_RUN |
89 | 331 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); |
332 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
329 | 333 if (global.I2C_SystemStatus != HAL_OK) |
334 { | |
89 | 335 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { |
336 MX_I2C1_TestAndClear(); // do it a second time | |
337 } | |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
338 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
339 I2C_DeInit(); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
340 HAL_Delay(100); |
89 | 341 MX_I2C1_Init(); |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
342 HAL_Delay(100); |
89 | 343 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); |
344 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
345 } | |
38 | 346 |
89 | 347 global.dataSendToMaster.sensorErrors = |
348 global.sensorError[SENSOR_PRESSURE_ID]; | |
329 | 349 |
350 if(is_init_pressure_done()) | |
351 { | |
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
|
352 init_surface_ring(0); |
329 | 353 } |
89 | 354 init_battery_gas_gauge(); |
355 HAL_Delay(10); | |
356 battery_gas_gauge_get_data(); | |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
357 |
662 | 358 global.lifeData.battery_voltage = get_voltage(); |
359 global.lifeData.battery_charge = get_charge(); | |
360 copyBatteryData(); | |
361 | |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
362 MX_SPI3_Init(); |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
363 |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
364 if(coldstart != 0xA5) /* Not reading a 0xA5 means the memory cells has not been initialized before => cold start */ |
433 | 365 { |
366 coldstart = 0xA5; | |
662 | 367 |
368 set_charge_state(Charger_ColdStart); | |
369 | |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
370 global.dataSendToMaster.power_on_reset = 1; |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
371 global.deviceDataSendToMaster.power_on_reset = 1; |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
372 |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
373 if (!scheduleSetButtonResponsiveness()) |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
374 { |
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
762
diff
changeset
|
375 HAL_Delay(10); |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
376 if (!scheduleSetButtonResponsiveness()) // send again, if problem it's not my problem here. |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
377 { |
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
762
diff
changeset
|
378 HAL_Delay(10); |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
379 scheduleSetButtonResponsiveness(); // init |
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
762
diff
changeset
|
380 HAL_Delay(10); |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
381 } |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
382 } |
433 | 383 } |
662 | 384 else |
385 { | |
386 set_charge_state(Charger_NotConnected); | |
387 } | |
38 | 388 |
89 | 389 ADCx_Init(); |
390 GPIO_Power_MainCPU_Init(); | |
662 | 391 |
392 externalInterface_InitPower33(); | |
393 | |
89 | 394 global.mode = MODE_POWERUP; |
38 | 395 #else |
89 | 396 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
|
397 init_surface_ring(0); |
38 | 398 |
89 | 399 ADCx_Init(); |
400 GPIO_Power_MainCPU_Init(); | |
401 global.mode = MODE_TEST; | |
38 | 402 #endif |
89 | 403 while (1) { |
120 | 404 /* printf("Global mode = %d\n", global.mode); */ |
38 | 405 |
89 | 406 switch (global.mode) { |
407 case MODE_POWERUP: | |
408 case MODE_BOOT: | |
409 // ReInit_battery_charger_status_pins(); | |
410 compass_init(0, 7); | |
411 accelerator_init(); | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
533
diff
changeset
|
412 externalInterface_Init(); |
181 | 413 |
89 | 414 if (global.mode == MODE_BOOT) { |
415 GPIO_Power_MainCPU_OFF(); | |
922 | 416 #ifdef ENABLE_GPIO_V2 |
880 | 417 GPIO_LED_GREEN_ON(); |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
418 #endif |
89 | 419 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); |
420 GPIO_Power_MainCPU_ON(); | |
922 | 421 #ifdef ENABLE_GPIO_V2 |
880 | 422 GPIO_LED_GREEN_OFF(); |
423 | |
424 GPIO_LED_RED_ON(); | |
900 | 425 GPIO_VIBRATION_ON(); |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
426 #endif |
880 | 427 HAL_Delay(100); |
922 | 428 #ifdef ENABLE_GPIO_V2 |
880 | 429 GPIO_LED_RED_OFF(); |
430 GPIO_VIBRATION_OFF(); | |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
431 #endif |
89 | 432 } |
922 | 433 #ifdef ENABLE_GPIO_V2 |
900 | 434 GPIO_LED_RED_OFF(); |
435 GPIO_LED_GREEN_OFF(); | |
436 GPIO_VIBRATION_OFF(); | |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
437 #endif |
89 | 438 SPI_synchronize_with_Master(); |
439 MX_DMA_Init(); | |
440 MX_SPI1_Init(); | |
134
0586ae83a243
Removed cyclic (by timer) send on slave side
Ideenmodellierer
parents:
120
diff
changeset
|
441 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ |
207 | 442 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
889 | 443 |
922 | 444 #ifdef ENABLE_GPIO_V2 |
889 | 445 // GNSS tests |
446 GNSS_IO_init(); | |
900 | 447 GPIO_GPS_ON(); |
448 GPIO_GPS_BCKP_ON(); | |
889 | 449 MX_USART6_UART_Init(); |
450 GNSS_Init(&GNSS_Handle, &huart6); | |
932 | 451 #else |
452 #ifdef ENABLE_GNSS_SUPPORT | |
453 GNSS_Init(&GNSS_Handle, &huart1); | |
454 #endif | |
900 | 455 #endif |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
890
diff
changeset
|
456 |
890
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
457 /* |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
458 * Demo code from SimpleMethod |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
459 * called 1/second |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
460 while (1) { |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
461 |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
462 if ((HAL_GetTick() - Timer) > 1000) { |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
463 GNSS_GetUniqID(&GNSS_Handle); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
464 GNSS_ParseBuffer(&GNSS_Handle); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
465 HAL_Delay(250); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
466 GNSS_GetPVTData(&GNSS_Handle); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
467 GNSS_ParseBuffer(&GNSS_Handle); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
468 printf("Day: %d-%d-%d \r\n", GNSS_Handle.day, GNSS_Handle.month,GNSS_Handle.year); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
469 printf("Time: %d:%d:%d \r\n", GNSS_Handle.hour, GNSS_Handle.min,GNSS_Handle.sec); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
470 printf("Status of fix: %d \r\n", GNSS_Handle.fixType); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
471 printf("Latitude: %f \r\n", GNSS_Handle.fLat); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
472 printf("Longitude: %f \r\n",(float) GNSS_Handle.lon / 10000000.0); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
473 printf("Height above ellipsoid: %d \r\n", GNSS_Handle.height); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
474 printf("Height above mean sea level: %d \r\n", GNSS_Handle.hMSL); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
475 printf("Ground Speed (2-D): %d \r\n", GNSS_Handle.gSpeed); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
476 printf("Unique ID: %04X %04X %04X %04X %04X \n\r", |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
477 GNSS_Handle.uniqueID[0], GNSS_Handle.uniqueID[1], |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
478 GNSS_Handle.uniqueID[2], GNSS_Handle.uniqueID[3], |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
479 GNSS_Handle.uniqueID[4], GNSS_Handle.uniqueID[5]); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
480 Timer = HAL_GetTick(); |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
481 } |
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
482 */ |
889 | 483 |
89 | 484 global.mode = MODE_SURFACE; |
485 break; | |
38 | 486 |
89 | 487 case MODE_CALIB: |
90 | 488 scheduleCompassCalibrationMode(); |
89 | 489 break; |
490 | |
491 case MODE_SURFACE: | |
492 scheduleSurfaceMode(); | |
493 break; | |
38 | 494 |
89 | 495 case MODE_TEST: |
496 break; | |
38 | 497 |
89 | 498 case MODE_DIVE: |
90 | 499 backup.no_fly_time_minutes = global.no_fly_time_minutes; |
500 backup.seconds_since_last_dive = global.seconds_since_last_dive; | |
501 | |
502 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive, | |
503 global.seconds_since_last_dive ); | |
504 global.no_fly_time_minutes = 0; | |
505 global.lifeData.dive_time_seconds = 0; | |
506 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
507 scheduleDiveMode(); | |
508 // done now in scheduler prior to change mode: global.seconds_since_last_dive = 1; | |
509 | |
510 if( global.lifeData.dive_time_seconds > 60 ) | |
511 { | |
512 //No Fly time 60% of desaturationtime after dive | |
513 global.no_fly_time_minutes = decom_calc_desaturation_time( | |
514 global.lifeData.tissue_nitrogen_bar, | |
515 global.lifeData.tissue_helium_bar, | |
516 global.lifeData.pressure_surface_bar ) * 60 / 100; | |
517 if( global.no_fly_time_minutes < (24 * 60) ) | |
518 global.no_fly_time_minutes = 24 * 60; | |
519 } | |
520 else | |
521 { | |
522 global.no_fly_time_minutes = backup.no_fly_time_minutes; | |
523 global.seconds_since_last_dive = backup.seconds_since_last_dive; | |
524 } | |
525 | |
526 global.lifeData.dive_time_seconds = 0; | |
527 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
528 global.lifeData.counterSecondsShallowDepth = 0; | |
529 | |
530 backup.no_fly_time_minutes = 0; | |
531 backup.seconds_since_last_dive = 0; | |
89 | 532 break; |
38 | 533 |
89 | 534 case MODE_SHUTDOWN: |
535 HAL_Delay(200); | |
536 global.mode = MODE_SLEEP; | |
537 MX_SPI3_Init(); | |
538 break; | |
539 | |
540 case MODE_SLEEP: | |
917
0d6c4b40fae4
Bugfix external interface power up after sleep:
Ideenmodellierer
parents:
909
diff
changeset
|
541 extInterfaceActive = externalInterface_isEnabledPower33(); |
839 | 542 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); |
662 | 543 externalInterface_SwitchPower33(false); |
89 | 544 if (hasExternalClock()) |
545 SystemClock_Config_HSI(); | |
887 | 546 GPIO_LEDs_VIBRATION_Init(); |
89 | 547 sleep_prepare(); |
38 | 548 |
89 | 549 scheduleSleepMode(); |
550 if (hasExternalClock()) | |
551 SystemClock_Config_HSE(); | |
552 EXTI_Wakeup_Button_DeInit(); | |
553 ADCx_Init(); | |
554 GPIO_Power_MainCPU_Init(); | |
555 GPIO_Power_MainCPU_ON(); | |
556 compass_init(0, 7); | |
557 accelerator_init(); | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
558 SPI_synchronize_with_Master(); |
89 | 559 MX_DMA_Init(); |
560 MX_SPI1_Init(); | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
561 SPI_Start_single_TxRx_with_Master(); |
89 | 562 |
917
0d6c4b40fae4
Bugfix external interface power up after sleep:
Ideenmodellierer
parents:
909
diff
changeset
|
563 if(extInterfaceActive) |
662 | 564 { |
565 externalInterface_SwitchPower33(true); | |
566 } | |
738
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
728
diff
changeset
|
567 externalInterface_InitDatastruct(); |
89 | 568 // EXTILine0_Button_DeInit(); not now, later after testing |
569 break; | |
570 } | |
120 | 571 |
572 #ifdef DEBUG_RUNTIME | |
573 HAL_RTC_GetTime(&RTCHandle, &Stime, RTC_FORMAT_BCD); | |
574 | |
575 if(lastsecond == 0xFF) | |
576 { | |
577 measurementindex = 0; | |
578 loopcnt[measurementindex] = 0; | |
579 lastsecond = Stime.Seconds; | |
580 } | |
581 loopcnt[measurementindex]++; | |
582 | |
583 if(lastsecond != Stime.Seconds) | |
584 { | |
585 measurementindex++; | |
586 if (measurementindex == MEASURECNT) measurementindex = 0; | |
587 loopcnt[measurementindex] = 0; | |
588 lastsecond = Stime.Seconds; | |
589 if(measurementindex +1 < MEASURECNT) loopcnt[measurementindex +1] = 0xffff; /* helps to identify the latest value */ | |
590 } | |
591 #endif | |
89 | 592 } |
38 | 593 } |
594 | |
595 /** @brief Button feedback - EXTI line detection callbacks | |
596 * @param GPIO_Pin: Specifies the pins connected EXTI line | |
597 * @retval None | |
598 */ | |
89 | 599 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
38 | 600 |
89 | 601 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { |
602 if (global.mode == MODE_SLEEP) { | |
603 global.mode = MODE_BOOT; | |
604 } | |
605 } | |
606 else | |
880 | 607 { |
608 | |
89 | 609 } |
38 | 610 } |
611 | |
612 /** | |
613 * @brief System Clock Configuration | |
614 * The system Clock is configured as follow : | |
615 * System Clock source = PLL (HSI) | |
616 * SYSCLK(Hz) = 100 MHz | |
617 * HCLK(Hz) = 100 MHz | |
618 * AHB Prescaler = 1 | |
619 * APB1 Prescaler = 2 | |
620 * APB2 Prescaler = 1 | |
621 * HSI Frequency(Hz) = 16 MHz | |
622 * PLL_M = 16 | |
623 * PLL_N = 400 | |
624 * PLL_P = 4 | |
625 * PLL_Q = 7 // no USB | |
626 * VDD(V) = 3.3 | |
627 * Main regulator output voltage = Scale1 mode | |
628 * Flash Latency(WS) = 3 | |
629 * @param None | |
630 * @retval None | |
631 */ | |
632 | |
89 | 633 void SystemClock_Config(void) { |
634 if (hasExternalClock()) | |
635 SystemClock_Config_HSE(); | |
636 else | |
637 SystemClock_Config_HSI(); | |
38 | 638 } |
639 | |
89 | 640 void SYSCLKConfig_STOP(void) { |
641 SYSCLKConfig_STOP_HSI(); | |
38 | 642 } |
643 | |
89 | 644 void SystemClock_Config_HSE(void) { |
645 RCC_OscInitTypeDef RCC_OscInitStruct; | |
646 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
38 | 647 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; |
648 | |
89 | 649 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); |
38 | 650 |
887 | 651 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
38 | 652 |
89 | 653 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; |
654 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
655 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
656 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
657 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
658 RCC_OscInitStruct.PLL.PLLM = 8; | |
659 RCC_OscInitStruct.PLL.PLLN = 320; | |
660 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
661 RCC_OscInitStruct.PLL.PLLQ = 4; | |
662 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 663 |
89 | 664 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
665 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
666 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
667 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
668 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
669 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
670 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 671 |
672 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
673 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
674 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
675 | |
676 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); | |
677 | |
678 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); | |
679 | |
89 | 680 /* SysTick_IRQn interrupt configuration */ |
38 | 681 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
682 } | |
683 | |
89 | 684 void SystemClock_Config_HSI(void) { |
685 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
686 RCC_OscInitTypeDef RCC_OscInitStruct; | |
38 | 687 |
89 | 688 /* Enable Power Control clock */ |
689 __HAL_RCC_PWR_CLK_ENABLE(); | |
38 | 690 |
89 | 691 /* The voltage scaling allows optimizing the power consumption when the device is |
692 clocked below the maximum system frequency, to update the voltage scaling value | |
693 regarding system frequency refer to product datasheet. */ | |
887 | 694 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
38 | 695 |
89 | 696 /* Enable HSI Oscillator and activate PLL with HSI as source */ |
697 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
698 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
699 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
700 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
701 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
702 RCC_OscInitStruct.PLL.PLLM = 16; | |
703 RCC_OscInitStruct.PLL.PLLN = 320; | |
704 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
705 RCC_OscInitStruct.PLL.PLLQ = 4; | |
706 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 707 |
89 | 708 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
709 clocks dividers */ | |
710 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
711 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | |
712 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
713 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
714 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
715 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
716 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 717 } |
718 | |
719 | |
720 /** | |
721 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL | |
722 * and select PLL as system clock source. | |
723 * @param None | |
724 * @retval None | |
725 */ | |
89 | 726 void SYSCLKConfig_STOP_HSE(void) { |
727 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
728 RCC_OscInitTypeDef RCC_OscInitStruct; | |
729 uint32_t pFLatency = 0; | |
38 | 730 |
89 | 731 /* Get the Oscillators configuration according to the internal RCC registers */ |
732 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 733 |
89 | 734 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
735 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
736 RCC_OscInitStruct.HSIState = RCC_HSE_ON; | |
737 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
738 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 739 |
89 | 740 /* Get the Clocks configuration according to the internal RCC registers */ |
741 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 742 |
89 | 743 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
744 clocks dividers */ | |
745 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
746 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
747 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 748 } |
749 | |
89 | 750 void SYSCLKConfig_STOP_HSI(void) { |
751 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
752 RCC_OscInitTypeDef RCC_OscInitStruct; | |
753 uint32_t pFLatency = 0; | |
38 | 754 |
89 | 755 /* Get the Oscillators configuration according to the internal RCC registers */ |
756 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 757 |
89 | 758 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
759 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
760 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
761 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
762 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
763 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 764 |
89 | 765 /* Get the Clocks configuration according to the internal RCC registers */ |
766 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 767 |
89 | 768 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
769 clocks dividers */ | |
770 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
771 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
772 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 773 } |
774 | |
775 /** | |
776 * @brief SYSTICK callback | |
777 * @param None | |
778 * @retval None | |
779 */ | |
89 | 780 void HAL_SYSTICK_Callback(void) { |
781 HAL_IncTick(); | |
38 | 782 } |
783 | |
784 /** | |
785 * @brief Configures GPIO for LED | |
786 * Might move with STM32Cube usage | |
787 * @param None | |
788 * @retval None | |
789 */ | |
790 /* | |
791 void GPIO_test_I2C_lines(void) | |
792 { | |
793 GPIO_InitTypeDef GPIO_InitStructure; | |
794 __GPIOB_CLK_ENABLE(); | |
795 GPIO_InitStructure.Pin = GPIO_PIN_8; | |
796 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
797 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
798 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
799 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
800 GPIO_InitStructure.Pin = GPIO_PIN_9; | |
801 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
802 | |
803 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET); | |
804 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET); | |
805 HAL_Delay(10); | |
806 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET); | |
807 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | |
808 HAL_Delay(10); | |
809 } | |
810 */ | |
811 | |
880 | 812 static void GPIO_LEDs_VIBRATION_Init(void) { |
89 | 813 GPIO_InitTypeDef GPIO_InitStructure; |
38 | 814 |
880 | 815 __GPIOA_CLK_ENABLE(); |
816 GPIO_InitStructure.Pin = LED_CONTROL_PIN_RED; | |
89 | 817 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
818 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
880 | 819 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; |
820 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); | |
909 | 821 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET); |
880 | 822 |
823 GPIO_InitStructure.Pin = LED_CONTROL_PIN_GREEN; | |
824 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
825 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
826 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
827 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); | |
909 | 828 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET); |
880 | 829 |
830 GPIO_InitStructure.Pin = VIBRATION_CONTROL_PIN; | |
831 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
832 GPIO_InitStructure.Pull = GPIO_PULLDOWN; | |
833 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
834 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); | |
909 | 835 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET); |
887 | 836 |
837 __GPIOB_CLK_ENABLE(); | |
838 GPIO_InitStructure.Pin = GPS_POWER_CONTROL_PIN; | |
839 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
840 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
841 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
842 HAL_GPIO_Init( GPIOB, &GPIO_InitStructure); | |
909 | 843 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET); |
887 | 844 |
845 GPIO_InitStructure.Pin = GPS_BCKP_CONTROL_PIN; | |
846 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
847 GPIO_InitStructure.Pull = GPIO_PULLDOWN; | |
848 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
849 HAL_GPIO_Init( GPIOB, &GPIO_InitStructure); | |
909 | 850 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_RESET); |
38 | 851 } |
852 | |
89 | 853 void GPIO_new_DEBUG_Init(void) { |
38 | 854 #ifdef DEBUG_PIN_ACTIVE |
89 | 855 GPIO_InitTypeDef GPIO_InitStructure; |
38 | 856 |
89 | 857 __GPIOC_CLK_ENABLE(); |
662 | 858 GPIO_InitStructure.Pin = LED_CONTROL_PIN; |
89 | 859 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
860 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
861 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
862 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
38 | 863 #endif |
864 } | |
865 | |
89 | 866 void GPIO_new_DEBUG_LOW(void) { |
38 | 867 #ifdef DEBUG_PIN_ACTIVE |
662 | 868 HAL_GPIO_WritePin(GPIOC,LED_CONTROL_PIN,GPIO_PIN_RESET); |
38 | 869 #endif |
870 } | |
871 | |
89 | 872 void GPIO_new_DEBUG_HIGH(void) { |
38 | 873 #ifdef DEBUG_PIN_ACTIVE |
662 | 874 HAL_GPIO_WritePin(GPIOC,LED_CONTROL_PIN,GPIO_PIN_SET); |
38 | 875 #endif |
876 } | |
877 | |
89 | 878 static void GPIO_Power_MainCPU_Init(void) { |
879 GPIO_InitTypeDef GPIO_InitStructure; | |
880 __GPIOC_CLK_ENABLE(); | |
662 | 881 GPIO_InitStructure.Pin = MAINCPU_CONTROL_PIN; |
89 | 882 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
883 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
884 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
885 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | |
662 | 886 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET); |
38 | 887 } |
888 | |
89 | 889 static void GPIO_Power_MainCPU_ON(void) { |
662 | 890 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET); |
38 | 891 } |
892 | |
89 | 893 static void GPIO_Power_MainCPU_OFF(void) { |
662 | 894 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_SET); |
38 | 895 } |
896 | |
922 | 897 #ifdef ENABLE_GPIO_V2 |
880 | 898 static void GPIO_LED_GREEN_ON(void) { |
899 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_RESET); | |
900 } | |
901 | |
902 static void GPIO_LED_GREEN_OFF(void) { | |
903 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET); | |
904 } | |
905 | |
906 static void GPIO_LED_RED_ON(void) { | |
907 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_RESET); | |
908 } | |
909 | |
910 static void GPIO_LED_RED_OFF(void) { | |
911 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET); | |
912 } | |
913 | |
914 static void GPIO_VIBRATION_ON(void) { | |
915 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_SET); | |
916 } | |
917 | |
918 static void GPIO_VIBRATION_OFF(void) { | |
919 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET); | |
920 } | |
921 | |
887 | 922 static void GPIO_GPS_ON(void) { |
923 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_RESET); | |
924 } | |
925 | |
926 static void GPIO_GPS_OFF(void) { | |
927 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET); | |
928 } | |
929 | |
930 static void GPIO_GPS_BCKP_ON(void) { | |
931 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_SET); | |
932 } | |
933 | |
934 static void GPIO_GPS_BCKP_OFF(void) { | |
935 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_RESET); | |
936 } | |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
937 #endif |
880 | 938 |
38 | 939 /** |
940 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | |
941 * @param None | |
942 * @retval None | |
943 */ | |
944 | |
89 | 945 static void EXTI_Wakeup_Button_Init(void) { |
946 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 947 |
89 | 948 __HAL_RCC_GPIOA_CLK_ENABLE(); |
949 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE(); | |
950 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | |
951 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
952 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
953 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | |
38 | 954 |
89 | 955 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0); |
956 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn); | |
38 | 957 } |
958 | |
89 | 959 static void EXTI_Wakeup_Button_DeInit(void) { |
960 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 961 |
89 | 962 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
963 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
964 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
38 | 965 |
89 | 966 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; |
967 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | |
968 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn); | |
38 | 969 } |
970 | |
971 /** | |
972 * @brief Wake Up Timer callback | |
973 * @param hrtc: RTC handle | |
974 * @retval None | |
975 */ | |
976 | |
977 /* | |
978 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) | |
979 { | |
980 static uint8_t uwCounter = 0; | |
981 uwCounter = 1; | |
982 } | |
983 */ | |
984 | |
89 | 985 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 986 |
987 } | |
988 | |
89 | 989 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 990 |
991 } | |
992 | |
89 | 993 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 994 |
995 } | |
996 | |
89 | 997 void sleep_prepare(void) { |
998 EXTI_Wakeup_Button_Init(); | |
662 | 999 |
89 | 1000 compass_sleep(); |
1001 HAL_Delay(100); | |
1002 accelerator_sleep(); | |
1003 HAL_Delay(100); | |
38 | 1004 |
89 | 1005 I2C_DeInit(); |
1006 MX_SPI_DeInit(); | |
1007 MX_SPI3_DeInit(); | |
1008 ADCx_DeInit(); | |
38 | 1009 |
89 | 1010 GPIO_InitTypeDef GPIO_InitStruct; |
38 | 1011 |
89 | 1012 __HAL_RCC_GPIOA_CLK_ENABLE(); |
1013 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
1014 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
1015 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
38 | 1016 |
89 | 1017 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
887 | 1018 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; |
89 | 1019 GPIO_InitStruct.Pull = GPIO_NOPULL; |
1020 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
1021 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 1022 #ifdef DEBUGMODE |
89 | 1023 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ |
38 | 1024 #endif |
887 | 1025 |
1026 GPIO_InitStruct.Pin = GPIO_PIN_All ^ (GPS_POWER_CONTROL_PIN | GPS_BCKP_CONTROL_PIN); | |
89 | 1027 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
38 | 1028 |
887 | 1029 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | EXT33V_CONTROL_PIN); /* power off & charger in & charge out & OSC32 & ext33Volt */ |
662 | 1030 |
89 | 1031 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); |
38 | 1032 |
887 | 1033 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | VIBRATION_CONTROL_PIN | LED_CONTROL_PIN_RED | LED_CONTROL_PIN_GREEN); |
38 | 1034 #ifdef DEBUGMODE |
89 | 1035 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ |
38 | 1036 #endif |
89 | 1037 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct); |
38 | 1038 |
89 | 1039 GPIO_InitStruct.Pin = GPIO_PIN_All; |
1040 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 1041 |
89 | 1042 GPIO_Power_MainCPU_OFF(); |
922 | 1043 #ifdef ENABLE_GPIO_V2 |
880 | 1044 GPIO_LED_GREEN_OFF(); |
1045 GPIO_LED_RED_OFF(); | |
887 | 1046 GPIO_VIBRATION_OFF(); |
1047 GPIO_GPS_BCKP_ON(); // mH : costs 100µA in sleep - beware | |
1048 GPIO_GPS_OFF(); | |
880 | 1049 |
890
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
1050 MX_USART6_UART_DeInit(); |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
1051 #endif |
38 | 1052 #ifndef DEBUGMODE |
89 | 1053 __HAL_RCC_GPIOB_CLK_DISABLE(); |
38 | 1054 #endif |
89 | 1055 __HAL_RCC_GPIOH_CLK_DISABLE(); |
38 | 1056 |
89 | 1057 HAL_Delay(1000); |
38 | 1058 } |
1059 | |
1060 /* | |
1061 void sleep_test(void) | |
1062 { | |
1063 GPIO_InitTypeDef GPIO_InitStruct; | |
1064 | |
1065 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
1066 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
1067 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
1068 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
1069 | |
1070 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
1071 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
1072 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
1073 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
1074 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); | |
1075 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
1076 | |
1077 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_15 | GPIO_PIN_14); | |
1078 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
1079 | |
1080 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | |
1081 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
1082 | |
1083 GPIO_Power_MainCPU_OFF(); | |
1084 | |
1085 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
1086 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
1087 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
1088 | |
1089 // __HAL_RCC_GPIOA_CLK_DISABLE(); | |
1090 __HAL_RCC_GPIOB_CLK_DISABLE(); | |
1091 // __HAL_RCC_GPIOC_CLK_DISABLE(); | |
1092 __HAL_RCC_GPIOH_CLK_DISABLE(); | |
1093 | |
1094 | |
1095 HAL_Delay(5000); | |
1096 while(1) | |
1097 { | |
1098 RTC_StopMode_2seconds(); | |
1099 HAL_Delay(200); | |
1100 } | |
1101 } | |
1102 */ | |
1103 | |
1104 #ifdef USE_FULL_ASSERT | |
1105 | |
1106 /** | |
1107 * @brief Reports the name of the source file and the source line number | |
1108 * where the assert_param error has occurred. | |
1109 * @param file: pointer to the source file name | |
1110 * @param line: assert_param error line source number | |
1111 * @retval None | |
1112 */ | |
1113 void assert_failed(uint8_t* file, uint32_t line) | |
1114 { | |
89 | 1115 /* User can add his own implementation to report the file name and line number, |
1116 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
38 | 1117 |
89 | 1118 /* Infinite loop */ |
1119 while (1) | |
1120 { | |
1121 } | |
38 | 1122 } |
1123 #endif | |
1124 | |
1125 /** | |
1126 * @} | |
1127 */ | |
104 | 1128 /** |
1129 * @brief This function handles SysTick Handler. | |
1130 * @param None | |
1131 * @retval None | |
1132 */ | |
38 | 1133 |
104 | 1134 /*TxRx only here. Every 100 ms.*/ |
1135 uint8_t ticks100ms=0; | |
1136 void SysTick_Handler(void) | |
1137 { | |
1138 HAL_IncTick(); | |
1139 if(ticks100ms<100){ | |
1140 ticks100ms++; | |
1141 }else | |
1142 { | |
1143 ticks100ms=0; | |
1144 } | |
1145 } | |
38 | 1146 /** |
1147 * @} | |
1148 */ | |
1149 | |
1150 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |