Two pitfalls of APP jump of Huada MCU HC32F460
[Copy link]
This post was last edited by Jacktang on 2021-5-26 07:36
Recently, I encountered two major pitfalls when using HC32F460 APP jump. I would like to share them with you so that netizens who have used it can learn from them.
1. The size of the BIN file generated after the FLASH and interrupt vector offset is incorrect, and it cannot jump to the APP normally after burning.
2. Triggering an interrupt after jumping to the APP will cause the system to crash.
The following records the experimental process and provides solutions for these two problems.
Figure 1 Homemade HC32F460 evaluation board
Compared with STM32, the IAP and APP jumps of HC32F460 are somewhat different. When using the IAR development environment to boot the APP under STM32, you only need to modify the address offset in the ICF file (including the interrupt vector offset and the FLASH address offset) and SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET in the SystemInit function. In this way, the compiled BIN file can be loaded directly. However, HC32F460 is a bit special. See the "Initialization Configuration" section in the official user manual. As shown in Figure 2
Figure 2 Initialization configuration instructions
Therefore, during the IDE link process, an additional part of the content is added to the FLASH address 400H-41fH. Therefore, an empty code segment will be generated in the APP, resulting in a particularly large BIN file after the offset. For example, the blogger set the FLASH address offset to 0x12000, but the compiled BIN file is 110KB, and the actual valid code segment is 31KB. After opening the BIN file with UltraEdit, it was found that a large number of blank characters were filled before the 0x12000 address in the file. Moreover, after using the BOOT program to burn the BIN file to the FLASH, it cannot be started normally. The ICF link file after the address offset of HC32F460 is shown in Figure 3:
Figure 3 HC32F460 address and interrupt offset settings
Solution (Problem 1): It seems that just changing the ICF file is not enough. After checking, it is found that the real program area needs to start from address 0x11c00, as shown in Figure 4. So the blogger directly deleted all the data in the area before 0x11c00. The effective APP size obtained is about 31KB. Use the BOOT program to burn and jump to the program to start running.
Figure 4 Valid program area
Solution (Problem 2): Although the APP can run normally at this time, another problem occurs when the APP enters the interrupt when sending serial port data. The MCU crashes. After consulting relevant information, it is found that the interrupt function that has been registered in the BOOT program and is in use needs to be unregistered before jumping to the APP. The specific method is to call the enIrqResign function. For convenience, the blogger directly unregisters all interrupts (unregistration is in the BOOT program, and it may also be possible when it is initialized in the APP. You can test it yourself).
void BOOT_JumpToApp(void)
{
uint32_t JumpAddr;
pBootFun pFun2App;
uint32_t Cnt;
//Disable interrupts//
//__disable_interrupt();
//__disable_irq();
//Release interrupt before jump//
/*
enIrqResign(Int000_IRQn);
enIrqResign (Int001_IRQn);
enIrqResign(Int002_IRQn);
enIrqResign(Int003_IRQn); enIrqResign(Int004_IRQn)
;
*/
for(Cnt = 0; Cnt < Int143_IRQn; Cnt++)
{
enIrqResign(Cnt);
}
//if (((*(__IO uint32_t *)APP_START_ADDR) & 0x2FFE0000 ) == 0x20000000)
//{
JumpAddr = *(__IO uint32_t*) (APP_START_ADDR + 4);
pFun2App = (pBootFun)JumpAddr;
__set_MSP(*(__IO uint32_t*) APP_START_ADDR);
pFun2App();
//}
}
At this point, the HC32F460 series The writing and testing of BOOT boot program and APP program are completed. The blogger's customized HC32F460-FLASH allocation table is shown in the table below, and the host computer for serial port update of BOOT program is shown in Figure 5:
0 0 Sector0 8*8=64KB BOOT
8192 2000 Sector1
16384 4000 Sector2
24576 6000 Sector3
32768 8000 Sector4
40960 A000 Sector5
49152 C000 Sector6
57344 E000 Sector7
65536 10000 Sector8 8KB parameter area
73728 12000 Sector9 26*8=208KB APP area
81920 14000 Sector10
90112 16000 Sector11
98304 18000 Sector12
106496 1A000 Sector13
114688 1C000 Sector14
122880 1E000 Sector15
131072 20000 Sector16
139264 22000 Sector17
147456 24000 Sector18
155648 26000 Sector19
163840 28000 Sector20 172032 2A000 Sector21
180 224 2C000 Sector22
188416
2E000 Sector23
196608 30000 Sector24
204800 32000 Sector25 212992 34000
Sector26
221184 36000 Sector27
229376 38000 Sector28
237568 3A000 Sector29
245760 3C000 Sector30
253952 3E000 Sector31
262144 40000 Sector32
270336 42000 Sector33
278528 44000 Sector34 286720
46000 Sector35 8KB Reserved
29491 2 48000 Sector36 26*8=208KB IAP area
303104 4A000 Sector37
311296 4C000 Sector38
319488 4E000 Sector39
327680 50000 Sector40
335872 52000 Sector41
344064 54000 Sector42
352256 56000 Sector43
360448 58000 Sector44
368640 5A000 Sector45
376832 5C000 Sector46 385024 5E000
Sector47
393216 60000 Sector48
401408 62000 Sector49
409600 64000 Sector50
417792 66000 Sector51
425984 68000 Sector52
434176 6A000 Sector53
442368 6C000 Sector54
450560 6E000 Sector55
458752 70000 Sector56
466944 72000 Sector57
475136 74000 Sector58
483328 76000 Sector59
491520 78000 Sector60
499712 7A000 Sector61
507904 7C000 Sector62
516096 7E000 Sector63 8KB Reserve
Figure 5 BOOT host computer program
|