annotate BootLoader/Src/base_bootlader.c @ 25:97eafbcb81a9

FIX move bootloader SFirmwareData at fixed address 0x0800A000
author jdg@air
date Wed, 03 Jan 2018 01:40:59 +0100
parents e65d01b6a17e
children ea1003f63e44
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
2 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
3 * @copyright heinrichs weikamp
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
4 * @file base_bootlader.c
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
5 * @author heinrichs/weikamp, Christian Weikamp
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
6 * @date 26-February-2014
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
7 * @version V1.0.4
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
8 * @since 09-Jan-2016
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
9 * @brief The beginning of it all. main() is part of this.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
10 * + Do the inits for hardware
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
11 * + check for button press or update process reset trigger
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
12 * + Do the inits for sub-systems like menu, dive screen etc.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
13 * + Start IRQs
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
14 * + Start MainTasks not in IRQs
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
15 * @bug
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
16 * @warning
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
17 @verbatim
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
18
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
19 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
20 ##### bootloader specific #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
21 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
22
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
23 151130 chsw sleep on button3
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
24 (MX_tell_reset_logik_alles_ok() + DataEX_call() in endlos loop)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
25
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
26 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
27 ##### bootloader specific #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
28 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
29
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
30 Bootloader info is set right here in this file.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
31 The location is 0x0800A000 instead of 0x08050000 (firmware)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
32
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
33 on system reset (Menu Start Bootloader in firmware) the update process
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
34 is started automatically if no button is pressed
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
35
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
36 if the right button is pressed the bootloader menu is started
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
37
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
38 after update process (with update or empty) cleaning of EEPROM is started
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
39 afterwards the watchdog reset starts without activating the update process
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
40
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
41 bluetooth chip is started in tComm on start of the mini bootloader firmware
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
42
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
43 SMALLCPU_CSB_PIN must be re-set to 0 to communicate with small CPU / CPU2 / RTE
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
44
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
45 for RealTerm to send file / firmware, Delays has to be increased to 0
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
46
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
47 RTE update / SPI1 with DMA gave IBUSERR, now it is working fine :-) 150828
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
48 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
49 from standard firmware, parts might be invalid here:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
50 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
51 ##### IRQs #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
52 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
53 [..] The IRQs are very important and most functions should only run there.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
54
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
55 PreemptPriority are as follows
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
56 (#) 2 (low) sprintf _only_ here. Don't use in maintask or anywhere else.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
57 Called by Buttons und Timer3
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
58 Timer3 is 1/10 second
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
59 (#) 1 (mid) anything that should work while in IRQ2 like HalDelay(), VSYNC
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
60 and DMA2D Transfer Complete for housekeepingFrame();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
61 (#) 0 (high) _very very short_ interrupts like The HAL hardware part for
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
62 spi, uart, i2c.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
63
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
64 SubPriority within PreemptPriority give the order to execute.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
65 Introduced 30.Oct.14 as it used by several HAL examples.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
66 Three levelAmbients are available (2 low,1 mid,0 high)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
67
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
68 The STM32F4 has 4bits for IRQ levelAmbients, divided 2/2 in this code
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
69 with the NVIC_PRIORITYGROUP_2 setting.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
70
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
71 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
72 ##### MainTask #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
73 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
74 [..] For everthing slow without importance to be 'in time'.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
75 Like VPM and Buehlmann.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
76 No sprintf and probably no GFX_SetFramesTopBottom() stuff neither.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
77 If sprintf is called while sprintf is executed it blows up everything.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
78
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
79 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
80 ##### Frames / the external SDRAM #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
81 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
82 [..] The SDRAM is handled by getFrame() and releaseFrame().
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
83 Each frame with 800*480*2 Bytes.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
84 Be carefull to release every frame
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
85 otherwise there will be a memory leakage over time.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
86 housekeepingFrame() in the MainTask takes care of cleaning the frames.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
87 All frames are filled with 0x00. This will be transparent with color of
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
88 CLUT_Font020 (is CLUT 0) if the alpha is set for a 16bit pair.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
89 housekeepingFrame() delays the cleaning of frames still used as screen
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
90 buffer to prevent flickering.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
91
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
92 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
93 ##### Display #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
94 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
95 [..] There is a Top layer, Bottom layer and background color.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
96 All are perfectly alpha-blended by hardware.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
97
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
98 (#) top layer has 800x480 option function calls only
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
99 as it is not used for cursors here
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
100 (#) bottom layer has free size and start option to be used
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
101 for cursors (or sprites in the future ;-)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
102 (#) background only black in the moment.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
103 ToDo: Could be anything else for warnings etc.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
104 if needed
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
105
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
106 [..] Frame updates, switching and cursors is done with
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
107
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
108 (#) GFX_SetFramesTopBottom() and the subset
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
109 GFX_SetFrameTop() + GFX_SetFrameBottom()
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
110 Those do not change anything on the display but give commands to..
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
111 (#) GFX_change_LTDC() The only place that changes the pointer.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
112 This prevents erratic behaviour if several changes
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
113 are made within one refresh rate of the screen.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
114 Is called in IRQ by PD4 and HAL_GPIO_EXTI_IRQHandler
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
115 from VSYNC signal.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
116
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
117 [..] Content
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
118
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
119 (#) Colors by LookupTable only. This could be modified by
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
120 system settings in the future. (gfx_color.h/.c)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
121
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
122 (#) Text by text_multilinguage.h/.c with one char
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
123 necessary only starting from '\x80'
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
124 with automatic language switch by
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
125 selected_language in SSettings
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
126 see openEdit_Language() in tMenuEditSystem.c
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
127 Therefore there are differnent functions
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
128 for example:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
129 write_label_fix() for single char multilanguage
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
130 write_label_var() for strings that could include
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
131 multilanguage as well
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
132 see GFX_write_string() to get an overview of the controls
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
133 as well as the command list in gfx_engine.h
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
134 There is no clear before writing, text overlay is always on.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
135 Many options to have LargeFont.SmallFont for numbers etc.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
136
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
137 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
138 ##### Update, DualBoot and build-in FLASH memory usage #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
139 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
140 [..] Boot0 pin, Boot1/PB2 pin and BFB2 software bit control the behaviour.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
141 PB2 should be tied to GND.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
142 Boot0 == VDD -> bootloader on start, otherwise boot from Bank1 or Bank2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
143 depending on BFB2.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
144 Bank2 contains the Fonts and should contain a proper test code in future
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
145 Bank1 is the main code (Bank1 is 1 MB too, usage as of Oct. 14 is 200 KB)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
146 [..] Bootloader should be either UART or USB (on FS pins _only_)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
147 USB HS to FS like on the Eval board does not work.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
148 [..] Bootloader for the smaller CPU2 is implemented via the SPI used for DMA copy.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
149
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
150 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
151 ##### Connection to CPU2 (STM32F411 as of Oct.14 #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
152 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
153 [..] Connected via SPI and DMA for every purpose.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
154 two entire arrays are transfered for data security reasons
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
155 with respect to master (STM32F429) might interrupt internal
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
156 data copy in CPU2 (like hi byte, low byte, etc.).
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
157 [..] The entire life data is calculated in CPU2. Like tissues, CNS,...
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
158 Therefore the main unit is _not_ necessarily a Real Time system.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
159 Simulation on the main unit can be executed without disrupting life data.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
160 [..] SPI is triggered and timed by calling DataEX_call() in data_exchange_main.c
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
161 DataEX_copy_to_LifeData() does the transfer from buffer to variables used.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
162
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
163 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
164 ##### Menu, MenuEdit, Info #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
165 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
166 [..] tMenu.c, tMenuEdit.c and tInfo.c is the system used.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
167 logbook is part of Info not Menu.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
168 The Info Menu is accessed by button 'Back'
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
169 The regular Menu is accessed by button 'Enter'
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
170 [..] Menu content is kept in frame memory for fast access.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
171 There is no need to build pages if the 'Enter' button is pressed.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
172 This is in contrast to MenuEdit pages.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
173 [..] Button control for new pages (and pages in general) have to implemented
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
174 in tMenu.c, tMenuEdit.c or tInfo.c
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
175
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
176 [..] ToDo (Oct. 14) Timeout for menus via Timer3 / IRQ 2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
177
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
178 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
179 ##### specials #####
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
180 ==============================================================================
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
181 [..] There was code for vector graphics from great demos
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
182 (peridiummmm and jupiter) that can be fitted again
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
183
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
184 @endverbatim
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
185 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
186 * @attention
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
187 *
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
188 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
189 *
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
190 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
191 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
192
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
193 /* Includes ------------------------------------------------------------------*/
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
194 #include "base_bootloader.h"
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
195
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
196 // From Bootloader/Inc:
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
197 #include "tInfoBootloader.h"
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
198
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
199 // ?
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
200 #include "externLogbookFlash.h"
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
201 #include "firmwareEraseProgram.h"
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
202 #include "firmwareJumpToApplication.h"
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
203
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
204 // From Common/Inc:
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
205 #include "FirmwareData.h"
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
206
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
207 // From Common/Drivers:
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
208 #include "stm32f4xx_hal.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
209 #include "stm32f4xx_hal_rcc.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
210 #include "stm32f4xx_hal_flash_ex.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
211 #include "stm32f4xx_hal_wwdg.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
212
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
213 // From Discovery/Inc (shall be shared...)
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
214 #include "data_exchange_main.h"
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
215 #include "display.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
216 #include "gfx_engine.h"
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
217 #include "ostc.h"
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
218 #include "tComm.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
219 #include "tStructure.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
220
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
221 // From AC6 support:
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
222 #include <stdio.h>
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
223 #include <string.h> // for memcopy
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
224
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
225 /** @addtogroup OSTC 4
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
226 * @{
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
227 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
228
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
229 /* Private typedef -----------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
230 /* Private define ------------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
231 #define BUFFER_SIZE ((uint32_t)0x00177000)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
232 #define WRITE_READ_ADDR ((uint32_t)0x0000)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
233 #define REFRESH_COUNT ((uint32_t)0x0569) /* SDRAM refresh counter (90Mhz SD clock) */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
234
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
235 /* Private macro -------------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
236 /* Private variables ---------------------------------------------------------*/
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
237 uint8_t returnFromCommCleanUpRequest = 0;
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
238
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
239 const SFirmwareData bootloader_FirmwareData __attribute__(( section(".bootloader_firmware_data") )) =
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
240 {
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
241 .versionFirst = 1,
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
242 .versionSecond = 0,
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
243 .versionThird = 1,
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
244 .versionBeta = 1,
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
245
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
246 /* 4 bytes with trailing 0 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
247 .signature = "cw",
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
248
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
249 .release_year = 16,
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
250 .release_month = 4,
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
251 .release_day = 8,
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
252 .release_sub = 0,
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
253
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
254 /* max 48 with trailing 0 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
255 .release_info ="tComm with all",
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
256
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
257 /* for safety reasons and coming functions*/
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
258 .magic[0] = FIRMWARE_MAGIC_FIRST,
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
259 .magic[1] = FIRMWARE_MAGIC_SECOND,
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
260 .magic[2] = FIRMWARE_MAGIC_FIRMWARE, /* the magic byte */
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
261 .magic[3] = FIRMWARE_MAGIC_END
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
262 };
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
263
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
264
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
265 const SHardwareData HardwareData __attribute__((at(HARDWAREDATA_ADDRESS))) = {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
266
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
267 // first 52 bytes
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
268 .primarySerial = 0xFFFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
269 .primaryLicence = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
270 .revision8bit = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
271 .production_year = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
272 .production_month = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
273 .production_day = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
274 .production_bluetooth_name_set = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
275
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
276 .production_info = {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
277 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
278 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
279 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
280 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
281
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
282 // other 12 bytes (64 in total)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
283 .secondarySerial = 0xFFFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
284 .secondaryLicence = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
285 .secondaryReason8bit = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
286 .secondary_year = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
287 .secondary_month = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
288 .secondary_day = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
289 .secondary_bluetooth_name_set = 0xFF,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
290 .secondary_info = {0xFF,0xFF,0xFF,0xFF}
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
291 };
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
292
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
293
25
97eafbcb81a9 FIX move bootloader SFirmwareData at fixed address 0x0800A000
jdg@air
parents: 5
diff changeset
294 RTC_HandleTypeDef RtcHandle;
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
295 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
296 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
297
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
298 uint32_t time_before;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
299 uint32_t time_between;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
300 uint32_t time_after;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
301
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
302 /* SDRAM handler declaration */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
303 SDRAM_HandleTypeDef hsdram;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
304 FMC_SDRAM_TimingTypeDef SDRAM_Timing;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
305 FMC_SDRAM_CommandTypeDef command;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
306
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
307 FLASH_OBProgramInitTypeDef OBInit;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
308 FLASH_AdvOBProgramInitTypeDef AdvOBInit;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
309
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
310
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
311 /* Private variables with external access ------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
312
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
313 uint32_t globalStateID = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
314 uint8_t globalModeID = SURFMODE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
315 uint32_t time_without_button_pressed_deciseconds = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
316 uint8_t bootToBootloader = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
317
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
318 /* Private function prototypes -----------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
319
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
320 //static void LCD_ToggleFramebuffer(GFX_DrawCfgTypeDef *hconfig);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
321 //static void LCD_Config(GFX_DrawCfgTypeDef *hconfig);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
322 static void SystemClock_Config(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
323 static void Error_Handler(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
324
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
325 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
326 static void SDRAM_Config(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
327 //static void DualBoot(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
328 static void EXTILine_Buttons_Config(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
329 //static void RTC_init(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
330 static void TIM_init(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
331 static void TIM_BACKLIGHT_init(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
332 //static void TIM_BACKLIGHT_adjust(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
333 static void gotoSleep(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
334 uint8_t checkResetForFirmwareUpdate(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
335 void DeleteResetToFirmwareUpdateRegister(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
336 void reset_to_firmware_using_Watchdog(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
337 void reset_to_update_using_system_reset(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
338
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
339 //static void DualBootToBootloader(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
340
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
341 /* ITM Trace-------- ---------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
342 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
343 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
344 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
345 #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
346
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
347 #define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
348 #define TRCENA 0x01000000
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
349
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
350 struct __FILE { int handle; };
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
351 FILE __stdout;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
352 FILE __stdin;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
353
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
354 int fputc(int ch, FILE *f) {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
355 if (DEMCR & TRCENA) {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
356 while (ITM_Port32(0) == 0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
357 ITM_Port8(0) = ch;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
358 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
359 return(ch);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
360 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
361 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
362
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
363 /* Private functions ---------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
364
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
365 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
366 * @brief Main program
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
367 * @param None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
368 * @retval None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
369 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
370
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
371 void GPIO_test_I2C_lines(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
372 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
373 GPIO_InitTypeDef GPIO_InitStructure;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
374 __GPIOA_CLK_ENABLE();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
375 __GPIOG_CLK_ENABLE();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
376 GPIO_InitStructure.Pin = GPIO_PIN_7;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
377 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
378 GPIO_InitStructure.Pull = GPIO_PULLUP;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
379 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
380 HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
381 GPIO_InitStructure.Pin = GPIO_PIN_3;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
382 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
383
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
384 while(1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
385 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
386 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_SET);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
387 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_RESET);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
388 HAL_Delay(10);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
389 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_RESET);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
390 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_SET);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
391 HAL_Delay(10);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
392 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
393 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
394
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
395
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
396 int main(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
397 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
398
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
399 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
400 HAL_Init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
401 SystemClock_Config();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
402 GPIO_test_I2C_lines();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
403 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
404 uint32_t pLayerInvisible;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
405 uint32_t firmware_load_result;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
406 uint8_t magicbyte = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
407 uint8_t callForUpdate;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
408 uint8_t status = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
409 char textVersion[32];
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
410 uint8_t ptr;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
411 uint32_t pOffset;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
412
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
413 set_globalState(StBoot0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
414
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
415 HAL_Init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
416 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
417
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
418 /* feedback for the user
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
419 * aber sehr unsch�n beim Warmstart
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
420 * da das letzte Bild noch lange nachleuchtet */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
421 // MX_GPIO_Backlight_max_static_only_Init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
422
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
423
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
424 /* button press is only 40 to 50 us low */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
425 MX_GPIO_One_Button_only_Init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
426
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
427 uint32_t i = 500000;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
428
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
429 callForUpdate = __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
430
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
431 if(callForUpdate)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
432 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
433 i = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
434 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
435 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
436 if( (firmware_MainCodeIsProgammed() == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
437 || (hardwareDataGetPointer()->primarySerial == 0xFFFF)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
438 || (hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
439 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
440 i = 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
441 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
442 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
443 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
444 while(MX_GPIO_Read_The_One_Button() && i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
445 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
446 i--;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
447 __NOP();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
448 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
449 if(i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
450 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
451 i = 200000;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
452 while(!MX_GPIO_Read_The_One_Button() && i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
453 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
454 i--;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
455 __NOP();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
456 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
457 if(i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
458 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
459 i = 200000;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
460 while(MX_GPIO_Read_The_One_Button() && i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
461 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
462 i--;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
463 __NOP();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
464 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
465 if(i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
466 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
467 i = 200000;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
468 while(!MX_GPIO_Read_The_One_Button() && i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
469 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
470 i--;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
471 __NOP();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
472 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
473 if(i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
474 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
475 i = 200000;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
476 while(MX_GPIO_Read_The_One_Button() && i)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
477 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
478 i--;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
479 __NOP();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
480 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
481 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
482 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
483 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
484 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
485 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
486
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
487 if((i == 0) && (callForUpdate == 0))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
488 firmware_JumpTo_Application();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
489
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
490 SystemClock_Config();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
491
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
492 MX_GPIO_Init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
493 MX_Bluetooth_PowerOn();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
494 MX_SPI_Init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
495 SDRAM_Config();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
496 HAL_Delay(100);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
497
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
498 GFX_init1_no_DMA(&pLayerInvisible, 2);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
499
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
500 TIM_BACKLIGHT_init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
501
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
502 // -----------------------------
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
503
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
504 display_power_on__1_of_2__pre_RGB();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
505 GFX_LTDC_Init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
506 GFX_LTDC_LayerDefaultInit(TOP_LAYER, pLayerInvisible);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
507 GFX_LTDC_LayerDefaultInit(BACKGRD_LAYER, pLayerInvisible);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
508 GFX_SetFramesTopBottom(pLayerInvisible,pLayerInvisible,480);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
509 HAL_Delay(20);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
510 display_power_on__2_of_2__post_RGB();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
511
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
512 // -----------------------------
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
513 GFX_change_LTDC();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
514 GFX_hwBackgroundOn();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
515 GFX_change_LTDC();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
516 // -----------------------------
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
517 tInfoBootloader_init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
518 // -----------------------------
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
519 if(i == 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
520 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
521 tInfo_newpage("load firmware data");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
522 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
523 firmware_load_result = ext_flash_read_firmware(pBuffer,768000, &magicbyte);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
524
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
525 if((firmware_load_result > 0) && (firmware_load_result < 768000) && (magicbyte == 0xEE))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
526 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
527 ptr = ext_flash_read_firmware_version(textVersion);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
528 textVersion[ptr++] = 'f';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
529 textVersion[ptr++] = 'o';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
530 textVersion[ptr++] = 'u';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
531 textVersion[ptr++] = 'n';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
532 textVersion[ptr++] = 'd';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
533 textVersion[ptr] = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
534
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
535 tInfo_newpage(textVersion);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
536 tInfo_write("erase flash");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
537 status = firmware_eraseFlashMemory();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
538 if(status != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
539 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
540 tInfo_newpage("error. try again.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
541 status = firmware_eraseFlashMemory();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
542 if(status != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
543 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
544 tInfo_newpage("error. skip update.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
545 HAL_Delay(1000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
546 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
547 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
548 if(status == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
549 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
550 tInfo_write("programm flash");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
551 status = firmware_programFlashMemory(pBuffer,firmware_load_result);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
552 if(status != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
553 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
554 tInfo_newpage("error. try again.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
555 status = firmware_programFlashMemory(pBuffer,firmware_load_result);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
556 if(status != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
557 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
558 tInfo_newpage("error. skip update.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
559 HAL_Delay(1000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
560 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
561 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
562 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
563 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
564 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
565
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
566 /* here comes the variable upper firmware loader */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
567 if((i == 0) && (status == HAL_OK))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
568 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
569 tInfo_newpage("load firmware2 data");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
570 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
571 firmware_load_result = ext_flash_read_firmware2(&pOffset, pBuffer,768000*2,0,0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
572
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
573 if((firmware_load_result > 0) && (firmware_load_result + pOffset <= 1024000))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
574 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
575 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
576 ptr += gfx_number_to_string(7,0,&textVersion[ptr],firmware_load_result);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
577 textVersion[ptr++] = ' ';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
578 textVersion[ptr++] = 'b';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
579 textVersion[ptr++] = 'y';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
580 textVersion[ptr++] = 't';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
581 textVersion[ptr++] = 'e';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
582 textVersion[ptr++] = 's';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
583 textVersion[ptr++] = ' ';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
584 textVersion[ptr++] = 'w';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
585 textVersion[ptr++] = 'i';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
586 textVersion[ptr++] = 't';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
587 textVersion[ptr++] = 'h';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
588 textVersion[ptr++] = ' ';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
589 ptr += gfx_number_to_string(7,0,&textVersion[ptr],pOffset);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
590 textVersion[ptr++] = ' ';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
591 textVersion[ptr++] = 'o';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
592 textVersion[ptr++] = 'f';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
593 textVersion[ptr++] = 'f';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
594 textVersion[ptr++] = 's';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
595 textVersion[ptr++] = 'e';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
596 textVersion[ptr++] = 't';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
597 textVersion[ptr] = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
598 tInfo_newpage(textVersion);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
599
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
600 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
601 textVersion[ptr++] = 'f';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
602 textVersion[ptr++] = 'o';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
603 textVersion[ptr++] = 'u';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
604 textVersion[ptr++] = 'n';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
605 textVersion[ptr++] = 'd';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
606 textVersion[ptr] = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
607
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
608 tInfo_write(textVersion);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
609 tInfo_write("erase flash");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
610 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
611 if(status != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
612 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
613 tInfo_newpage("error. try again.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
614 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
615 if(status != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
616 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
617 tInfo_newpage("error. skip update.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
618 HAL_Delay(1000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
619 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
620 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
621 if(status == HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
622 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
623 tInfo_write("programm flash");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
624 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
625 if(status != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
626 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
627 tInfo_newpage("error. try again.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
628 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
629 if(status != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
630 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
631 tInfo_newpage("error. skip update.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
632 HAL_Delay(1000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
633 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
634 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
635 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
636 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
637 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
638
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
639 if((i == 0) && (status == HAL_OK))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
640 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
641 tInfo_newpage("Done.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
642 tInfo_write("Cleaning.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
643 ext_flash_erase_firmware_if_not_empty();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
644 ext_flash_erase_firmware2_if_not_empty();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
645 tInfo_write("Reset device.");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
646 reset_to_firmware_using_Watchdog();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
647 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
648
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
649 ptr = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
650 textVersion[ptr++] = '\021';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
651 textVersion[ptr++] = 's';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
652 textVersion[ptr++] = 'e';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
653 textVersion[ptr++] = 'r';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
654 textVersion[ptr++] = 'i';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
655 textVersion[ptr++] = 'a';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
656 textVersion[ptr++] = 'l';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
657 textVersion[ptr++] = ' ';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
658 if(HardwareData.primarySerial == 0xFFFF)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
659 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
660 textVersion[ptr++] = 'n';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
661 textVersion[ptr++] = 'o';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
662 textVersion[ptr++] = 't';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
663 textVersion[ptr++] = ' ';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
664 textVersion[ptr++] = 's';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
665 textVersion[ptr++] = 'e';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
666 textVersion[ptr++] = 't';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
667 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
668 else if(HardwareData.secondarySerial == 0xFFFF)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
669 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
670 textVersion[ptr++] = '#';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
671 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData.primarySerial);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
672 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
673 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
674 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
675 textVersion[ptr++] = '#';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
676 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData.secondarySerial);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
677 textVersion[ptr++] = ' ';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
678 textVersion[ptr++] = '(';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
679 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData.primarySerial);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
680 textVersion[ptr++] = ')';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
681 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
682 textVersion[ptr++] = '\020';
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
683 textVersion[ptr] = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
684
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
685 tInfo_button_text("Exit","","Sleep");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
686 tInfo_newpage("Bootloader 160602");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
687 tInfo_write("start bluetooth");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
688 tInfo_write("");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
689 tInfo_write(textVersion);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
690 tInfo_write("");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
691
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
692 TIM_init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
693 MX_UART_Init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
694 MX_Bluetooth_PowerOn();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
695 tComm_Set_Bluetooth_Name(0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
696
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
697 tComm_init();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
698 set_globalState_Base();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
699
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
700 GFX_start_VSYNC_IRQ();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
701
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
702 EXTILine_Buttons_Config();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
703 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
704 uint8_t* pBuffer1 = (uint8_t*)getFrame(20);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
705 firmware_load_result = ext_flash_read_firmware(pBuffer1,768000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
706
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
707 if((firmware_load_result > 0) && (firmware_load_result < 768000))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
708 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
709 firmware_eraseFlashMemory();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
710 firmware_programFlashMemory(pBuffer1,firmware_load_result);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
711 // not for testing
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
712 //ext_flash_erase_firmware_if_not_empty();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
713 reset_to_firmware_using_Watchdog();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
714 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
715 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
716 while(1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
717 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
718 // if(bootToBootloader)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
719 // DualBootToBootloader();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
720
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
721 if(bootToBootloader)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
722 reset_to_update_using_system_reset();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
723
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
724 tComm_control(); // will stop while loop if tComm Mode started until exit from UART
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
725 };
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
726 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
727
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
728
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
729 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
730 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
731
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
732 SStateList status;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
733
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
734 get_globalStateList(&status);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
735
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
736 switch(status.base)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
737 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
738 default:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
739 // TIM_BACKLIGHT_adjust();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
740 break;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
741 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
742
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
743 if(returnFromCommCleanUpRequest)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
744 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
745 tComm_exit();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
746 returnFromCommCleanUpRequest = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
747 GFX_hwBackgroundOn();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
748 tInfo_button_text("Exit","","Sleep");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
749 tInfo_newpage("bluetooth disonnected");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
750 tInfo_write("");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
751 tInfo_write("");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
752 tInfo_write("");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
753 tInfo_write("");
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
754 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
755
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
756 get_globalStateList(&status);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
757
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
758 switch(status.base)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
759 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
760 case BaseComm:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
761 if(get_globalState() == StUART_STANDARD)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
762 tComm_refresh();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
763 break;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
764 default:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
765 break;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
766 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
767 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
768
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
769 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
770 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
771 uint8_t action;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
772 SStateList status;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
773 static uint8_t counterToPreventSleep = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
774 if(GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
775 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
776 GFX_change_LTDC();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
777 housekeepingFrame();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
778 if(counterToPreventSleep < 250)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
779 counterToPreventSleep++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
780 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
781 if(counterToPreventSleep != 255)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
782 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
783 counterToPreventSleep = 255;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
784 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
785
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
786 return;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
787 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
788
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
789 time_without_button_pressed_deciseconds = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
790
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
791 if(GFX_logoStatus() != 0)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
792 return;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
793
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
794 if(GPIO_Pin == BUTTON_BACK_PIN) // links
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
795 action = ACTION_BUTTON_BACK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
796 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
797 if(GPIO_Pin == BUTTON_ENTER_PIN) // mitte
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
798 action = ACTION_BUTTON_ENTER;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
799 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
800 if(GPIO_Pin == BUTTON_NEXT_PIN) // rechts
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
801 action = ACTION_BUTTON_NEXT;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
802 #ifdef BUTTON_CUSTOM_PIN
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
803 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
804 if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
805 action = ACTION_BUTTON_CUSTOM;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
806 #endif
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
807 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
808 action = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
809 get_globalStateList(&status);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
810
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
811 switch(status.base)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
812 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
813 case BaseComm:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
814 if(action == ACTION_BUTTON_BACK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
815 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
816 reset_to_firmware_using_Watchdog();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
817 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
818 break;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
819
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
820 default:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
821 if((action == ACTION_BUTTON_NEXT) && (counterToPreventSleep == 255) && (get_globalState() == StS))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
822 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
823 while(1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
824 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
825 MX_tell_reset_logik_alles_ok();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
826 DataEX_call();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
827 HAL_Delay(100);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
828 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
829 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
830 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
831 if(action == ACTION_BUTTON_BACK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
832 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
833 reset_to_firmware_using_Watchdog();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
834 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
835 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
836 if(action == ACTION_BUTTON_CUSTOM)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
837 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
838 if(get_globalState() == StS)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
839 gotoSleep();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
840 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
841 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
842 if(action == ACTION_BUTTON_ENTER)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
843 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
844 reset_to_update_using_system_reset();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
845 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
846 break;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
847 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
848 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
849
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
850
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
851 void gotoSleep(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
852 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
853 ext_flash_erase_firmware_if_not_empty();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
854 set_globalState(StStop);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
855 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
856
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
857 // -----------------------------
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
858
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
859
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
860 void MainBootLoaderInit(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
861 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
862 void (*SysMemBootJump)(void);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
863 SysMemBootJump=(void (*)(void)) (*((uint32_t *) 0x1fff0004));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
864
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
865 // DMA, SPI, UART, TIM, ExtIRQ, graphics DMA, LTDC
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
866
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
867 HAL_RCC_DeInit();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
868 SysTick->CTRL = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
869 SysTick->LOAD = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
870 SysTick->VAL = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
871
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
872 __set_PRIMASK(1);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
873
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
874 __set_MSP(0x20002318);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
875 SysMemBootJump();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
876 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
877
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
878 uint32_t get_globalState(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
879 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
880 return globalStateID;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
881 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
882
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
883 void get_globalStateList(SStateList *output)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
884 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
885 output->base = (uint8_t)((globalStateID >> 28) & 0x0F);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
886 output->page = (uint8_t)((globalStateID >> 24) & 0x0F);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
887 output->line = (uint8_t)((globalStateID >> 16) & 0xFF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
888 output->field = (uint8_t)((globalStateID >> 8) & 0xFF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
889 output->mode = (uint8_t)((globalStateID ) & 0xFF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
890 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
891
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
892 void get_idSpecificStateList(uint32_t id, SStateList *output)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
893 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
894 output->base = (uint8_t)((id >> 28) & 0x0F);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
895 output->page = (uint8_t)((id >> 24) & 0x0F);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
896 output->line = (uint8_t)((id >> 16) & 0xFF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
897 output->field = (uint8_t)((id >> 8) & 0xFF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
898 output->mode = (uint8_t)((id ) & 0xFF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
899 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
900
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
901 void set_globalState_Base(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
902 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
903 set_globalState(StS);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
904 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
905
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
906 void set_globalState_Menu_Page(uint8_t page)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
907 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
908 globalStateID = ((BaseMenu << 28) + (page << 24));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
909 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
910
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
911 void set_globalState_Log_Page(uint8_t pageIsLine)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
912 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
913 globalStateID = StILOGLIST + (pageIsLine << 16);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
914 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
915
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
916
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
917 void set_globalState_Menu_Line(uint8_t line)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
918 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
919 globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
920 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
921
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
922
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
923 void set_globalState(uint32_t newID)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
924 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
925 globalStateID = newID;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
926 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
927
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
928
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
929
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
930 void delayMicros(uint32_t micros)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
931 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
932 micros = micros * (168/4) - 10;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
933 while(micros--);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
934 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
935
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
936
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
937 void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget, RTC_TimeTypeDef * stimestructureget)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
938 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
939 /* Get the RTC current Time */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
940 if(sdatestructureget)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
941 HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
942 /* Get the RTC current Date */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
943 if(stimestructureget)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
944 HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
945 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
946
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
947
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
948 void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure, RTC_TimeTypeDef * stimestructure)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
949 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
950 if(sdatestructure)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
951 if(HAL_RTC_SetDate(&RtcHandle,sdatestructure,FORMAT_BCD) != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
952 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
953 /* Initialization Error */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
954 Error_Handler();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
955 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
956
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
957 if(stimestructure)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
958 if(HAL_RTC_SetTime(&RtcHandle,stimestructure,FORMAT_BCD) != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
959 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
960 /* Initialization Error */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
961 Error_Handler();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
962 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
963 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
964
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
965 static void TIM_init(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
966 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
967 uint16_t uwPrescalerValue = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
968
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
969 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
970
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
971 /* Set TIMx instance */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
972 TimHandle.Instance = TIMx;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
973
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
974 /* Initialize TIM3 peripheral as follows:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
975 + Period = 10000 - 1
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
976 + Prescaler = ((SystemCoreClock/2)/10000) - 1
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
977 + ClockDivision = 0
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
978 + Counter direction = Up
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
979 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
980 TimHandle.Init.Period = 1000 - 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
981 TimHandle.Init.Prescaler = uwPrescalerValue;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
982 TimHandle.Init.ClockDivision = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
983 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
984 if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
985 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
986 /* Initialization Error */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
987 Error_Handler();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
988 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
989
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
990 /*##-2- Start the TIM Base generation in interrupt mode ####################*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
991 /* Start Channel1 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
992 if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
993 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
994 /* Starting Error */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
995 Error_Handler();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
996 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
997 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
998
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
999 #ifndef TIM_BACKLIGHT
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1000 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1001 static void TIM_BACKLIGHT_adjust(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1002 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1003 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1004 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1005 static void TIM_BACKLIGHT_init(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1006 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1007 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1008 #else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1009 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1010 static void TIM_BACKLIGHT_adjust(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1011 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1012
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1013 TIM_OC_InitTypeDef sConfig;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1014 sConfig.OCMode = TIM_OCMODE_PWM1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1015 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1016 sConfig.OCFastMode = TIM_OCFAST_DISABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1017 sConfig.Pulse = 600;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1018
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1019 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1020 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1021 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1022 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1023 static void TIM_BACKLIGHT_init(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1024 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1025 uint32_t uwPrescalerValue = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1026 TIM_OC_InitTypeDef sConfig;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1027
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1028 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 18000000) - 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1029
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1030 TimBacklightHandle.Instance = TIM_BACKLIGHT;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1031
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1032 // Initialize TIM3 peripheral as follows: 30 kHz
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1033
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1034 TimBacklightHandle.Init.Period = 600 - 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1035 TimBacklightHandle.Init.Prescaler = uwPrescalerValue;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1036 TimBacklightHandle.Init.ClockDivision = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1037 TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1038 HAL_TIM_PWM_Init(&TimBacklightHandle);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1039
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1040 sConfig.OCMode = TIM_OCMODE_PWM1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1041 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1042 sConfig.OCFastMode = TIM_OCFAST_DISABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1043 sConfig.Pulse = 50 * 6;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1044
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1045 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1046 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1047 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1048 #endif
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1049
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1050 /* Configure RTC prescaler and RTC data registers */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1051 /* RTC configured as follow:
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1052 - Hour Format = Format 24
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1053 - Asynch Prediv = Value according to source clock
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1054 - Synch Prediv = Value according to source clock
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1055 - OutPut = Output Disable
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1056 - OutPutPolarity = High Polarity
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1057 - OutPutType = Open Drain */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1058 /*#define RTC_ASYNCH_PREDIV 0x7F LSE as RTC clock */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1059 /*LSE: #define RTC_SYNCH_PREDIV 0x00FF LSE as RTC clock */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1060 /*LSI: #define RTC_SYNCH_PREDIV 0x0130 LSI as RTC clock */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1061 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1062 static void RTC_init(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1063 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1064 RtcHandle.Instance = RTC;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1065
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1066
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1067 RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1068 RtcHandle.Init.AsynchPrediv = 0x7F;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1069 RtcHandle.Init.SynchPrediv = 0x0130;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1070 RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1071 RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1072 RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1073
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1074 if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1075 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1076 Error_Handler();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1077 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1078 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1079 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1080
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1081 static void EXTILine_Buttons_Config(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1082 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1083 GPIO_InitTypeDef GPIO_InitStructure;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1084
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1085 BUTTON_ENTER_GPIO_ENABLE();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1086 BUTTON_NEXT_GPIO_ENABLE();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1087 BUTTON_BACK_GPIO_ENABLE();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1088
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1089 /* Configure pin as weak PULLUP input */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1090 /* buttons */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1091 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1092 GPIO_InitStructure.Pull = GPIO_NOPULL;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1093 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1094
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1095 GPIO_InitStructure.Pin = BUTTON_ENTER_PIN;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1096 HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1097
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1098 GPIO_InitStructure.Pin = BUTTON_NEXT_PIN;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1099 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1100
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1101 GPIO_InitStructure.Pin = BUTTON_BACK_PIN;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1102 HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1103
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1104 /* Enable and set EXTI Line0 Interrupt to the lowest priority */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1105 HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1106 HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn, 2, 0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1107 HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn, 2, 0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1108 HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1109 HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1110 HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1111
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1112 #ifdef BUTTON_CUSTOM_PIN
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1113 BUTTON_CUSTOM_GPIO_ENABLE();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1114 GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1115 HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1116 HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn, 2, 0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1117 HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1118 #endif
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1119 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1120
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1121
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1122 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1123 * @brief System Clock Configuration
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1124 * The system Clock is configured as follow :
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1125 * System Clock source = PLL (HSE)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1126 * SYSCLK(Hz) = 180000000
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1127 * HCLK(Hz) = 180000000
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1128 * AHB Prescaler = 1
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1129 * APB1 Prescaler = 4
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1130 * APB2 Prescaler = 2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1131 * HSE Frequency(Hz) = 8000000
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1132 * PLL_M = 8
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1133 * PLL_N = 360
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1134 * PLL_P = 2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1135 * PLL_Q = 7
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1136 * VDD(V) = 3.3
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1137 * Main regulator output voltage = Scale1 mode
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1138 * Flash Latency(WS) = 5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1139 * The LTDC Clock is configured as follow :
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1140 * PLLSAIN = 192
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1141 * PLLSAIR = 4
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1142 * PLLSAIDivR = 8
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1143 * @param None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1144 * @retval None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1145 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1146 static void SystemClock_Config(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1147 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1148 RCC_ClkInitTypeDef RCC_ClkInitStruct;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1149 RCC_OscInitTypeDef RCC_OscInitStruct;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1150 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1151
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1152 /* Enable Power Control clock */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1153 __PWR_CLK_ENABLE();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1154
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1155 /* The voltage scaling allows optimizing the power consumption when the device is
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1156 clocked below the maximum system frequency, to update the voltage scaling value
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1157 regarding system frequency refer to product datasheet. */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1158 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1159
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1160 /*##-1- System Clock Configuration #########################################*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1161 /* Enable HSE Oscillator and activate PLL with HSE as source */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1162 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1163 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1164 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1165 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1166 RCC_OscInitStruct.PLL.PLLM = 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1167 RCC_OscInitStruct.PLL.PLLN = 336;//360;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1168 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1169 RCC_OscInitStruct.PLL.PLLQ = 7;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1170 HAL_RCC_OscConfig(&RCC_OscInitStruct);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1171
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1172 // HAL_PWREx_ActivateOverDrive();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1173 HAL_PWREx_DeactivateOverDrive();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1174 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1175 clocks dividers */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1176 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1177 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1178 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1179 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1180 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1181 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8);//FLASH_LATENCY_5);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1182
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1183 /*##-2- LTDC Clock Configuration ###########################################*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1184 /* LCD clock configuration */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1185 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1186 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1187 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1188 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1189
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1190 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1191 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1192 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300;//192;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1193 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5;//4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1194 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1195 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1196 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1197
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1198
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1199 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1200 * @brief This function is executed in case of error occurrence.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1201 * @param None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1202 * @retval None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1203 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1204 static void Error_Handler(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1205 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1206 /* Turn LED3 on */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1207 // BSP_LED_On(LED3);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1208 while(1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1209 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1210 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1211 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1212
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1213 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1214 * @brief Perform the SDRAM exernal memory inialization sequence
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1215 * @param hsdram: SDRAM handle
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1216 * @param Command: Pointer to SDRAM command structure
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1217 * @retval None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1218 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1219 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1220 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1221 __IO uint32_t tmpmrd =0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1222 /* Step 3: Configure a clock configuration enable command */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1223 Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1224 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1225 Command->AutoRefreshNumber = 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1226 Command->ModeRegisterDefinition = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1227
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1228 /* Send the command */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1229 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1230
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1231 /* Step 4: Insert 100 ms delay */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1232 HAL_Delay(100);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1233
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1234 /* Step 5: Configure a PALL (precharge all) command */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1235 Command->CommandMode = FMC_SDRAM_CMD_PALL;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1236 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1237 Command->AutoRefreshNumber = 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1238 Command->ModeRegisterDefinition = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1239
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1240 /* Send the command */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1241 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1242
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1243 /* Step 6 : Configure a Auto-Refresh command */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1244 Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1245 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1246 Command->AutoRefreshNumber = 4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1247 Command->ModeRegisterDefinition = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1248
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1249 /* Send the command */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1250 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1251
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1252 /* Step 7: Program the external memory mode register */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1253 tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 |
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1254 SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL |
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1255 SDRAM_MODEREG_CAS_LATENCY_3 |
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1256 SDRAM_MODEREG_OPERATING_MODE_STANDARD |
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1257 SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1258
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1259 Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1260 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1261 Command->AutoRefreshNumber = 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1262 Command->ModeRegisterDefinition = tmpmrd;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1263
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1264 /* Send the command */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1265 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1266
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1267 /* Step 8: Set the refresh rate counter */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1268 /* (15.62 us x Freq) - 20 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1269 /* neu: (8 us x Freq) - 20 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1270 /* Set the device refresh counter */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1271 HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1272 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1273
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1274 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1275 static void DualBoot(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1276 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1277 // Set BFB2 bit to enable boot from Flash Bank2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1278 // Allow Access to Flash control registers and user Falsh
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1279 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1280
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1281 // Allow Access to option bytes sector
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1282 HAL_FLASH_OB_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1283
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1284 // Get the Dual boot configuration status
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1285 AdvOBInit.OptionType = OBEX_BOOTCONFIG;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1286 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1287
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1288 // Enable/Disable dual boot feature
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1289 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1290 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1291 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1292 HAL_FLASHEx_AdvOBProgram (&AdvOBInit);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1293 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1294 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1295 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1296 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1297 HAL_FLASHEx_AdvOBProgram (&AdvOBInit);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1298 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1299
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1300 // Start the Option Bytes programming process
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1301 if (HAL_FLASH_OB_Launch() != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1302 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1303 // User can add here some code to deal with this error
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1304 while (1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1305 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1306 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1307 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1308 // Prevent Access to option bytes sector
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1309 HAL_FLASH_OB_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1310
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1311 // Disable the Flash option control register access (recommended to protect
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1312 // the option Bytes against possible unwanted operations)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1313 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1314
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1315 // Initiates a system reset request to reset the MCU
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1316 reset_to_firmware_using_Watchdog();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1317 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1318 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1319 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1320 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1321 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1322 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1323 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1324
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1325
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1326 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1327 * @brief DMA2D configuration.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1328 * @note This function Configure tha DMA2D peripheral :
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1329 * 1) Configure the transfer mode : memory to memory W/ pixel format conversion
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1330 * 2) Configure the output color mode as ARGB4444
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1331 * 3) Configure the output memory address at SRAM memory
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1332 * 4) Configure the data size : 320x120 (pixels)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1333 * 5) Configure the input color mode as ARGB8888
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1334 * 6) Configure the input memory address at FLASH memory
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1335 * @retval
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1336 * None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1337 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1338
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1339 static void SDRAM_Config(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1340 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1341 /*##-1- Configure the SDRAM device #########################################*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1342 /* SDRAM device configuration */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1343 hsdram.Instance = FMC_SDRAM_DEVICE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1344
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1345 /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1346 /* TMRD: 2 Clock cycles */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1347 SDRAM_Timing.LoadToActiveDelay = 2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1348 /* TXSR: min=70ns (6x11.90ns) */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1349 SDRAM_Timing.ExitSelfRefreshDelay = 7;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1350 /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1351 SDRAM_Timing.SelfRefreshTime = 4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1352 /* TRC: min=63 (6x11.90ns) */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1353 SDRAM_Timing.RowCycleDelay = 7;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1354 /* TWR: 2 Clock cycles */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1355 SDRAM_Timing.WriteRecoveryTime = 2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1356 /* TRP: 15ns => 2x11.90ns */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1357 SDRAM_Timing.RPDelay = 2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1358 /* TRCD: 15ns => 2x11.90ns */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1359 SDRAM_Timing.RCDDelay = 2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1360
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1361 hsdram.Init.SDBank = FMC_SDRAM_BANK2;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1362 hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1363 hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1364 hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1365 hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1366 hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1367 hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1368 hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1369 hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1370 hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1371
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1372 /* Initialize the SDRAM controller */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1373 if(HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1374 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1375 /* Initialization Error */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1376 Error_Handler();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1377 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1378
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1379 /* Program the SDRAM external device */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1380 SDRAM_Initialization_Sequence(&hsdram, &command);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1381 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1382
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1383
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1384 uint8_t checkResetForFirmwareUpdate(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1385 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1386 uint32_t backupRegisterContent;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1387
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1388 RTC_HandleTypeDef RtcHandle;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1389 RtcHandle.Instance = RTC;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1390 backupRegisterContent = HAL_RTCEx_BKUPRead(&RtcHandle,RTC_BKP_DR0);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1391
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1392 if(backupRegisterContent == 0x12345678)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1393 return 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1394 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1395 return 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1396 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1397
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1398 void DeleteResetToFirmwareUpdateRegister(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1399 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1400 RTC_HandleTypeDef RtcHandle;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1401 RtcHandle.Instance = RTC;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1402 __HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1403 HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR0,0x00);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1404 __HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1405 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1406
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1407 #ifdef USE_FULL_ASSERT
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1408
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1409 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1410 * @brief Reports the name of the source file and the source line number
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1411 * where the assert_param error has occurred.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1412 * @param file: pointer to the source file name
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1413 * @param line: assert_param error line source number
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1414 * @retval None
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1415 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1416 void assert_failed(uint8_t* file, uint32_t line)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1417 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1418 /* User can add his own implementation to report the file name and line number,
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1419 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1420
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1421 /* Infinite loop */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1422 while (1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1423 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1424 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1425 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1426 #endif
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1427
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1428 /*
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1429 static void DualBootToBootloader(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1430 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1431 // Set BFB2 bit to enable boot from Flash Bank2
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1432 // Allow Access to Flash control registers and user Falsh
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1433 HAL_FLASH_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1434
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1435 // Allow Access to option bytes sector
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1436 HAL_FLASH_OB_Unlock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1437
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1438 // Get the Dual boot configuration status
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1439 AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1440 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1441
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1442 // Enable/Disable dual boot feature
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1443 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1444 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1445 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1446 HAL_FLASHEx_AdvOBProgram (&AdvOBInit);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1447 if (HAL_FLASH_OB_Launch() != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1448 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1449 while (1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1450 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1451 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1452 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1453 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1454 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1455 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1456
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1457 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1458 HAL_FLASHEx_AdvOBProgram (&AdvOBInit);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1459 if (HAL_FLASH_OB_Launch() != HAL_OK)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1460 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1461 while (1)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1462 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1463 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1464 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1465 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1466
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1467 // Prevent Access to option bytes sector
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1468 HAL_FLASH_OB_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1469
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1470 / Disable the Flash option control register access (recommended to protect
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1471 // the option Bytes against possible unwanted operations)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1472 HAL_FLASH_Lock();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1473
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1474 // Initiates a system reset request to reset the MCU
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1475 reset_to_firmware_using_Watchdog();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1476 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1477 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1478
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1479 void reset_to_update_using_system_reset(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1480 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1481 __HAL_RCC_CLEAR_RESET_FLAGS();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1482 HAL_NVIC_SystemReset();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1483 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1484
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1485 void reset_to_firmware_using_Watchdog(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1486 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1487 __HAL_RCC_CLEAR_RESET_FLAGS();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1488 __HAL_RCC_WWDG_CLK_ENABLE();
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1489
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1490 WWDG_HandleTypeDef WwdgHandle;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1491 WwdgHandle.Instance = WWDG;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1492
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1493 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1494 WwdgHandle.Init.Window = 80;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1495 WwdgHandle.Init.Counter = 127;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1496
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1497 HAL_WWDG_Init(&WwdgHandle);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1498 HAL_WWDG_Start(&WwdgHandle);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1499 while(1);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1500 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1501
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1502
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1503 void set_returnFromComm(void)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1504 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1505 returnFromCommCleanUpRequest = 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1506 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1507
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1508 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1509 * @}
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1510 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1511
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1512 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1513 * @}
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1514 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1515
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1516 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/