annotate BootLoader/Src/base_bootlader.c @ 8:d81b21014d6b

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