Mercurial > public > ostc4
annotate BootLoader/Src/base_bootlader.c @ 1015:4ef0511c6665 BootloaderOstc5
Bootloader: Cleanup memory map
The images for OSTC and battery are not needed by the bootloader => removed. Because the Bootloader does not need access to the upper font section the references have been removed from linker file
| author | Ideenmodellierer |
|---|---|
| date | Tue, 06 May 2025 21:56:03 +0200 |
| parents | f1b78bc8de10 |
| children | 0dd92e9b70a2 |
| 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 | |
| 869 | 226 #include "Fonts/Font_T48_plus.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 | |
| 242 /* Private define ------------------------------------------------------------*/ | |
| 243 #define BUFFER_SIZE ((uint32_t)0x00177000) | |
| 244 #define WRITE_READ_ADDR ((uint32_t)0x0000) | |
| 245 #define REFRESH_COUNT ((uint32_t)0x0569) /* SDRAM refresh counter (90Mhz SD clock) */ | |
| 246 | |
| 247 /* Private macro -------------------------------------------------------------*/ | |
| 248 /* Private variables ---------------------------------------------------------*/ | |
| 249 uint8_t returnFromCommCleanUpRequest = 0; | |
| 250 | |
| 251 const SFirmwareData bootloader_FirmwareData __attribute__(( section(".bootloader_firmware_data") )) = | |
| 252 { | |
| 253 .versionFirst = 1, | |
| 254 .versionSecond = 0, | |
| 255 .versionThird = 1, | |
| 256 .versionBeta = 1, | |
| 257 | |
| 258 /* 4 bytes with trailing 0 */ | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
259 .signature = "mh", |
| 30 | 260 |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
261 .release_year = 25, |
|
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
262 .release_month = 1, |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
263 .release_day = 13, |
| 30 | 264 .release_sub = 0, |
| 265 | |
| 266 /* max 48 with trailing 0 */ | |
| 267 .release_info ="tComm with all", | |
| 268 | |
| 269 /* for safety reasons and coming functions*/ | |
| 270 .magic[0] = FIRMWARE_MAGIC_FIRST, | |
| 271 .magic[1] = FIRMWARE_MAGIC_SECOND, | |
| 272 .magic[2] = FIRMWARE_MAGIC_FIRMWARE, /* the magic byte */ | |
| 273 .magic[3] = FIRMWARE_MAGIC_END | |
| 274 }; | |
| 275 | |
| 965 | 276 const SHardwareData HardwareData __attribute__((section(".bootloader_hardware_data"))) = |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
277 { |
| 30 | 278 |
| 279 // first 52 bytes | |
| 280 .primarySerial = 0xFFFF, | |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
281 .primaryLicence = 0x00, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
282 .revision8bit = 0x02, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
283 .production_year = 0x19, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
284 .production_month = 0x01, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
285 .production_day = 0x10, |
| 30 | 286 .production_bluetooth_name_set = 0xFF, |
| 287 | |
| 288 .production_info = { | |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
289 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x4F,0x53,0x54,0x43, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
290 0x20,0x35,0x20,0x65,0x6E,0x64,0x2D,0x32,0x30,0x32,0x34, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
291 0x20,0x68,0x61,0x72,0x64,0x77,0x61,0x72,0x65,0x20,0x20, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
292 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}, |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
293 |
|
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
294 /* 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 30 | 295 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 296 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |
| 297 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
298 */ |
| 30 | 299 // other 12 bytes (64 in total) |
| 300 .secondarySerial = 0xFFFF, | |
| 301 .secondaryLicence = 0xFF, | |
| 302 .secondaryReason8bit = 0xFF, | |
| 303 .secondary_year = 0xFF, | |
| 304 .secondary_month = 0xFF, | |
| 305 .secondary_day = 0xFF, | |
| 306 .secondary_bluetooth_name_set = 0xFF, | |
| 307 .secondary_info = {0xFF,0xFF,0xFF,0xFF} | |
| 308 }; | |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
309 |
| 30 | 310 |
| 311 RTC_HandleTypeDef RtcHandle; | |
| 312 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ | |
| 313 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ | |
| 314 | |
| 315 uint32_t time_before; | |
| 316 uint32_t time_between; | |
| 317 uint32_t time_after; | |
| 318 | |
| 319 /* SDRAM handler declaration */ | |
| 320 SDRAM_HandleTypeDef hsdram; | |
| 321 FMC_SDRAM_TimingTypeDef SDRAM_Timing; | |
| 322 FMC_SDRAM_CommandTypeDef command; | |
| 323 | |
| 324 FLASH_OBProgramInitTypeDef OBInit; | |
| 325 FLASH_AdvOBProgramInitTypeDef AdvOBInit; | |
| 326 | |
| 327 | |
| 328 /* Private variables with external access ------------------------------------*/ | |
| 329 | |
| 330 uint32_t globalStateID = 0; | |
| 331 uint8_t globalModeID = SURFMODE; | |
| 332 uint32_t time_without_button_pressed_deciseconds = 0; | |
| 333 uint8_t bootToBootloader = 0; | |
| 334 | |
| 335 /* Private function prototypes -----------------------------------------------*/ | |
| 336 | |
| 337 //static void LCD_ToggleFramebuffer(GFX_DrawCfgTypeDef *hconfig); | |
| 338 //static void LCD_Config(GFX_DrawCfgTypeDef *hconfig); | |
| 339 static void SystemClock_Config(void); | |
| 340 static void Error_Handler(void); | |
| 341 | |
| 342 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command); | |
| 343 static void SDRAM_Config(void); | |
| 344 //static void DualBoot(void); | |
| 345 static void EXTILine_Buttons_Config(void); | |
| 346 //static void RTC_init(void); | |
| 347 static void TIM_init(void); | |
| 348 static void TIM_BACKLIGHT_init(void); | |
| 349 //static void TIM_BACKLIGHT_adjust(void); | |
| 350 static void gotoSleep(void); | |
| 351 uint8_t checkResetForFirmwareUpdate(void); | |
| 352 void DeleteResetToFirmwareUpdateRegister(void); | |
| 353 void reset_to_firmware_using_Watchdog(void); | |
| 354 void reset_to_update_using_system_reset(void); | |
| 355 | |
| 356 //static void DualBootToBootloader(void); | |
| 357 | |
| 358 /* ITM Trace-------- ---------------------------------------------------------*/ | |
| 359 /* | |
| 360 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) | |
| 361 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) | |
| 362 #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n))) | |
| 363 | |
| 364 #define DEMCR (*((volatile unsigned long *)(0xE000EDFC))) | |
| 365 #define TRCENA 0x01000000 | |
| 366 | |
| 367 struct __FILE { int handle; }; | |
| 368 FILE __stdout; | |
| 369 FILE __stdin; | |
| 370 | |
| 371 int fputc(int ch, FILE *f) { | |
| 372 if (DEMCR & TRCENA) { | |
| 373 while (ITM_Port32(0) == 0); | |
| 374 ITM_Port8(0) = ch; | |
| 375 } | |
| 376 return(ch); | |
| 377 } | |
| 378 */ | |
| 379 | |
| 380 /* Private functions ---------------------------------------------------------*/ | |
| 381 | |
| 382 /** | |
| 383 * @brief Main program | |
| 384 * @param None | |
| 385 * @retval None | |
| 386 */ | |
| 387 | |
| 388 void GPIO_test_I2C_lines(void) | |
| 389 { | |
| 390 GPIO_InitTypeDef GPIO_InitStructure; | |
| 391 __GPIOA_CLK_ENABLE(); | |
| 392 __GPIOG_CLK_ENABLE(); | |
| 393 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
| 394 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
| 395 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
| 396 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
| 397 HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); | |
| 398 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
| 399 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
| 400 | |
| 401 while(1) | |
| 402 { | |
| 403 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_SET); | |
| 404 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_RESET); | |
| 405 HAL_Delay(10); | |
| 406 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_7,GPIO_PIN_RESET); | |
| 407 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_SET); | |
| 408 HAL_Delay(10); | |
| 409 } | |
| 410 } | |
| 411 | |
| 991 | 412 int __attribute__((optimize("O0"))) main(void) |
| 30 | 413 { |
| 414 | |
| 415 /* | |
| 416 HAL_Init(); | |
| 417 SystemClock_Config(); | |
| 418 GPIO_test_I2C_lines(); | |
| 419 */ | |
| 420 uint32_t pLayerInvisible; | |
| 421 uint32_t firmware_load_result; | |
| 422 uint8_t magicbyte = 0; | |
| 423 uint8_t callForUpdate; | |
| 424 uint8_t status = 0; | |
| 425 char textVersion[32]; | |
| 426 uint8_t ptr; | |
| 427 uint32_t pOffset; | |
| 428 | |
| 869 | 429 const SHardwareData* HardwareData = hardwareDataGetPointer(); |
| 430 | |
| 30 | 431 set_globalState(StBoot0); |
| 432 | |
| 433 HAL_Init(); | |
| 434 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); | |
| 869 | 435 SystemClock_Config(); |
| 436 | |
| 437 MX_GPIO_Init(); | |
| 30 | 438 |
| 439 /* button press is only 40 to 50 us low */ | |
| 440 MX_GPIO_One_Button_only_Init(); | |
| 441 | |
| 991 | 442 uint32_t i = 4000000; |
| 30 | 443 |
| 444 callForUpdate = __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST); | |
| 445 | |
| 446 if(callForUpdate) | |
| 447 { | |
| 448 i = 0; | |
| 449 } | |
| 450 else | |
| 451 if( (firmware_MainCodeIsProgammed() == 0) | |
| 869 | 452 || (HardwareData->primarySerial == 0xFFFF) |
| 453 || (HardwareData->production_bluetooth_name_set == 0xFF)) | |
| 30 | 454 { |
| 455 i = 1; | |
| 456 } | |
| 457 else | |
| 458 { | |
| 459 while(MX_GPIO_Read_The_One_Button() && i) | |
| 460 { | |
| 461 i--; | |
| 462 __NOP(); | |
| 463 } | |
| 464 if(i) | |
| 465 { | |
| 991 | 466 i = 4000000; |
| 30 | 467 while(!MX_GPIO_Read_The_One_Button() && i) |
| 468 { | |
| 469 i--; | |
| 470 __NOP(); | |
| 471 } | |
| 472 if(i) | |
| 473 { | |
| 991 | 474 i = 4000000; |
| 30 | 475 while(MX_GPIO_Read_The_One_Button() && i) |
| 476 { | |
| 477 i--; | |
| 478 __NOP(); | |
| 479 } | |
| 480 } | |
| 481 } | |
| 482 } | |
| 483 | |
| 484 if((i == 0) && (callForUpdate == 0)) | |
| 485 firmware_JumpTo_Application(); | |
| 486 | |
| 487 MX_SPI_Init(); | |
| 488 SDRAM_Config(); | |
| 489 HAL_Delay(100); | |
| 490 | |
| 491 GFX_init1_no_DMA(&pLayerInvisible, 2); | |
| 492 | |
| 493 TIM_BACKLIGHT_init(); | |
| 494 | |
| 495 // ----------------------------- | |
| 496 | |
| 497 display_power_on__1_of_2__pre_RGB(); | |
| 498 GFX_LTDC_Init(); | |
| 499 GFX_LTDC_LayerDefaultInit(TOP_LAYER, pLayerInvisible); | |
| 500 GFX_LTDC_LayerDefaultInit(BACKGRD_LAYER, pLayerInvisible); | |
| 501 GFX_SetFramesTopBottom(pLayerInvisible,pLayerInvisible,480); | |
| 502 HAL_Delay(20); | |
| 503 display_power_on__2_of_2__post_RGB(); | |
| 504 | |
| 505 // ----------------------------- | |
| 506 GFX_change_LTDC(); | |
| 507 GFX_hwBackgroundOn(); | |
| 508 GFX_change_LTDC(); | |
| 509 // ----------------------------- | |
| 510 tInfoBootloader_init(); | |
| 511 // ----------------------------- | |
| 512 if(i == 0) | |
| 513 { | |
| 514 tInfo_newpage("load firmware data"); | |
| 515 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */ | |
| 516 firmware_load_result = ext_flash_read_firmware(pBuffer,768000, &magicbyte); | |
| 517 | |
| 518 if((firmware_load_result > 0) && (firmware_load_result < 768000) && (magicbyte == 0xEE)) | |
| 519 { | |
| 520 ptr = ext_flash_read_firmware_version(textVersion); | |
| 521 textVersion[ptr++] = 'f'; | |
| 522 textVersion[ptr++] = 'o'; | |
| 523 textVersion[ptr++] = 'u'; | |
| 524 textVersion[ptr++] = 'n'; | |
| 525 textVersion[ptr++] = 'd'; | |
| 526 textVersion[ptr] = 0; | |
| 527 | |
| 528 tInfo_newpage(textVersion); | |
| 529 tInfo_write("erase flash"); | |
| 530 status = firmware_eraseFlashMemory(); | |
| 531 if(status != HAL_OK) | |
| 532 { | |
| 533 tInfo_newpage("error. try again."); | |
| 534 status = firmware_eraseFlashMemory(); | |
| 535 if(status != HAL_OK) | |
| 536 { | |
| 537 tInfo_newpage("error. skip update."); | |
| 538 HAL_Delay(1000); | |
| 539 } | |
| 540 } | |
| 541 if(status == HAL_OK) | |
| 542 { | |
| 252 | 543 tInfo_write("program flash"); |
| 30 | 544 status = firmware_programFlashMemory(pBuffer,firmware_load_result); |
| 545 if(status != HAL_OK) | |
| 546 { | |
| 547 tInfo_newpage("error. try again."); | |
| 548 status = firmware_programFlashMemory(pBuffer,firmware_load_result); | |
| 549 if(status != HAL_OK) | |
| 550 { | |
| 551 tInfo_newpage("error. skip update."); | |
| 552 HAL_Delay(1000); | |
| 553 } | |
| 554 } | |
| 555 } | |
| 556 } | |
| 557 } | |
| 558 | |
| 559 /* here comes the variable upper firmware loader */ | |
| 560 if((i == 0) && (status == HAL_OK)) | |
| 561 { | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
562 tInfo_newpage("load fontpack data"); |
| 30 | 563 uint8_t* pBuffer = (uint8_t*)((uint32_t)0xD0000000); /* blocked via GFX_init1_no_DMA */ |
| 564 firmware_load_result = ext_flash_read_firmware2(&pOffset, pBuffer,768000*2,0,0); | |
| 565 | |
| 566 if((firmware_load_result > 0) && (firmware_load_result + pOffset <= 1024000)) | |
| 567 { | |
| 568 ptr = 0; | |
| 569 ptr += gfx_number_to_string(7,0,&textVersion[ptr],firmware_load_result); | |
| 570 textVersion[ptr++] = ' '; | |
| 571 textVersion[ptr++] = 'b'; | |
| 572 textVersion[ptr++] = 'y'; | |
| 573 textVersion[ptr++] = 't'; | |
| 574 textVersion[ptr++] = 'e'; | |
| 575 textVersion[ptr++] = 's'; | |
| 576 textVersion[ptr++] = ' '; | |
| 577 textVersion[ptr++] = 'w'; | |
| 578 textVersion[ptr++] = 'i'; | |
| 579 textVersion[ptr++] = 't'; | |
| 580 textVersion[ptr++] = 'h'; | |
| 581 textVersion[ptr++] = ' '; | |
| 582 ptr += gfx_number_to_string(7,0,&textVersion[ptr],pOffset); | |
| 583 textVersion[ptr++] = ' '; | |
| 584 textVersion[ptr++] = 'o'; | |
| 585 textVersion[ptr++] = 'f'; | |
| 586 textVersion[ptr++] = 'f'; | |
| 587 textVersion[ptr++] = 's'; | |
| 588 textVersion[ptr++] = 'e'; | |
| 589 textVersion[ptr++] = 't'; | |
| 590 textVersion[ptr] = 0; | |
| 591 tInfo_newpage(textVersion); | |
| 592 | |
| 593 ptr = 0; | |
| 594 textVersion[ptr++] = 'f'; | |
| 595 textVersion[ptr++] = 'o'; | |
| 596 textVersion[ptr++] = 'u'; | |
| 597 textVersion[ptr++] = 'n'; | |
| 598 textVersion[ptr++] = 'd'; | |
| 599 textVersion[ptr] = 0; | |
| 600 | |
| 601 tInfo_write(textVersion); | |
| 602 tInfo_write("erase flash"); | |
| 603 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset); | |
| 604 if(status != HAL_OK) | |
| 605 { | |
| 606 tInfo_newpage("error. try again."); | |
| 607 status = firmware2_variable_upperpart_eraseFlashMemory(firmware_load_result,pOffset); | |
| 608 if(status != HAL_OK) | |
| 609 { | |
| 610 tInfo_newpage("error. skip update."); | |
| 611 HAL_Delay(1000); | |
| 612 } | |
| 613 } | |
| 614 if(status == HAL_OK) | |
| 615 { | |
| 252 | 616 tInfo_write("program flash"); |
| 30 | 617 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0); |
| 618 if(status != HAL_OK) | |
| 619 { | |
| 620 tInfo_newpage("error. try again."); | |
| 621 status = firmware2_variable_upperpart_programFlashMemory(firmware_load_result,pOffset,pBuffer,firmware_load_result,0); | |
| 622 if(status != HAL_OK) | |
| 623 { | |
| 624 tInfo_newpage("error. skip update."); | |
| 625 HAL_Delay(1000); | |
| 626 } | |
| 627 } | |
| 628 } | |
| 629 } | |
| 630 } | |
| 631 | |
| 632 if((i == 0) && (status == HAL_OK)) | |
| 633 { | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
634 tInfo_newpage("done."); |
|
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
635 tInfo_write("cleaning."); |
| 30 | 636 ext_flash_erase_firmware_if_not_empty(); |
| 637 ext_flash_erase_firmware2_if_not_empty(); | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
638 tInfo_write("reset device."); |
| 30 | 639 reset_to_firmware_using_Watchdog(); |
| 640 } | |
| 641 | |
| 642 ptr = 0; | |
| 880 | 643 textVersion[ptr++] = '\020'; |
| 30 | 644 textVersion[ptr++] = 's'; |
| 645 textVersion[ptr++] = 'e'; | |
| 646 textVersion[ptr++] = 'r'; | |
| 647 textVersion[ptr++] = 'i'; | |
| 648 textVersion[ptr++] = 'a'; | |
| 649 textVersion[ptr++] = 'l'; | |
| 650 textVersion[ptr++] = ' '; | |
| 869 | 651 if(HardwareData->primarySerial == 0xFFFF) |
| 30 | 652 { |
| 653 textVersion[ptr++] = 'n'; | |
| 654 textVersion[ptr++] = 'o'; | |
| 655 textVersion[ptr++] = 't'; | |
| 656 textVersion[ptr++] = ' '; | |
| 657 textVersion[ptr++] = 's'; | |
| 658 textVersion[ptr++] = 'e'; | |
| 659 textVersion[ptr++] = 't'; | |
| 660 } | |
| 869 | 661 else if(HardwareData->secondarySerial == 0xFFFF) |
| 30 | 662 { |
| 663 textVersion[ptr++] = '#'; | |
| 869 | 664 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
| 30 | 665 } |
| 666 else | |
| 667 { | |
| 668 textVersion[ptr++] = '#'; | |
| 869 | 669 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->secondarySerial); |
| 30 | 670 textVersion[ptr++] = ' '; |
| 671 textVersion[ptr++] = '('; | |
| 869 | 672 ptr += gfx_number_to_string(5,1,&textVersion[ptr],HardwareData->primarySerial); |
| 30 | 673 textVersion[ptr++] = ')'; |
| 674 } | |
| 675 textVersion[ptr++] = '\020'; | |
| 676 textVersion[ptr] = 0; | |
| 677 | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
678 TIM_init(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
679 MX_UART_Init(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
680 MX_Bluetooth_PowerOn(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
681 tComm_init(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
682 |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
683 tInfo_button_text("exit","","sleep"); |
|
963
c19c8f17a9f3
hard-coded hardwaredata for testing purposes
heinrichsweikamp
parents:
960
diff
changeset
|
684 tInfo_newpage("bootloader 250113"); |
| 30 | 685 tInfo_write("start bluetooth"); |
| 686 tInfo_write(""); | |
| 687 tInfo_write(textVersion); | |
| 992 | 688 #if 0 |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
689 if(tComm_Set_Bluetooth_Name(0) == 0xFF) |
| 992 | 690 #else |
| 691 if(hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF) | |
| 692 #endif | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
693 { |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
694 tInfo_write("init bluetooth"); |
| 986 | 695 tComm_StartBlueModBaseInit(); |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
696 } |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
697 else |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
698 { |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
699 tInfo_write("bluetooth set"); |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
700 tComm_StartBlueModConfig(); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
869
diff
changeset
|
701 } |
| 30 | 702 |
| 703 set_globalState_Base(); | |
| 704 | |
| 705 GFX_start_VSYNC_IRQ(); | |
| 706 | |
| 707 EXTILine_Buttons_Config(); | |
| 708 /* | |
| 709 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
| 710 firmware_load_result = ext_flash_read_firmware(pBuffer1,768000); | |
| 711 | |
| 712 if((firmware_load_result > 0) && (firmware_load_result < 768000)) | |
| 713 { | |
| 714 firmware_eraseFlashMemory(); | |
| 715 firmware_programFlashMemory(pBuffer1,firmware_load_result); | |
| 716 // not for testing | |
| 717 //ext_flash_erase_firmware_if_not_empty(); | |
| 718 reset_to_firmware_using_Watchdog(); | |
| 719 } | |
| 720 */ | |
| 721 while(1) | |
| 722 { | |
| 723 // if(bootToBootloader) | |
| 724 // DualBootToBootloader(); | |
| 725 | |
| 726 if(bootToBootloader) | |
| 727 reset_to_update_using_system_reset(); | |
| 728 | |
| 729 tComm_control(); // will stop while loop if tComm Mode started until exit from UART | |
| 730 }; | |
| 731 } | |
| 732 | |
| 733 | |
| 734 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |
| 735 { | |
| 736 | |
| 737 SStateList status; | |
| 738 | |
| 739 get_globalStateList(&status); | |
| 740 | |
| 741 switch(status.base) | |
| 742 { | |
| 743 default: | |
| 744 // TIM_BACKLIGHT_adjust(); | |
| 745 break; | |
| 746 } | |
| 747 | |
| 748 if(returnFromCommCleanUpRequest) | |
| 749 { | |
| 750 tComm_exit(); | |
| 751 returnFromCommCleanUpRequest = 0; | |
| 752 GFX_hwBackgroundOn(); | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
753 tInfo_button_text("exit","","sleep"); |
| 30 | 754 tInfo_newpage("bluetooth disonnected"); |
| 755 tInfo_write(""); | |
| 756 tInfo_write(""); | |
| 757 tInfo_write(""); | |
| 758 tInfo_write(""); | |
| 759 } | |
| 760 | |
| 761 get_globalStateList(&status); | |
| 762 | |
| 763 switch(status.base) | |
| 764 { | |
| 765 case BaseComm: | |
| 766 if(get_globalState() == StUART_STANDARD) | |
| 767 tComm_refresh(); | |
| 768 break; | |
| 769 default: | |
| 770 break; | |
| 771 } | |
| 772 } | |
| 773 | |
| 774 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | |
| 775 { | |
| 776 uint8_t action; | |
| 777 SStateList status; | |
| 778 static uint8_t counterToPreventSleep = 0; | |
| 779 if(GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten | |
| 780 { | |
| 781 GFX_change_LTDC(); | |
| 782 housekeepingFrame(); | |
| 783 if(counterToPreventSleep < 250) | |
| 784 counterToPreventSleep++; | |
| 785 else | |
| 786 if(counterToPreventSleep != 255) | |
| 787 { | |
| 788 counterToPreventSleep = 255; | |
| 789 } | |
| 790 | |
| 791 return; | |
| 792 } | |
| 793 | |
| 794 time_without_button_pressed_deciseconds = 0; | |
| 795 | |
| 796 if(GFX_logoStatus() != 0) | |
| 797 return; | |
| 798 | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
799 if(GPIO_Pin == BUTTON_BACK_PIN) // left |
| 30 | 800 action = ACTION_BUTTON_BACK; |
| 801 else | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
802 if(GPIO_Pin == BUTTON_ENTER_PIN) // center |
| 30 | 803 action = ACTION_BUTTON_ENTER; |
| 804 else | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
805 if(GPIO_Pin == BUTTON_NEXT_PIN) // right |
| 30 | 806 action = ACTION_BUTTON_NEXT; |
| 807 #ifdef BUTTON_CUSTOM_PIN | |
| 808 else | |
| 809 if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra | |
| 810 action = ACTION_BUTTON_CUSTOM; | |
| 811 #endif | |
| 812 else | |
| 813 action = 0; | |
| 814 get_globalStateList(&status); | |
| 815 | |
| 971 | 816 if(status.base == BaseComm) |
| 30 | 817 { |
| 818 if(action == ACTION_BUTTON_BACK) | |
| 819 { | |
| 820 reset_to_firmware_using_Watchdog(); | |
| 821 } | |
| 971 | 822 } |
| 823 else | |
| 824 { | |
| 825 switch (action) | |
| 826 { | |
| 827 case ACTION_BUTTON_NEXT: if((counterToPreventSleep == 255) && (get_globalState() == StS)) | |
| 828 { | |
| 829 while(1) | |
| 830 { | |
| 831 MX_tell_reset_logik_alles_ok(); | |
| 832 DataEX_call(); | |
| 833 HAL_Delay(100); | |
| 834 } | |
| 835 } | |
| 836 break; | |
| 837 case ACTION_BUTTON_BACK: reset_to_firmware_using_Watchdog(); | |
| 838 break; | |
| 839 case ACTION_BUTTON_CUSTOM: if(get_globalState() == StS) | |
| 840 { | |
| 841 gotoSleep(); | |
| 842 } | |
| 843 break; | |
| 844 case ACTION_BUTTON_ENTER: /* reset_to_update_using_system_reset(); old function */ | |
| 845 tComm_StartBlueModBaseInit(); /* new: factory reset bluetooth */ | |
| 846 break; | |
| 847 default: | |
| 848 break; | |
| 849 } | |
| 30 | 850 } |
| 851 } | |
| 852 | |
| 853 | |
| 854 void gotoSleep(void) | |
| 855 { | |
| 856 ext_flash_erase_firmware_if_not_empty(); | |
| 857 set_globalState(StStop); | |
| 858 } | |
| 859 | |
| 860 // ----------------------------- | |
| 861 | |
| 862 | |
| 863 void MainBootLoaderInit(void) | |
| 864 { | |
| 865 void (*SysMemBootJump)(void); | |
| 866 SysMemBootJump=(void (*)(void)) (*((uint32_t *) 0x1fff0004)); | |
| 867 | |
| 868 // DMA, SPI, UART, TIM, ExtIRQ, graphics DMA, LTDC | |
| 869 | |
| 870 HAL_RCC_DeInit(); | |
| 871 SysTick->CTRL = 0; | |
| 872 SysTick->LOAD = 0; | |
| 873 SysTick->VAL = 0; | |
| 874 | |
| 875 __set_PRIMASK(1); | |
| 876 | |
| 877 __set_MSP(0x20002318); | |
| 878 SysMemBootJump(); | |
| 879 } | |
| 880 | |
| 881 uint32_t get_globalState(void) | |
| 882 { | |
| 883 return globalStateID; | |
| 884 } | |
| 885 | |
| 886 void get_globalStateList(SStateList *output) | |
| 887 { | |
| 888 output->base = (uint8_t)((globalStateID >> 28) & 0x0F); | |
| 889 output->page = (uint8_t)((globalStateID >> 24) & 0x0F); | |
| 890 output->line = (uint8_t)((globalStateID >> 16) & 0xFF); | |
| 891 output->field = (uint8_t)((globalStateID >> 8) & 0xFF); | |
| 892 output->mode = (uint8_t)((globalStateID ) & 0xFF); | |
| 893 } | |
| 894 | |
| 895 void get_idSpecificStateList(uint32_t id, SStateList *output) | |
| 896 { | |
| 897 output->base = (uint8_t)((id >> 28) & 0x0F); | |
| 898 output->page = (uint8_t)((id >> 24) & 0x0F); | |
| 899 output->line = (uint8_t)((id >> 16) & 0xFF); | |
| 900 output->field = (uint8_t)((id >> 8) & 0xFF); | |
| 901 output->mode = (uint8_t)((id ) & 0xFF); | |
| 902 } | |
| 903 | |
| 904 void set_globalState_Base(void) | |
| 905 { | |
| 906 set_globalState(StS); | |
| 907 } | |
| 908 | |
| 909 void set_globalState_Menu_Page(uint8_t page) | |
| 910 { | |
| 911 globalStateID = ((BaseMenu << 28) + (page << 24)); | |
| 912 } | |
| 913 | |
| 914 void set_globalState_Log_Page(uint8_t pageIsLine) | |
| 915 { | |
| 916 globalStateID = StILOGLIST + (pageIsLine << 16); | |
| 917 } | |
| 918 | |
| 919 | |
| 920 void set_globalState_Menu_Line(uint8_t line) | |
| 921 { | |
| 922 globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16)); | |
| 923 } | |
| 924 | |
| 925 | |
| 926 void set_globalState(uint32_t newID) | |
| 927 { | |
| 928 globalStateID = newID; | |
| 929 } | |
| 930 | |
| 931 | |
| 932 | |
| 933 void delayMicros(uint32_t micros) | |
| 934 { | |
| 935 micros = micros * (168/4) - 10; | |
| 936 while(micros--); | |
| 937 } | |
| 938 | |
| 939 | |
| 940 void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget, RTC_TimeTypeDef * stimestructureget) | |
| 941 { | |
| 942 /* Get the RTC current Time */ | |
| 943 if(sdatestructureget) | |
| 944 HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN); | |
| 945 /* Get the RTC current Date */ | |
| 946 if(stimestructureget) | |
| 947 HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN); | |
| 948 } | |
| 949 | |
| 950 | |
| 951 void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure, RTC_TimeTypeDef * stimestructure) | |
| 952 { | |
| 953 if(sdatestructure) | |
| 954 if(HAL_RTC_SetDate(&RtcHandle,sdatestructure,FORMAT_BCD) != HAL_OK) | |
| 955 { | |
| 956 /* Initialization Error */ | |
| 957 Error_Handler(); | |
| 958 } | |
| 959 | |
| 960 if(stimestructure) | |
| 961 if(HAL_RTC_SetTime(&RtcHandle,stimestructure,FORMAT_BCD) != HAL_OK) | |
| 962 { | |
| 963 /* Initialization Error */ | |
| 964 Error_Handler(); | |
| 965 } | |
| 966 } | |
| 967 | |
| 968 static void TIM_init(void) | |
| 969 { | |
| 970 uint16_t uwPrescalerValue = 0; | |
| 971 | |
| 972 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1; | |
| 973 | |
| 974 /* Set TIMx instance */ | |
| 975 TimHandle.Instance = TIMx; | |
| 976 | |
| 977 /* Initialize TIM3 peripheral as follows: | |
| 978 + Period = 10000 - 1 | |
| 979 + Prescaler = ((SystemCoreClock/2)/10000) - 1 | |
| 980 + ClockDivision = 0 | |
| 981 + Counter direction = Up | |
| 982 */ | |
| 983 TimHandle.Init.Period = 1000 - 1; | |
| 984 TimHandle.Init.Prescaler = uwPrescalerValue; | |
| 985 TimHandle.Init.ClockDivision = 0; | |
| 986 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
| 987 if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK) | |
| 988 { | |
| 989 /* Initialization Error */ | |
| 990 Error_Handler(); | |
| 991 } | |
| 992 | |
| 993 /*##-2- Start the TIM Base generation in interrupt mode ####################*/ | |
| 994 /* Start Channel1 */ | |
| 995 if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) | |
| 996 { | |
| 997 /* Starting Error */ | |
| 998 Error_Handler(); | |
| 999 } | |
| 1000 } | |
| 1001 | |
| 1002 #ifndef TIM_BACKLIGHT | |
| 1003 /* | |
| 1004 static void TIM_BACKLIGHT_adjust(void) | |
| 1005 { | |
| 1006 } | |
| 1007 */ | |
| 1008 static void TIM_BACKLIGHT_init(void) | |
| 1009 { | |
| 1010 } | |
| 1011 #else | |
| 1012 /* | |
| 1013 static void TIM_BACKLIGHT_adjust(void) | |
| 1014 { | |
| 1015 | |
| 1016 TIM_OC_InitTypeDef sConfig; | |
| 1017 sConfig.OCMode = TIM_OCMODE_PWM1; | |
| 1018 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
| 1019 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
| 1020 sConfig.Pulse = 600; | |
| 1021 | |
| 1022 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
| 1023 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
| 1024 } | |
| 1025 */ | |
| 1026 static void TIM_BACKLIGHT_init(void) | |
| 1027 { | |
| 1028 uint32_t uwPrescalerValue = 0; | |
| 1029 TIM_OC_InitTypeDef sConfig; | |
| 1030 | |
| 1031 uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 18000000) - 1; | |
| 1032 | |
| 1033 TimBacklightHandle.Instance = TIM_BACKLIGHT; | |
| 1034 | |
| 1035 // Initialize TIM3 peripheral as follows: 30 kHz | |
| 1036 | |
| 1037 TimBacklightHandle.Init.Period = 600 - 1; | |
| 1038 TimBacklightHandle.Init.Prescaler = uwPrescalerValue; | |
| 1039 TimBacklightHandle.Init.ClockDivision = 0; | |
| 1040 TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
| 1041 HAL_TIM_PWM_Init(&TimBacklightHandle); | |
| 1042 | |
| 1043 sConfig.OCMode = TIM_OCMODE_PWM1; | |
| 1044 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; | |
| 1045 sConfig.OCFastMode = TIM_OCFAST_DISABLE; | |
| 1046 sConfig.Pulse = 50 * 6; | |
| 1047 | |
| 1048 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); | |
| 1049 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); | |
| 1050 } | |
| 1051 #endif | |
| 1052 | |
| 1053 /* Configure RTC prescaler and RTC data registers */ | |
| 1054 /* RTC configured as follow: | |
| 1055 - Hour Format = Format 24 | |
| 1056 - Asynch Prediv = Value according to source clock | |
| 1057 - Synch Prediv = Value according to source clock | |
| 1058 - OutPut = Output Disable | |
| 1059 - OutPutPolarity = High Polarity | |
| 1060 - OutPutType = Open Drain */ | |
| 1061 /*#define RTC_ASYNCH_PREDIV 0x7F LSE as RTC clock */ | |
| 1062 /*LSE: #define RTC_SYNCH_PREDIV 0x00FF LSE as RTC clock */ | |
| 1063 /*LSI: #define RTC_SYNCH_PREDIV 0x0130 LSI as RTC clock */ | |
| 1064 /* | |
| 1065 static void RTC_init(void) | |
| 1066 { | |
| 1067 RtcHandle.Instance = RTC; | |
| 1068 | |
| 1069 | |
| 1070 RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
| 1071 RtcHandle.Init.AsynchPrediv = 0x7F; | |
| 1072 RtcHandle.Init.SynchPrediv = 0x0130; | |
| 1073 RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
| 1074 RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
| 1075 RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
| 1076 | |
| 1077 if(HAL_RTC_Init(&RtcHandle) != HAL_OK) | |
| 1078 { | |
| 1079 Error_Handler(); | |
| 1080 } | |
| 1081 } | |
| 1082 */ | |
| 1083 | |
| 1084 static void EXTILine_Buttons_Config(void) | |
| 1085 { | |
| 1086 GPIO_InitTypeDef GPIO_InitStructure; | |
| 1087 | |
| 1088 BUTTON_ENTER_GPIO_ENABLE(); | |
| 1089 BUTTON_NEXT_GPIO_ENABLE(); | |
| 1090 BUTTON_BACK_GPIO_ENABLE(); | |
| 1091 | |
| 1092 /* Configure pin as weak PULLUP input */ | |
| 1093 /* buttons */ | |
| 1094 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
| 1095 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
| 1096 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
| 1097 | |
| 1098 GPIO_InitStructure.Pin = BUTTON_ENTER_PIN; | |
| 1099 HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure); | |
| 1100 | |
| 1101 GPIO_InitStructure.Pin = BUTTON_NEXT_PIN; | |
| 1102 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure); | |
| 1103 | |
| 1104 GPIO_InitStructure.Pin = BUTTON_BACK_PIN; | |
| 1105 HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure); | |
| 1106 | |
| 1107 /* Enable and set EXTI Line0 Interrupt to the lowest priority */ | |
| 1108 HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0); | |
| 1109 HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn, 2, 0); | |
| 1110 HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn, 2, 0); | |
| 1111 HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn); | |
| 1112 HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn); | |
| 1113 HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn); | |
| 1114 | |
| 1115 #ifdef BUTTON_CUSTOM_PIN | |
| 1116 BUTTON_CUSTOM_GPIO_ENABLE(); | |
| 1117 GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN; | |
| 1118 HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure); | |
| 1119 HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn, 2, 0); | |
| 1120 HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn); | |
| 1121 #endif | |
| 1122 } | |
| 1123 | |
| 1124 | |
| 1125 /** | |
| 1126 * @brief System Clock Configuration | |
| 1127 * The system Clock is configured as follow : | |
| 1128 * System Clock source = PLL (HSE) | |
| 1129 * SYSCLK(Hz) = 180000000 | |
| 1130 * HCLK(Hz) = 180000000 | |
| 1131 * AHB Prescaler = 1 | |
| 1132 * APB1 Prescaler = 4 | |
| 1133 * APB2 Prescaler = 2 | |
| 1134 * HSE Frequency(Hz) = 8000000 | |
| 1135 * PLL_M = 8 | |
| 1136 * PLL_N = 360 | |
| 1137 * PLL_P = 2 | |
| 1138 * PLL_Q = 7 | |
| 1139 * VDD(V) = 3.3 | |
| 1140 * Main regulator output voltage = Scale1 mode | |
| 1141 * Flash Latency(WS) = 5 | |
| 1142 * The LTDC Clock is configured as follow : | |
| 1143 * PLLSAIN = 192 | |
| 1144 * PLLSAIR = 4 | |
| 1145 * PLLSAIDivR = 8 | |
| 1146 * @param None | |
| 1147 * @retval None | |
| 1148 */ | |
| 1149 static void SystemClock_Config(void) | |
| 1150 { | |
| 869 | 1151 /* Enable Power Control clock */ |
| 1152 __PWR_CLK_ENABLE(); | |
| 30 | 1153 |
| 869 | 1154 /* The voltage scaling allows optimizing the power consumption when the device is |
| 1155 clocked below the maximum system frequency, to update the voltage scaling value | |
| 1156 regarding system frequency refer to product datasheet. */ | |
| 1157 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |
| 30 | 1158 |
| 869 | 1159 /*##-1- System Clock Configuration #########################################*/ |
| 1160 /* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */ | |
| 1161 RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; | |
| 1162 #ifdef DISC1_BOARD | |
| 1163 // Use High Speed Internal (HSI) oscillator, running at 16MHz. | |
| 1164 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
| 1165 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
| 1166 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
| 1167 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
| 1168 RCC_OscInitStruct.PLL.PLLM = 16; // HSI/16 is 1Mhz. | |
| 1169 #else | |
| 1170 // Use High Speed External oscillator, running at 8MHz | |
| 1171 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
| 1172 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
| 1173 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
| 1174 RCC_OscInitStruct.PLL.PLLM = 8; // HSE/8 is 1Mhz. | |
| 1175 #endif | |
| 1176 // System clock = PLL (1MHz) * N/p = 180 MHz. | |
| 1177 RCC_OscInitStruct.PLL.PLLN = 360; | |
| 1178 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | |
| 1179 RCC_OscInitStruct.PLL.PLLQ = 7; | |
| 1180 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
| 1181 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | |
| 30 | 1182 |
| 1183 // HAL_PWREx_ActivateOverDrive(); | |
| 869 | 1184 HAL_PWREx_DeactivateOverDrive(); |
| 1185 | |
| 1186 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ | |
| 1187 RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; | |
| 1188 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
| 1189 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
| 1190 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
| 1191 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
| 1192 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; | |
| 1193 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; | |
| 1194 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_8 ); //FLASH_LATENCY_5); | |
| 30 | 1195 |
| 869 | 1196 /*##-2- LTDC Clock Configuration ###########################################*/ |
| 1197 /* LCD clock configuration */ | |
| 1198 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ | |
| 1199 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ | |
| 1200 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ | |
| 1201 /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ | |
| 30 | 1202 |
| 869 | 1203 /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */ |
| 1204 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; | |
| 1205 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; | |
| 1206 PeriphClkInitStruct.PLLSAI.PLLSAIN = 300; //192; | |
| 1207 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; //4; | |
| 1208 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8 | |
| 1209 HAL_RCCEx_PeriphCLKConfig( &PeriphClkInitStruct ); | |
| 30 | 1210 } |
| 1211 | |
| 1212 | |
| 1213 /** | |
| 1214 * @brief This function is executed in case of error occurrence. | |
| 1215 * @param None | |
| 1216 * @retval None | |
| 1217 */ | |
| 1218 static void Error_Handler(void) | |
| 1219 { | |
| 1220 /* Turn LED3 on */ | |
| 1221 // BSP_LED_On(LED3); | |
| 1222 while(1) | |
| 1223 { | |
| 1224 } | |
| 1225 } | |
| 1226 | |
| 1227 /** | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1228 * @brief Perform the SDRAM external memory initialization sequence |
| 30 | 1229 * @param hsdram: SDRAM handle |
| 1230 * @param Command: Pointer to SDRAM command structure | |
| 1231 * @retval None | |
| 1232 */ | |
| 1233 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command) | |
| 1234 { | |
| 1235 __IO uint32_t tmpmrd =0; | |
| 1236 /* Step 3: Configure a clock configuration enable command */ | |
| 1237 Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; | |
| 1238 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1239 Command->AutoRefreshNumber = 1; | |
| 1240 Command->ModeRegisterDefinition = 0; | |
| 1241 | |
| 1242 /* Send the command */ | |
| 1243 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1244 | |
| 1245 /* Step 4: Insert 100 ms delay */ | |
| 1246 HAL_Delay(100); | |
| 1247 | |
| 1248 /* Step 5: Configure a PALL (precharge all) command */ | |
| 1249 Command->CommandMode = FMC_SDRAM_CMD_PALL; | |
| 1250 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1251 Command->AutoRefreshNumber = 1; | |
| 1252 Command->ModeRegisterDefinition = 0; | |
| 1253 | |
| 1254 /* Send the command */ | |
| 1255 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1256 | |
| 1257 /* Step 6 : Configure a Auto-Refresh command */ | |
| 1258 Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; | |
| 1259 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1260 Command->AutoRefreshNumber = 4; | |
| 1261 Command->ModeRegisterDefinition = 0; | |
| 1262 | |
| 1263 /* Send the command */ | |
| 1264 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1265 | |
| 1266 /* Step 7: Program the external memory mode register */ | |
| 1267 tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 | | |
| 1268 SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | | |
| 1269 SDRAM_MODEREG_CAS_LATENCY_3 | | |
| 1270 SDRAM_MODEREG_OPERATING_MODE_STANDARD | | |
| 1271 SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; | |
| 1272 | |
| 1273 Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE; | |
| 1274 Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; | |
| 1275 Command->AutoRefreshNumber = 1; | |
| 1276 Command->ModeRegisterDefinition = tmpmrd; | |
| 1277 | |
| 1278 /* Send the command */ | |
| 1279 HAL_SDRAM_SendCommand(hsdram, Command, 0x1000); | |
| 1280 | |
| 1281 /* Step 8: Set the refresh rate counter */ | |
| 1282 /* (15.62 us x Freq) - 20 */ | |
| 1283 /* neu: (8 us x Freq) - 20 */ | |
| 1284 /* Set the device refresh counter */ | |
| 1285 HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT); | |
| 1286 } | |
| 1287 | |
| 1288 /* | |
| 1289 static void DualBoot(void) | |
| 1290 { | |
| 1291 // Set BFB2 bit to enable boot from Flash Bank2 | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1292 // Allow Access to Flash control registers and user Flash |
| 30 | 1293 HAL_FLASH_Unlock(); |
| 1294 | |
| 1295 // Allow Access to option bytes sector | |
| 1296 HAL_FLASH_OB_Unlock(); | |
| 1297 | |
| 1298 // Get the Dual boot configuration status | |
| 1299 AdvOBInit.OptionType = OBEX_BOOTCONFIG; | |
| 1300 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
| 1301 | |
| 1302 // Enable/Disable dual boot feature | |
| 1303 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
| 1304 { | |
| 1305 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
| 1306 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1307 } | |
| 1308 else | |
| 1309 { | |
| 1310 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
| 1311 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1312 } | |
| 1313 | |
| 1314 // Start the Option Bytes programming process | |
| 1315 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1316 { | |
| 1317 // User can add here some code to deal with this error | |
| 1318 while (1) | |
| 1319 { | |
| 1320 } | |
| 1321 } | |
| 1322 // Prevent Access to option bytes sector | |
| 1323 HAL_FLASH_OB_Lock(); | |
| 1324 | |
| 1325 // Disable the Flash option control register access (recommended to protect | |
| 1326 // the option Bytes against possible unwanted operations) | |
| 1327 HAL_FLASH_Lock(); | |
| 1328 | |
| 1329 // Initiates a system reset request to reset the MCU | |
| 1330 reset_to_firmware_using_Watchdog(); | |
| 1331 } | |
| 1332 */ | |
| 1333 /** | |
| 1334 ****************************************************************************** | |
| 1335 ****************************************************************************** | |
| 1336 ****************************************************************************** | |
| 1337 */ | |
| 1338 | |
| 1339 | |
| 1340 /** | |
| 1341 * @brief DMA2D configuration. | |
|
960
a8c0e6d07b8e
Minor: fix some typos in the bootloader code
heinrichsweikamp
parents:
880
diff
changeset
|
1342 * @note This function Configure the DMA2D peripheral : |
| 30 | 1343 * 1) Configure the transfer mode : memory to memory W/ pixel format conversion |
| 1344 * 2) Configure the output color mode as ARGB4444 | |
| 1345 * 3) Configure the output memory address at SRAM memory | |
| 1346 * 4) Configure the data size : 320x120 (pixels) | |
| 1347 * 5) Configure the input color mode as ARGB8888 | |
| 1348 * 6) Configure the input memory address at FLASH memory | |
| 1349 * @retval | |
| 1350 * None | |
| 1351 */ | |
| 1352 | |
| 1353 static void SDRAM_Config(void) | |
| 1354 { | |
| 1355 /*##-1- Configure the SDRAM device #########################################*/ | |
| 1356 /* SDRAM device configuration */ | |
| 1357 hsdram.Instance = FMC_SDRAM_DEVICE; | |
| 1358 | |
| 1359 /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */ | |
| 1360 /* TMRD: 2 Clock cycles */ | |
| 1361 SDRAM_Timing.LoadToActiveDelay = 2; | |
| 1362 /* TXSR: min=70ns (6x11.90ns) */ | |
| 1363 SDRAM_Timing.ExitSelfRefreshDelay = 7; | |
| 1364 /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */ | |
| 1365 SDRAM_Timing.SelfRefreshTime = 4; | |
| 1366 /* TRC: min=63 (6x11.90ns) */ | |
| 1367 SDRAM_Timing.RowCycleDelay = 7; | |
| 1368 /* TWR: 2 Clock cycles */ | |
| 1369 SDRAM_Timing.WriteRecoveryTime = 2; | |
| 1370 /* TRP: 15ns => 2x11.90ns */ | |
| 1371 SDRAM_Timing.RPDelay = 2; | |
| 1372 /* TRCD: 15ns => 2x11.90ns */ | |
| 1373 SDRAM_Timing.RCDDelay = 2; | |
| 1374 | |
| 1375 hsdram.Init.SDBank = FMC_SDRAM_BANK2; | |
| 1376 hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9; | |
| 1377 hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13; | |
| 1378 hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; | |
| 1379 hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; | |
| 1380 hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3; | |
| 1381 hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; | |
| 1382 hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD; | |
| 1383 hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; | |
| 1384 hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1; | |
| 1385 | |
| 1386 /* Initialize the SDRAM controller */ | |
| 1387 if(HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK) | |
| 1388 { | |
| 1389 /* Initialization Error */ | |
| 1390 Error_Handler(); | |
| 1391 } | |
| 1392 | |
| 1393 /* Program the SDRAM external device */ | |
| 1394 SDRAM_Initialization_Sequence(&hsdram, &command); | |
| 1395 } | |
| 1396 | |
| 1397 | |
| 1398 uint8_t checkResetForFirmwareUpdate(void) | |
| 1399 { | |
| 1400 uint32_t backupRegisterContent; | |
| 1401 | |
| 1402 RTC_HandleTypeDef RtcHandle; | |
| 1403 RtcHandle.Instance = RTC; | |
| 1404 backupRegisterContent = HAL_RTCEx_BKUPRead(&RtcHandle,RTC_BKP_DR0); | |
| 1405 | |
| 1406 if(backupRegisterContent == 0x12345678) | |
| 1407 return 1; | |
| 1408 else | |
| 1409 return 0; | |
| 1410 } | |
| 1411 | |
| 1412 void DeleteResetToFirmwareUpdateRegister(void) | |
| 1413 { | |
| 1414 RTC_HandleTypeDef RtcHandle; | |
| 1415 RtcHandle.Instance = RTC; | |
| 1416 __HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle); | |
| 1417 HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR0,0x00); | |
| 1418 __HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle); | |
| 1419 } | |
| 1420 | |
| 1421 #ifdef USE_FULL_ASSERT | |
| 1422 | |
| 1423 /** | |
| 1424 * @brief Reports the name of the source file and the source line number | |
| 1425 * where the assert_param error has occurred. | |
| 1426 * @param file: pointer to the source file name | |
| 1427 * @param line: assert_param error line source number | |
| 1428 * @retval None | |
| 1429 */ | |
| 1430 void assert_failed(uint8_t* file, uint32_t line) | |
| 1431 { | |
| 1432 /* User can add his own implementation to report the file name and line number, | |
| 1433 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
| 1434 | |
| 1435 /* Infinite loop */ | |
| 1436 while (1) | |
| 1437 { | |
| 1438 } | |
| 1439 } | |
| 1440 #endif | |
| 1441 | |
| 1442 /* | |
| 1443 static void DualBootToBootloader(void) | |
| 1444 { | |
| 1445 // Set BFB2 bit to enable boot from Flash Bank2 | |
| 1446 // Allow Access to Flash control registers and user Falsh | |
| 1447 HAL_FLASH_Unlock(); | |
| 1448 | |
| 1449 // Allow Access to option bytes sector | |
| 1450 HAL_FLASH_OB_Unlock(); | |
| 1451 | |
| 1452 // Get the Dual boot configuration status | |
| 1453 AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG; | |
| 1454 HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit); | |
| 1455 | |
| 1456 // Enable/Disable dual boot feature | |
| 1457 if (((AdvOBInit.BootConfig) & (FLASH_OPTCR_BFB2)) == FLASH_OPTCR_BFB2) | |
| 1458 { | |
| 1459 AdvOBInit.BootConfig = OB_DUAL_BOOT_DISABLE; | |
| 1460 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1461 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1462 { | |
| 1463 while (1) | |
| 1464 { | |
| 1465 } | |
| 1466 } | |
| 1467 } | |
| 1468 else | |
| 1469 { | |
| 1470 | |
| 1471 AdvOBInit.BootConfig = OB_DUAL_BOOT_ENABLE; | |
| 1472 HAL_FLASHEx_AdvOBProgram (&AdvOBInit); | |
| 1473 if (HAL_FLASH_OB_Launch() != HAL_OK) | |
| 1474 { | |
| 1475 while (1) | |
| 1476 { | |
| 1477 } | |
| 1478 } | |
| 1479 } | |
| 1480 | |
| 1481 // Prevent Access to option bytes sector | |
| 1482 HAL_FLASH_OB_Lock(); | |
| 1483 | |
| 1484 / Disable the Flash option control register access (recommended to protect | |
| 1485 // the option Bytes against possible unwanted operations) | |
| 1486 HAL_FLASH_Lock(); | |
| 1487 | |
| 1488 // Initiates a system reset request to reset the MCU | |
| 1489 reset_to_firmware_using_Watchdog(); | |
| 1490 } | |
| 1491 */ | |
| 1492 | |
| 1493 void reset_to_update_using_system_reset(void) | |
| 1494 { | |
| 1495 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
| 1496 HAL_NVIC_SystemReset(); | |
| 1497 } | |
| 1498 | |
| 1499 void reset_to_firmware_using_Watchdog(void) | |
| 1500 { | |
| 1501 __HAL_RCC_CLEAR_RESET_FLAGS(); | |
| 1502 __HAL_RCC_WWDG_CLK_ENABLE(); | |
| 1503 | |
| 1504 WWDG_HandleTypeDef WwdgHandle; | |
| 1505 WwdgHandle.Instance = WWDG; | |
| 1506 | |
| 1507 WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8; | |
| 1508 WwdgHandle.Init.Window = 80; | |
| 1509 WwdgHandle.Init.Counter = 127; | |
| 1510 | |
| 1511 HAL_WWDG_Init(&WwdgHandle); | |
| 869 | 1512 /* HAL_WWDG_Start(&WwdgHandle); has been removed from HAL library starting_V120 */ |
| 30 | 1513 while(1); |
| 1514 } | |
| 1515 | |
| 1516 | |
| 1517 void set_returnFromComm(void) | |
| 1518 { | |
| 1519 returnFromCommCleanUpRequest = 1; | |
| 1520 } | |
| 1521 | |
| 1522 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
