annotate BootLoader/Src/base_bootlader.c @ 966:90edc237d60f Evo_2_23

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