annotate Small_CPU/Src/baseCPU2.c @ 310:95928ef3986f cleanup-4

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