Showing results for 
Search instead for 
Did you mean: 

STM32G0B1 jump across flash banks errata: what about interrupts?


There is this errata for STM32G0B1

2.2.10 Prefetch failure when branching across flash memory banks
In rare cases, the code prefetch may fail upon branching and function calls across flash memory banks,
regardless of the DUAL_BANK and nSWAP_BANK option byte settings. The failing prefetch then provides an
incorrect data to the CPU, which causes code execution corruption and may lead to HardFault interrupt.

The workaround is obvious, either disable prefetch when jumping to code in the other bank and enable it again afterwards or use a small "trampoline" function in RAM. We can live with that, as our software is split into separately compiled "core" and "application" parts loaded into separate banks, having only a handful of interface functions there would be e.g. no jumps into library functions in the other bank.


What about exceptions and interrupts, how are they affected?


The ARM literature generally refers to loading the exception handler address from the vector table as fetching. It makes sense on architectures where there is a separate instruction and data bus, as it can stack a few registers while waiting for the address from the slower flash. This is not the case on Cortex-M0+, however there could still be an internal distinction between data loads and instuction fetches.

So, what happens when an exception occurs while code is running in bank 1 and NVIC->VTOR points to bank 0?

What happens when an interrupt handler running in bank 0 returns to code in bank 1?

Are those kinds of branches affected by this errata or only literal BX,BLX and BL instructions? All of them?

Having the vector table and a small handler function in RAM would solve that problem, right?

Oh, and to complicate matters further there is a RTOS (ThreadX) running in bank 0 that might want to return to a different address and mess with the stack.


Hi @berendi ,

long time no see.

While ST's presence increased recently, this is still the primarily user driven forum as it used to be, so you have to ask ST directly. Please come back with any reply from ST if you do so.



Yeah, this looks super messy, would really like to see a worked example of the failure.

I'm guessing it would impact a lot of things. Sounds like there would need to be a safety region between the two banks at the boundary, so no code crosses, and no branch/call targets within it. This will be a pig to catch as the linker/user might want to concatenate banks into larger linear region.

Back linking to this thread so it's less hard to find later..

ie large size induced weirdness

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