Mercurial > public > ostc4
annotate BootLoader/Src/base_bootlader.c @ 1016:0dd92e9b70a2 BootloaderOstc5
Bootloader use compressed fonts:
The previous Bootloader was larger than 128k => not fitting into the first sectors of the second flash bank. Most memory is occupied by the two fonts in use. In order to make the bootloader small enough for the bootloader update function the fonts need to be compressed. To avoid code changes in visualization functions the compressed fonts are decompressed into RAM and then used in the same way as before.
| author | Ideenmodellierer |
|---|---|
| date | Wed, 28 May 2025 17:20:44 +0200 |
| parents | 4ef0511c6665 |
| children | 9d9d506a82d3 |
| 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, |
|
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
265 .release_month = 1, |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
266 .release_day = 13, |
| 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 | |
| 283 .primarySerial = 0xFFFF, | |
|
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"); |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
691 tInfo_newpage("bootloader 250113"); |
| 30 | 692 tInfo_write("start bluetooth"); |
| 693 tInfo_write(""); | |
| 694 tInfo_write(textVersion); | |
| 992 | 695 #if 0 |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
696 if(tComm_Set_Bluetooth_Name(0) == 0xFF) |
| 992 | 697 #else |
| 698 if(hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF) | |
| 699 #endif | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
700 { |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
701 tInfo_write("init bluetooth"); |
| 986 | 702 tComm_StartBlueModBaseInit(); |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
703 } |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
704 else |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
705 { |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
706 tInfo_write("bluetooth set"); |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
707 tComm_StartBlueModConfig(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
708 } |
| 30 | 709 |
| 710 set_globalState_Base(); | |
| 711 | |
| 712 GFX_start_VSYNC_IRQ(); | |
| 713 | |
| 714 EXTILine_Buttons_Config(); | |
| 715 /* | |
| 716 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
| 717 firmware_load_result = ext_flash_read_firmware(pBuffer1,768000); | |
| 718 | |
| 719 if((firmware_load_result > 0) && (firmware_load_result < 768000)) | |
| 720 { | |
| 721 firmware_eraseFlashMemory(); | |
| 722 firmware_programFlashMemory(pBuffer1,firmware_load_result); | |
| 723 // not for testing | |
| 724 //ext_flash_erase_firmware_if_not_empty(); | |
| 725 reset_to_firmware_using_Watchdog(); | |
| 726 } | |
| 727 */ | |
| 728 while(1) | |
| 729 { | |
| 730 // if(bootToBootloader) | |
| 731 // DualBootToBootloader(); | |
| 732 | |
| 733 if(bootToBootloader) | |
| 734 reset_to_update_using_system_reset(); | |
| 735 | |
| 736 tComm_control(); // will stop while loop if tComm Mode started until exit from UART | |
| 737 }; | |
| 738 } | |
| 739 | |
| 740 | |
| 741 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |
| 742 { | |
| 743 | |
| 744 SStateList status; | |
| 745 | |
| 746 get_globalStateList(&status); | |
| 747 | |
| 748 switch(status.base) | |
| 749 { | |
| 750 default: | |
| 751 // TIM_BACKLIGHT_adjust(); | |
| 752 break; | |
| 753 } | |
| 754 | |
| 755 if(returnFromCommCleanUpRequest) | |
| 756 { | |
| 757 tComm_exit(); | |
| 758 returnFromCommCleanUpRequest = 0; | |
| 759 GFX_hwBackgroundOn(); | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
760 tInfo_button_text("exit","","sleep"); |
| 30 | 761 tInfo_newpage("bluetooth disonnected"); |
| 762 tInfo_write(""); | |
| 763 tInfo_write(""); | |
| 764 tInfo_write(""); | |
| 765 tInfo_write(""); | |
| 766 } | |
| 767 | |
| 768 get_globalStateList(&status); | |
| 769 | |
| 770 switch(status.base) | |
| 771 { | |
| 772 case BaseComm: | |
| 773 if(get_globalState() == StUART_STANDARD) | |
| 774 tComm_refresh(); | |
| 775 break; | |
| 776 default: | |
| 777 break; | |
| 778 } | |
| 779 } | |
| 780 | |
| 781 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | |
| 782 { | |
| 783 uint8_t action; | |
| 784 SStateList status; | |
| 785 static uint8_t counterToPreventSleep = 0; | |
| 786 if(GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten | |
| 787 { | |
| 788 GFX_change_LTDC(); | |
| 789 housekeepingFrame(); | |
| 790 if(counterToPreventSleep < 250) | |
| 791 counterToPreventSleep++; | |
| 792 else | |
| 793 if(counterToPreventSleep != 255) | |
| 794 { | |
| 795 counterToPreventSleep = 255; | |
| 796 } | |
| 797 | |
| 798 return; | |
| 799 } | |
| 800 | |
| 801 time_without_button_pressed_deciseconds = 0; | |
| 802 | |
| 803 if(GFX_logoStatus() != 0) | |
| 804 return; | |
| 805 | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
806 if(GPIO_Pin == BUTTON_BACK_PIN) // left |
| 30 | 807 action = ACTION_BUTTON_BACK; |
| 808 else | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
809 if(GPIO_Pin == BUTTON_ENTER_PIN) // center |
| 30 | 810 action = ACTION_BUTTON_ENTER; |
| 811 else | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
812 if(GPIO_Pin == BUTTON_NEXT_PIN) // right |
| 30 | 813 action = ACTION_BUTTON_NEXT; |
| 814 #ifdef BUTTON_CUSTOM_PIN | |
| 815 else | |
| 816 if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra | |
| 817 action = ACTION_BUTTON_CUSTOM; | |
| 818 #endif | |
| 819 else | |
| 820 action = 0; | |
| 821 get_globalStateList(&status); | |
| 822 | |
| 971 | 823 if(status.base == BaseComm) |
| 30 | 824 { |
| 825 if(action == ACTION_BUTTON_BACK) | |
| 826 { | |
| 827 reset_to_firmware_using_Watchdog(); | |
| 828 } | |
| 971 | 829 } |
| 830 else | |
| 831 { | |
| 832 switch (action) | |
| 833 { | |
| 834 case ACTION_BUTTON_NEXT: if((counterToPreventSleep == 255) && (get_globalState() == StS)) | |
| 835 { | |
| 836 while(1) | |
| 837 { | |
| 838 MX_tell_reset_logik_alles_ok(); | |
| 839 DataEX_call(); | |
| 840 HAL_Delay(100); | |
| 841 } | |
| 842 } | |
| 843 break; | |
| 844 case ACTION_BUTTON_BACK: reset_to_firmware_using_Watchdog(); | |
| 845 break; | |
| 846 case ACTION_BUTTON_CUSTOM: if(get_globalState() == StS) | |
| 847 { | |
| 848 gotoSleep(); | |
| 849 } | |
| 850 break; | |
| 851 case ACTION_BUTTON_ENTER: /* reset_to_update_using_system_reset(); old function */ | |
| 852 tComm_StartBlueModBaseInit(); /* new: factory reset bluetooth */ | |
| 853 break; | |
| 854 default: | |
| 855 break; | |
| 856 } | |
| 30 | 857 } |
| 858 } | |
| 859 | |
| 860 | |
| 861 void gotoSleep(void) | |
| 862 { | |
| 863 ext_flash_erase_firmware_if_not_empty(); | |
| 864 set_globalState(StStop); | |
| 865 } | |
| 866 | |
| 867 // ----------------------------- | |
| 868 | |
| 869 | |
| 870 void MainBootLoaderInit(void) | |
| 871 { | |
| 872 void (*SysMemBootJump)(void); | |
| 873 SysMemBootJump=(void (*)(void)) (*((uint32_t *) 0x1fff0004)); | |
| 874 | |
| 875 // DMA, SPI, UART, TIM, ExtIRQ, graphics DMA, LTDC | |
| 876 | |
| 877 HAL_RCC_DeInit(); | |
| 878 SysTick->CTRL = 0; | |
| 879 SysTick->LOAD = 0; | |
| 880 SysTick->VAL = 0; | |
| 881 | |
| 882 __set_PRIMASK(1); | |
| 883 | |
| 884 __set_MSP(0x20002318); | |
| 885 SysMemBootJump(); | |
| 886 } | |
| 887 | |
| 888 uint32_t get_globalState(void) | |
| 889 { | |
| 890 return globalStateID; | |
| 891 } | |
| 892 | |
| 893 void get_globalStateList(SStateList *output) | |
| 894 { | |
| 895 output->base = (uint8_t)((globalStateID >> 28) & 0x0F); | |
| 896 output->page = (uint8_t)((globalStateID >> 24) & 0x0F); | |
| 897 output->line = (uint8_t)((globalStateID >> 16) & 0xFF); | |
| 898 output->field = (uint8_t)((globalStateID >> 8) & 0xFF); | |
| 899 output->mode = (uint8_t)((globalStateID ) & 0xFF); | |
| 900 } | |
| 901 | |
| 902 void get_idSpecificStateList(uint32_t id, SStateList *output) | |
| 903 { | |
| 904 output->base = (uint8_t)((id >> 28) & 0x0F); | |
| 905 output->page = (uint8_t)((id >> 24) & 0x0F); | |
| 906 output->line = (uint8_t)((id >> 16) & 0xFF); | |
| 907 output->field = (uint8_t)((id >> 8) & 0xFF); | |
| 908 output->mode = (uint8_t)((id ) & 0xFF); | |
| 909 } | |
| 910 | |
| 911 void set_globalState_Base(void) | |
| 912 { | |
| 913 set_globalState(StS); | |
| 914 } | |
| 915 | |
| 916 void set_globalState_Menu_Page(uint8_t page) | |
| 917 { | |
| 918 globalStateID = ((BaseMenu << 28) + (page << 24)); | |
| 919 } | |
| 920 | |
| 921 void set_globalState_Log_Page(uint8_t pageIsLine) | |
| 922 { | |
| 923 globalStateID = StILOGLIST + (pageIsLine << 16); | |
| 924 } | |
| 925 | |
| 926 | |
| 927 void set_globalState_Menu_Line(uint8_t line) | |
| 928 { | |
| 929 globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16)); | |
| 930 } | |
| 931 | |
| 932 | |
| 933 void set_globalState(uint32_t newID) | |
| 934 { | |
| 935 globalStateID = newID; | |
| 936 } | |
| 937 | |
| 938 | |
| 939 | |
| 940 void delayMicros(uint32_t micros) | |
| 941 { | |
| 942 micros = micros * (168/4) - 10; | |
| 943 while(micros--); | |
| 944 } | |
| 945 | |
| 946 | |
| 947 void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget, RTC_TimeTypeDef * stimestructureget) | |
| 948 { | |
| 949 /* Get the RTC current Time */ | |
| 950 if(sdatestructureget) | |
| 951 HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN); | |
| 952 /* Get the RTC current Date */ | |
| 953 if(stimestructureget) | |
| 954 HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN); | |
| 955 } | |
| 956 | |
| 957 | |
| 958 void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure, RTC_TimeTypeDef * stimestructure) | |
| 959 { | |
| 960 if(sdatestructure) | |
| 961 if(HAL_RTC_SetDate(&RtcHandle,sdatestructure,FORMAT_BCD) != HAL_OK) | |
| 962 { | |
| 963 /* Initialization Error */ | |
| 964 Error_Handler(); | |
| 965 } | |
| 966 | |
| 967 if(stimestructure) | |
| 968 if(HAL_RTC_SetTime(&RtcHandle,stimestructure,FORMAT_BCD) != HAL_OK) | |
| 969 { | |
| 970 /* Initialization Error */ | |
| 971 Error_Handler(); | |
| 972 } | |
| 973 } | |
| 974 | |
| 975 static void TIM_init(void) | |
| 976 { | |
| 977 uint16_t uwPrescalerValue = 0; | |
| 978 | |
| 979 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1; | |
| 980 | |
| 981 /* Set TIMx instance */ | |
| 982 TimHandle.Instance = TIMx; | |
| 983 | |
| 984 /* Initialize TIM3 peripheral as follows: | |
| 985 + Period = 10000 - 1 | |
| 986 + Prescaler = ((SystemCoreClock/2)/10000) - 1 | |
| 987 + ClockDivision = 0 | |
| 988 + Counter direction = Up | |
| 989 */ | |
| 990 TimHandle.Init.Period = 1000 - 1; | |
| 991 TimHandle.Init.Prescaler = uwPrescalerValue; | |
| 992 TimHandle.Init.ClockDivision = 0; | |
| 993 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
| 994 if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK) | |
| 995 { | |
| 996 /* Initialization Error */ | |
| 997 Error_Handler(); | |
| 998 } | |
| 999 | |
| 1000 /*##-2- Start the TIM Base generation in interrupt mode ####################*/ | |
| 1001 /* Start Channel1 */ | |
| 1002 if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) | |
| 1003 { | |
| 1004 /* Starting Error */ | |
| 1005 Error_Handler(); | |
| 1006 } | |
| 1007 } | |
| 1008 | |
| 1009 #ifndef TIM_BACKLIGHT | |
| 1010 /* | |
| 1011 static void TIM_BACKLIGHT_adjust(void) | |
| 1012 { | |
| 1013 } | |
| 1014 */ | |
| 1015 static void TIM_BACKLIGHT_init(void) | |
| 1016 { | |
| 1017 } | |
| 1018 #else | |
| 1019 /* | |
| 1020 static void TIM_BACKLIGHT_adjust(void) | |
| 1021 { | |
| 1022 | |
| 1023 TIM_OC_InitTypeDef sConfig; | |
| 1024 sConfig.OCMode = TIM_OCMODE_PWM1; | |
| 1025 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
| 1026 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
| 1027 sConfig.Pulse = 600; | |
| 1028 | |
| 1029 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
| 1030 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
| 1031 } | |
| 1032 */ | |
| 1033 static void TIM_BACKLIGHT_init(void) | |
| 1034 { | |
| 1035 uint32_t uwPrescalerValue = 0; | |
| 1036 TIM_OC_InitTypeDef sConfig; | |
| 1037 | |
| 1038 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 18000000) - 1; | |
| 1039 | |
| 1040 TimBacklightHandle.Instance = TIM_BACKLIGHT; | |
| 1041 | |
| 1042 // Initialize TIM3 peripheral as follows: 30 kHz | |
| 1043 | |
| 1044 TimBacklightHandle.Init.Period = 600 - 1; | |
| 1045 TimBacklightHandle.Init.Prescaler = uwPrescalerValue; | |
| 1046 TimBacklightHandle.Init.ClockDivision = 0; | |
| 1047 TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
| 1048 HAL_TIM_PWM_Init(&TimBacklightHandle); | |
| 1049 | |
| 1050 sConfig.OCMode = TIM_OCMODE_PWM1; | |
| 1051 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
| 1052 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
| 1053 sConfig.Pulse = 50 * 6; | |
| 1054 | |
| 1055 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
| 1056 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
| 1057 } | |
| 1058 #endif | |
| 1059 | |
| 1060 /* Configure RTC prescaler and RTC data registers */ | |
| 1061 /* RTC configured as follow: | |
| 1062 - Hour Format = Format 24 | |
| 1063 - Asynch Prediv = Value according to source clock | |
| 1064 - Synch Prediv = Value according to source clock | |
| 1065 - OutPut = Output Disable | |
| 1066 - OutPutPolarity = High Polarity | |
| 1067 - OutPutType = Open Drain */ | |
| 1068 /*#define RTC_ASYNCH_PREDIV 0x7F LSE as RTC clock */ | |
| 1069 /*LSE: #define RTC_SYNCH_PREDIV 0x00FF LSE as RTC clock */ | |
| 1070 /*LSI: #define RTC_SYNCH_PREDIV 0x0130 LSI as RTC clock */ | |
| 1071 /* | |
| 1072 static void RTC_init(void) | |
| 1073 { | |
| 1074 RtcHandle.Instance = RTC; | |
| 1075 | |
| 1076 | |
| 1077 RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
| 1078 RtcHandle.Init.AsynchPrediv = 0x7F; | |
| 1079 RtcHandle.Init.SynchPrediv = 0x0130; | |
| 1080 RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
| 1081 RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
| 1082 RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
| 1083 | |
| 1084 if(HAL_RTC_Init(&RtcHandle) != HAL_OK) | |
| 1085 { | |
| 1086 Error_Handler(); | |
| 1087 } | |
| 1088 } | |
| 1089 */ | |
| 1090 | |
| 1091 static void EXTILine_Buttons_Config(void) | |
| 1092 { | |
| 1093 GPIO_InitTypeDef GPIO_InitStructure; | |
| 1094 | |
| 1095 BUTTON_ENTER_GPIO_ENABLE(); | |
| 1096 BUTTON_NEXT_GPIO_ENABLE(); | |
| 1097 BUTTON_BACK_GPIO_ENABLE(); | |
| 1098 | |
| 1099 /* Configure pin as weak PULLUP input */ | |
| 1100 /* buttons */ | |
| 1101 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
| 1102 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
| 1103 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
| 1104 | |
| 1105 GPIO_InitStructure.Pin = BUTTON_ENTER_PIN; | |
| 1106 HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure); | |
| 1107 | |
| 1108 GPIO_InitStructure.Pin = BUTTON_NEXT_PIN; | |
| 1109 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure); | |
| 1110 | |
| 1111 GPIO_InitStructure.Pin = BUTTON_BACK_PIN; | |
| 1112 HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure); | |
| 1113 | |
| 1114 /* Enable and set EXTI Line0 Interrupt to the lowest priority */ | |
| 1115 HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0); | |
| 1116 HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn, 2, 0); | |
| 1117 HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn, 2, 0); | |
| 1118 HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn); | |
| 1119 HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn); | |
| 1120 HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn); | |
| 1121 | |
| 1122 #ifdef BUTTON_CUSTOM_PIN | |
| 1123 BUTTON_CUSTOM_GPIO_ENABLE(); | |
| 1124 GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN; | |
| 1125 HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure); | |
| 1126 HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn, 2, 0); | |
| 1127 HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn); | |
| 1128 #endif | |
| 1129 } | |
| 1130 | |
| 1131 | |
| 1132 /** | |
| 1133 * @brief System Clock Configuration | |
| 1134 * The system Clock is configured as follow : | |
| 1135 * System Clock source = PLL (HSE) | |
| 1136 * SYSCLK(Hz) = 180000000 | |
| 1137 * HCLK(Hz) = 180000000 | |
| 1138 * AHB Prescaler = 1 | |
| 1139 * APB1 Prescaler = 4 | |
| 1140 * APB2 Prescaler = 2 | |
| 1141 * HSE Frequency(Hz) = 8000000 | |
| 1142 * PLL_M = 8 | |
| 1143 * PLL_N = 360 | |
| 1144 * PLL_P = 2 | |
| 1145 * PLL_Q = 7 | |
| 1146 * VDD(V) = 3.3 | |
| 1147 * Main regulator output voltage = Scale1 mode | |
| 1148 * Flash Latency(WS) = 5 | |
| 1149 * The LTDC Clock is configured as follow : | |
| 1150 * PLLSAIN = 192 | |
| 1151 * PLLSAIR = 4 | |
| 1152 * PLLSAIDivR = 8 | |
| 1153 * @param None | |
| 1154 * @retval None | |
| 1155 */ | |
| 1156 static void SystemClock_Config(void) | |
| 1157 { | |
| 869 | 1158 /* Enable Power Control clock */ |
| 1159 __PWR_CLK_ENABLE(); | |
| 30 | 1160 |
| 869 | 1161 /* The voltage scaling allows optimizing the power consumption when the device is |
| 1162 clocked below the maximum system frequency, to update the voltage scaling value | |
| 1163 regarding system frequency refer to product datasheet. */ | |
| 1164 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |
| 30 | 1165 |
| 869 | 1166 /*##-1- System Clock Configuration #########################################*/ |
| 1167 /* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */ | |
| 1168 RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; | |
| 1169 #ifdef DISC1_BOARD | |
| 1170 // Use High Speed Internal (HSI) oscillator, running at 16MHz. | |
| 1171 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
| 1172 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
| 1173 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
| 1174 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
| 1175 RCC_OscInitStruct.PLL.PLLM = 16; // HSI/16 is 1Mhz. | |
| 1176 #else | |
| 1177 // Use High Speed External oscillator, running at 8MHz | |
| 1178 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
| 1179 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
| 1180 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
| 1181 RCC_OscInitStruct.PLL.PLLM = 8; // HSE/8 is 1Mhz. | |
| 1182 #endif | |
| 1183 // System clock = PLL (1MHz) * N/p = 180 MHz. | |
| 1184 RCC_OscInitStruct.PLL.PLLN = 360; | |
| 1185 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | |
| 1186 RCC_OscInitStruct.PLL.PLLQ = 7; | |
| 1187 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
| 1188 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
| 30 | 1189 |
| 1190 // HAL_PWREx_ActivateOverDrive(); | |
| 869 | 1191 HAL_PWREx_DeactivateOverDrive(); |
| 1192 | |
| 1193 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ | |
| 1194 RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; | |
| 1195 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
| 1196 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
| 1197 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
| 1198 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
| 1199 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; | |
| 1200 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; | |
| 1201 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_8 ); //FLASH_LATENCY_5); | |
| 30 | 1202 |
| 869 | 1203 /*##-2- LTDC Clock Configuration ###########################################*/ |
| 1204 /* LCD clock configuration */ | |
| 1205 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ | |
| 1206 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ | |
| 1207 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ | |
| 1208 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ | |
| 30 | 1209 |
| 869 | 1210 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */ |
| 1211 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; | |
| 1212 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; | |
| 1213 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300; //192; | |
| 1214 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; //4; | |
| 1215 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8 | |
| 1216 HAL_RCCEx_PeriphCLKConfig( &PeriphClkInitStruct ); | |
| 30 | 1217 } |
| 1218 | |
| 1219 | |
| 1220 /** | |
| 1221 * @brief This function is executed in case of error occurrence. | |
| 1222 * @param None | |
| 1223 * @retval None | |
| 1224 */ | |
| 1225 static void Error_Handler(void) | |
| 1226 { | |
| 1227 /* Turn LED3 on */ | |
| 1228 // BSP_LED_On(LED3); | |
| 1229 while(1) | |
| 1230 { | |
| 1231 } | |
| 1232 } | |
| 1233 | |
| 1234 /** | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1235 * @brief Perform the SDRAM external memory initialization sequence |
| 30 | 1236 * @param hsdram: SDRAM handle |
| 1237 * @param Command: Pointer to SDRAM command structure | |
| 1238 * @retval None | |
| 1239 */ | |
| 1240 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command) | |
| 1241 { | |
| 1242 __IO uint32_t tmpmrd =0; | |
| 1243 /* Step 3: Configure a clock configuration enable command */ | |
| 1244 Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; | |
| 1245 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1246 Command->AutoRefreshNumber = 1; | |
| 1247 Command->ModeRegisterDefinition = 0; | |
| 1248 | |
| 1249 /* Send the command */ | |
| 1250 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1251 | |
| 1252 /* Step 4: Insert 100 ms delay */ | |
| 1253 HAL_Delay(100); | |
| 1254 | |
| 1255 /* Step 5: Configure a PALL (precharge all) command */ | |
| 1256 Command->CommandMode = FMC_SDRAM_CMD_PALL; | |
| 1257 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1258 Command->AutoRefreshNumber = 1; | |
| 1259 Command->ModeRegisterDefinition = 0; | |
| 1260 | |
| 1261 /* Send the command */ | |
| 1262 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1263 | |
| 1264 /* Step 6 : Configure a Auto-Refresh command */ | |
| 1265 Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; | |
| 1266 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1267 Command->AutoRefreshNumber = 4; | |
| 1268 Command->ModeRegisterDefinition = 0; | |
| 1269 | |
| 1270 /* Send the command */ | |
| 1271 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1272 | |
| 1273 /* Step 7: Program the external memory mode register */ | |
| 1274 tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 | | |
| 1275 SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | | |
| 1276 SDRAM_MODEREG_CAS_LATENCY_3 | | |
| 1277 SDRAM_MODEREG_OPERATING_MODE_STANDARD | | |
| 1278 SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; | |
| 1279 | |
| 1280 Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE; | |
| 1281 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1282 Command->AutoRefreshNumber = 1; | |
| 1283 Command->ModeRegisterDefinition = tmpmrd; | |
| 1284 | |
| 1285 /* Send the command */ | |
| 1286 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1287 | |
| 1288 /* Step 8: Set the refresh rate counter */ | |
| 1289 /* (15.62 us x Freq) - 20 */ | |
| 1290 /* neu: (8 us x Freq) - 20 */ | |
| 1291 /* Set the device refresh counter */ | |
| 1292 HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT); | |
| 1293 } | |
| 1294 | |
| 1295 /* | |
| 1296 static void DualBoot(void) | |
| 1297 { | |
| 1298 // Set BFB2 bit to enable boot from Flash Bank2 | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1299 // Allow Access to Flash control registers and user Flash |
| 30 | 1300 HAL_FLASH_Unlock(); |
| 1301 | |
| 1302 // Allow Access to option bytes sector | |
| 1303 HAL_FLASH_OB_Unlock(); | |
| 1304 | |
| 1305 // Get the Dual boot configuration status | |
| 1306 AdvOBInit.OptionType = OBEX_BOOTCONFIG; | |
| 1307 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
| 1308 | |
| 1309 // Enable/Disable dual boot feature | |
| 1310 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
| 1311 { | |
| 1312 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
| 1313 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1314 } | |
| 1315 else | |
| 1316 { | |
| 1317 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
| 1318 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1319 } | |
| 1320 | |
| 1321 // Start the Option Bytes programming process | |
| 1322 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1323 { | |
| 1324 // User can add here some code to deal with this error | |
| 1325 while (1) | |
| 1326 { | |
| 1327 } | |
| 1328 } | |
| 1329 // Prevent Access to option bytes sector | |
| 1330 HAL_FLASH_OB_Lock(); | |
| 1331 | |
| 1332 // Disable the Flash option control register access (recommended to protect | |
| 1333 // the option Bytes against possible unwanted operations) | |
| 1334 HAL_FLASH_Lock(); | |
| 1335 | |
| 1336 // Initiates a system reset request to reset the MCU | |
| 1337 reset_to_firmware_using_Watchdog(); | |
| 1338 } | |
| 1339 */ | |
| 1340 /** | |
| 1341 ****************************************************************************** | |
| 1342 ****************************************************************************** | |
| 1343 ****************************************************************************** | |
| 1344 */ | |
| 1345 | |
| 1346 | |
| 1347 /** | |
| 1348 * @brief DMA2D configuration. | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1349 * @note This function Configure the DMA2D peripheral : |
| 30 | 1350 * 1) Configure the transfer mode : memory to memory W/ pixel format conversion |
| 1351 * 2) Configure the output color mode as ARGB4444 | |
| 1352 * 3) Configure the output memory address at SRAM memory | |
| 1353 * 4) Configure the data size : 320x120 (pixels) | |
| 1354 * 5) Configure the input color mode as ARGB8888 | |
| 1355 * 6) Configure the input memory address at FLASH memory | |
| 1356 * @retval | |
| 1357 * None | |
| 1358 */ | |
| 1359 | |
| 1360 static void SDRAM_Config(void) | |
| 1361 { | |
| 1362 /*##-1- Configure the SDRAM device #########################################*/ | |
| 1363 /* SDRAM device configuration */ | |
| 1364 hsdram.Instance = FMC_SDRAM_DEVICE; | |
| 1365 | |
| 1366 /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */ | |
| 1367 /* TMRD: 2 Clock cycles */ | |
| 1368 SDRAM_Timing.LoadToActiveDelay = 2; | |
| 1369 /* TXSR: min=70ns (6x11.90ns) */ | |
| 1370 SDRAM_Timing.ExitSelfRefreshDelay = 7; | |
| 1371 /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */ | |
| 1372 SDRAM_Timing.SelfRefreshTime = 4; | |
| 1373 /* TRC: min=63 (6x11.90ns) */ | |
| 1374 SDRAM_Timing.RowCycleDelay = 7; | |
| 1375 /* TWR: 2 Clock cycles */ | |
| 1376 SDRAM_Timing.WriteRecoveryTime = 2; | |
| 1377 /* TRP: 15ns => 2x11.90ns */ | |
| 1378 SDRAM_Timing.RPDelay = 2; | |
| 1379 /* TRCD: 15ns => 2x11.90ns */ | |
| 1380 SDRAM_Timing.RCDDelay = 2; | |
| 1381 | |
| 1382 hsdram.Init.SDBank = FMC_SDRAM_BANK2; | |
| 1383 hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9; | |
| 1384 hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13; | |
| 1385 hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; | |
| 1386 hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; | |
| 1387 hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3; | |
| 1388 hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; | |
| 1389 hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD; | |
| 1390 hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; | |
| 1391 hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1; | |
| 1392 | |
| 1393 /* Initialize the SDRAM controller */ | |
| 1394 if(HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK) | |
| 1395 { | |
| 1396 /* Initialization Error */ | |
| 1397 Error_Handler(); | |
| 1398 } | |
| 1399 | |
| 1400 /* Program the SDRAM external device */ | |
| 1401 SDRAM_Initialization_Sequence(&hsdram, &command); | |
| 1402 } | |
| 1403 | |
| 1404 | |
| 1405 uint8_t checkResetForFirmwareUpdate(void) | |
| 1406 { | |
| 1407 uint32_t backupRegisterContent; | |
| 1408 | |
| 1409 RTC_HandleTypeDef RtcHandle; | |
| 1410 RtcHandle.Instance = RTC; | |
| 1411 backupRegisterContent = HAL_RTCEx_BKUPRead(&RtcHandle,RTC_BKP_DR0); | |
| 1412 | |
| 1413 if(backupRegisterContent == 0x12345678) | |
| 1414 return 1; | |
| 1415 else | |
| 1416 return 0; | |
| 1417 } | |
| 1418 | |
| 1419 void DeleteResetToFirmwareUpdateRegister(void) | |
| 1420 { | |
| 1421 RTC_HandleTypeDef RtcHandle; | |
| 1422 RtcHandle.Instance = RTC; | |
| 1423 __HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle); | |
| 1424 HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR0,0x00); | |
| 1425 __HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle); | |
| 1426 } | |
| 1427 | |
| 1428 #ifdef USE_FULL_ASSERT | |
| 1429 | |
| 1430 /** | |
| 1431 * @brief Reports the name of the source file and the source line number | |
| 1432 * where the assert_param error has occurred. | |
| 1433 * @param file: pointer to the source file name | |
| 1434 * @param line: assert_param error line source number | |
| 1435 * @retval None | |
| 1436 */ | |
| 1437 void assert_failed(uint8_t* file, uint32_t line) | |
| 1438 { | |
| 1439 /* User can add his own implementation to report the file name and line number, | |
| 1440 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
| 1441 | |
| 1442 /* Infinite loop */ | |
| 1443 while (1) | |
| 1444 { | |
| 1445 } | |
| 1446 } | |
| 1447 #endif | |
| 1448 | |
| 1449 /* | |
| 1450 static void DualBootToBootloader(void) | |
| 1451 { | |
| 1452 // Set BFB2 bit to enable boot from Flash Bank2 | |
| 1453 // Allow Access to Flash control registers and user Falsh | |
| 1454 HAL_FLASH_Unlock(); | |
| 1455 | |
| 1456 // Allow Access to option bytes sector | |
| 1457 HAL_FLASH_OB_Unlock(); | |
| 1458 | |
| 1459 // Get the Dual boot configuration status | |
| 1460 AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG; | |
| 1461 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
| 1462 | |
| 1463 // Enable/Disable dual boot feature | |
| 1464 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
| 1465 { | |
| 1466 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
| 1467 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1468 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1469 { | |
| 1470 while (1) | |
| 1471 { | |
| 1472 } | |
| 1473 } | |
| 1474 } | |
| 1475 else | |
| 1476 { | |
| 1477 | |
| 1478 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
| 1479 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1480 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1481 { | |
| 1482 while (1) | |
| 1483 { | |
| 1484 } | |
| 1485 } | |
| 1486 } | |
| 1487 | |
| 1488 // Prevent Access to option bytes sector | |
| 1489 HAL_FLASH_OB_Lock(); | |
| 1490 | |
| 1491 / Disable the Flash option control register access (recommended to protect | |
| 1492 // the option Bytes against possible unwanted operations) | |
| 1493 HAL_FLASH_Lock(); | |
| 1494 | |
| 1495 // Initiates a system reset request to reset the MCU | |
| 1496 reset_to_firmware_using_Watchdog(); | |
| 1497 } | |
| 1498 */ | |
| 1499 | |
| 1500 void reset_to_update_using_system_reset(void) | |
| 1501 { | |
| 1502 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
| 1503 HAL_NVIC_SystemReset(); | |
| 1504 } | |
| 1505 | |
| 1506 void reset_to_firmware_using_Watchdog(void) | |
| 1507 { | |
| 1508 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
| 1509 __HAL_RCC_WWDG_CLK_ENABLE(); | |
| 1510 | |
| 1511 WWDG_HandleTypeDef WwdgHandle; | |
| 1512 WwdgHandle.Instance = WWDG; | |
| 1513 | |
| 1514 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8; | |
| 1515 WwdgHandle.Init.Window = 80; | |
| 1516 WwdgHandle.Init.Counter = 127; | |
| 1517 | |
| 1518 HAL_WWDG_Init(&WwdgHandle); | |
| 869 | 1519 /* HAL_WWDG_Start(&WwdgHandle); has been removed from HAL library starting_V120 */ |
| 30 | 1520 while(1); |
| 1521 } | |
| 1522 | |
| 1523 | |
| 1524 void set_returnFromComm(void) | |
| 1525 { | |
| 1526 returnFromCommCleanUpRequest = 1; | |
| 1527 } | |
| 1528 | |
| 1529 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
