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