cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 flash bootloader cannot program more than 900 kB

abaril_catalys
Associate II

Hello,

I have written a Flash bootloader for the STM32H743 for our custom application PCB. In a nutshell, the flash bootloader check an external flash memory IC with SPI on the custom application PCB if there is a new image to be flash and do it if it has to. Then it computes the CRC and boot the application.

In the linker script, the application resides at 0x08000000, and the flash bootloader at 0x081E0000. I use the options bytes BOOT_CM7_ADD0 to set the boot address at the flash bootloader 0x081E. The flash bootloader is at the last sector of the flash bank 2.

Technically, this would mean that my application can take up as much as (2 MB - 128 kB). I would like my application to take all this space and be able to replace it when required by the bootloader.

The flash bootloader works perfectly with image below 900 kB. Please keep that in mind, my code isn't total garbage.

However, when I try to flash a bigger image than about 900 kB, the bootloader crashes when it try to read memory in bank 1 to perform the CRC after the flash erase and flash write. Specifically at line 251 of bootloader_app.c.

I tried checking the FLASH->SR1 and SR2 words for Flash errors but none are found... When I use STM32CubeProgrammer, I also cannot read the chip as I am getting a read error message.

To un-brick the STM32H743, I need to do a mass erase in STM32CubeProgrammer and the chip restart to behave normally and read memory in bank 1 as normal.

I tried to clear the SR1 and SR2 register but it didn't prevent the problem.

I tried to execute the flash erase and flash program functions in RAM but it didn't prevent the problem.

I looked at the errata but didn't find anything related to my problem.

I can program image bigger than 900 kB using STM32CubeProgrammer without issue, but I need to use my flash bootloader in the field.

I cannot share the custom application code but the bootloader code is generic so you should be able to have it in the zip file.

Thank you for taking the time to look into my issue.

2 REPLIES 2
Pavel A.
Evangelist III

In your DriverInternalFlash.c line 66:

 

    erase_init_struct.Banks = FLASH_BANK_1;
    erase_init_struct.Sector = FLASH_SECTOR_0;
    erase_init_struct.NbSectors = FLASH_SECTOR_7;

 

NbSectors is the number of sectors to erase. To erase whole bank 1 it should be 8, not 7.

Same for bank 2, you want to erase 7 sectors.

7*128K = 917504  This is the max. size you can write after erasing 7 sectors.

Otherwise, a very nice design, kudos.

I tried checking the FLASH->SR1 and SR2 words for Flash errors but none are found

This seems strange, IIRC attempt to program over not-erased flash should set some error bit.

The "crash" while reading from internal flash (elevated fault or NMI?) can be because of ECC error. Proper mass erase will dismiss ECC errors.

 

NbSectors should be an integer, not a FLASH_SECTOR_* define. In this case, it should be 8.

  uint32_t NbSectors;   /*!< Number of sectors to be erased.
                             This parameter must be a value between 1 and (max number of sectors - value of Initial sector)*/

 

Same effect except FLASH_SECTOR_8 isn't necessarily defined.

If you feel a post has answered your question, please click "Accept as Solution".