cancel
Showing results for 
Search instead for 
Did you mean: 

program flash of STM32H745 and execute code from same bank?

Gunnar Bohlen
Associate III

Hello,

my CPU is a STM32H745. I want to flash data into both banks (bank 1, sector 2-7, complete bank 2, while the code runs from the first bank, sector 0+1.

I'm using the given HAL-drivers stm32h7xx_hal_flash.c and stm32h7xx_hal_flash_ex.c and found an example for  STM32H743i-EVAL called IAP that demonstrates a firmware-upload into both flash-banks, while the code runs in the first sector of the first bank.

My applicatioun seems to flash the data (except the very last 32bytes @0x801ffe0 that stay 0xff) when I run my code without interruption, but as soon as I have a breakpoint within this code I see that the flash is correctly written until the current position, but If I continue the program the following flash write fails.

In the given IAP example from ST I don't see that any interrupts are disabled while the hal-functions are called, and no code is moved into RAM etc. On the other hand I don't understand why this code seems to work, because I don't understand why I can flash and execute code from the same bank, and why flashing seems to work, but fails when I use the debugger and interrupt the flashing-sequence (I don't interrupt the hal-function itself  and not between Flash unlock and lock)

Therefor although the code seems to work in my first tests I'm not sure that it willwork in all conditions.

Is it save to write the flash in this way, or can this concept fail?
Any ideas why the existing code does not program the last 32 bytes (which is one flash word?)

I don't have the STM32H743i-EVAL board so I can't simply test the IAP examle code there.

Thank you.

4 REPLIES 4
FBL
ST Employee

Hello @Gunnar Bohlen 

This application is a set of sources files that build the application to be loaded into Flash memory using IAP through USART. 

To load user app from the second sector, you can simply #define APPLICATION_ADDRESS as ADDR_FLASH_SECTOR_2_BANK1

I don't get your point about managing interrupts. This particular application doesn't use any peripheral interrupt handler. It is meant to be configured in polling mode through UART to load application binary.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

32-bytes is also cache line length.

Data should be writable, but only get a single shot at each flash word. Not aware of any specific anomalies with the H7 devices in this regard.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist II

>> except the very last 32bytes @0x801ffe0 that stay 0xff

Bank 2 starts from 0x08100000.  0x0801FFE0 is entirely within bank1 sector 0.

 I don't understand why I can flash and execute code from the same bank

Actually the MCU will wait until flash operation completes, so you code won't execute while flashing in the same bank. It will continue seamlessly after the operation ends. For best results, run the flashing code in the RAM.

Gunnar Bohlen
Associate III

>Actually the MCU will wait until flash operation completes, 

This is what I now understand, CPU can't fetch the next instruction while flash is being programmed.

But for me this dosn't explain why subsequent flash programming fails once I interrupt my progamming loop with a debugger/breakpoint and look at some variables.