GD32F4XX IAP upgrade

The GD32F405RG is used here, the flash is 1M (0x08000000 - 0x080FFFFF), please refer to the official manual for details

Because the flash size of each chip is different, the address division should be allocated according to the actual flash size and your own design. Your own address division is as follows:

BOOT_ADDRESS: 0x08000000 - 0x08003FFF 16k (sector 0)

APP_ADDRESS: 0x08004000 - 0x0807FFFF 512k-16k=496k (sector 1-7)

Buffer_ADDRESS: 0x08080000 - 0x080FEFFF 512k-4k=508k (sector 8-11)

Flags_ADDRESS: 0x80FF000 -0x80FFFFF 4k (last 4k of sector 11)

The upgrade idea of ​​IAP is basically the same, as shown in the figure (too lazy to draw a picture, this picture is stolen (doge))

 Simply made an IAP upgrade method for usart reception, mainly USART+DMA+idle interrupt reception, the upper computer sends the computer command, the board starts to upgrade after receiving the upgrade command, and the upper computer converts the bin file into a frame of 1024 bytes The board will write the data into the buffer area every time it receives a frame, and the host computer will send an end command after the transmission is completed. After the board is received, it writes the upgrade flag, then jumps to the boot to execute the copy, copies the Buffer code to the APP address, and finally points the PC pointer to the APP.

The above is the basic idea, the following is the code process

First of all, write and read the code of flash. For details, please refer to the official routine, GigaDevice (gd32mcu.com)

 It should be noted that if you want to write flash, you must erase it first. Erase flash by sector. The official write routine includes the operation of erasing the corresponding sector before each write. If you use it directly It will cause the previous code of the same sector to be erased.

 We can make a slight modification to this, erase the sectors of the buffer uniformly before writing, and then write to flash frame by frame

Upgraded receiving module:

 When the reception is complete, write the upgrade flag, and then jump to boot to copy

BootLoader:

 vJumpToApplication():

 The configuration of USART is not attached, just refer to the official routine.

Still need to pay attention to the details:

1. When burning keil, you need to assign a good burning address to avoid being overwritten

 2. The transmitted file is in bin format, and the type on the flash is a word, so remember to write in word format when writing

If you have any questions, you can leave a message to communicate, thank you!

Supongo que te gusta

Origin blog.csdn.net/cuncun666/article/details/128241741
Recomendado
Clasificación