I trying to do a bank swap with the ST32 H743ZI2. I wasted much of time
to fix it but i didnt get it. Maybe because im new in STM32 controllers.
I copied the bank swap code from STM32CubeH7 Firmware Examples and did a
few modifications regarding to gpio configuration in CubeMX. I did them
because i want to implicate the code in a excisting project without the
stm32h7xx_nucleo headers.
Following the Code for Bank1:
1 | HAL_FLASH_Unlock();
|
2 | HAL_FLASH_OB_Unlock();
|
3 |
|
4 | while (1)
|
5 | {
|
6 | /* Wait for BUTTON_USER is released */
|
7 | if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == 1)
|
8 | {
|
9 | while (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == 1);
|
10 |
|
11 | /* Get the Dual boot configuration status */
|
12 | HAL_FLASHEx_OBGetConfig(&OBInit);
|
13 |
|
14 | /* Get FLASH_WRP_SECTORS write protection status */
|
15 | OBInit.Banks = FLASH_BANK_1;
|
16 | HAL_FLASHEx_OBGetConfig(&OBInit);
|
17 |
|
18 | /* Check Swap FLASH banks status */
|
19 | if ((OBInit.USERConfig & OB_SWAP_BANK_ENABLE) == OB_SWAP_BANK_DISABLE)
|
20 | {
|
21 | /*Swap to bank2 */
|
22 | /*Set OB SWAP_BANK_OPT to swap Bank2*/
|
23 | OBInit.OptionType = OPTIONBYTE_USER;
|
24 | OBInit.USERType = OB_USER_SWAP_BANK;
|
25 | OBInit.USERConfig = OB_SWAP_BANK_ENABLE;
|
26 | HAL_FLASHEx_OBProgram(&OBInit);
|
27 |
|
28 | /* Launch Option bytes loading */
|
29 | HAL_FLASH_OB_Launch();
|
30 |
|
31 | /*
|
32 | as the CPU is executing from the FLASH Bank1, and the I-Cache is enabled :
|
33 | Instruction cache must be invalidated after bank switching to ensure that
|
34 | CPU will fetch correct instructions from the FLASH.
|
35 | */
|
36 | SCB_InvalidateICache();
|
37 |
|
38 |
|
39 | HAL_NVIC_SystemReset();
|
40 | }
|
41 | else
|
42 | {
|
43 | /* Swap to bank1 */
|
44 | /*Set OB SWAP_BANK_OPT to swap Bank1*/
|
45 | OBInit.OptionType = OPTIONBYTE_USER;
|
46 | OBInit.USERType = OB_USER_SWAP_BANK;
|
47 | OBInit.USERConfig = OB_SWAP_BANK_DISABLE;
|
48 | HAL_FLASHEx_OBProgram(&OBInit);
|
49 |
|
50 | /* Launch Option bytes loading */
|
51 | HAL_FLASH_OB_Launch();
|
52 |
|
53 | /*
|
54 | as the CPU is executing from the FLASH Bank1, and the I-Cache is enabled :
|
55 | Instruction cache must be invalidated after bank switching to ensure that
|
56 | CPU will fetch correct instructions from the FLASH.
|
57 | */
|
58 | SCB_InvalidateICache();
|
59 | }
|
60 | }
|
61 | else
|
62 | {
|
63 | #ifdef FLASH_BANK1
|
64 | /* Toggle LED1 */
|
65 |
|
66 | HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
|
67 | /*Turn Off LED2*/
|
68 | HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, 0);
|
69 |
|
70 | #else
|
71 | /* Toggle LED2 */
|
72 | HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1);
|
73 | /* Turn off LED1 */
|
74 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, 0);
|
75 | #endif
|
76 |
|
77 | /* Insert 100 ms delay */
|
78 | HAL_Delay(100);
|
79 | }
|
80 |
|
81 | /* USER CODE END WHILE */
|
82 |
|
83 | /* USER CODE BEGIN 3 */
|
84 | }
|
85 | /* USER CODE END 3 */
|
86 | }
|
The code for bank1 and bank2 are equal except linkerscript. I splited
Flash in two areas wich have 1024kb each. In following you can see the
code for bank1.
1 | /* Specify the memory areas */
|
2 | MEMORY
|
3 | {
|
4 |
|
5 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
6 | RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
|
7 | RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
|
8 | RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
|
9 | ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
|
10 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
|
11 | }
|
In linkerscript for bank2 i changed flash start addres to 0x08100000.
Now i have following problem. If i load in order code for bank1 and code
for bank2 press the Button1 and Press the Resetbutton i get following
error message:
1 | Break at address "0x81006fe" with no debug information available, or outside of program code.
|
I already successfully checked if there is placed some code with STM32
Utility.
If i load the codes in reverse order the banks get swaped once.
Independently if Button1 gets pressed before system reset or not..
I already checked some forums without success.
Does anyone know where the problem could be?