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