annotate Small_CPU/Src/baseCPU2.c @ 77:efc0e78e12c9

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