cancel
Showing results for 
Search instead for 
Did you mean: 

BFB2 and bootloader flash-bank selection

mhaun
Associate II
Posted on February 23, 2016 at 18:15

I've recently delved into this subject because I need to design a firmware upgrade mechanism on the STM32L4xx.  The documentation is pretty much useless, as it is not only incomplete, but contradictory too.  I'm guessing the guy/gal who wrote that section of the Reference Manual wasn't sure how it worked either.  The only prose description is the following passage from section 2.6:

When booting from the main Flash memory, the application software can either boot from

bank

1 or from bank 2. By default, boot from bank 1 is selected.  To select boot from Flash memory bank 2, set the BFB2 bit in the user option bytes. When this bit is set and the boot pins are in the boot from main Flash memory configuration, the device boots from system memory, and the boot loader jumps to execute the user application programmed in Flash memory bank 2. For further details, please refer to AN2606.

The string ''BFB2'' does not appear in AN2606.  There is a ''dual bank boot'' flow chart (figure 55), but it seems to indicate that the decision to boot from bank 1 or bank 2 depends on whether ''the value of first address of bank 1/2 is within internal SRAM address''.  I must be missing something fundamental, as I don't see what any of this has to do with SRAM...

I know this topic has come up before, but I am still not clear on what, exactly, the BFB2 bit does:

1) Does it select which bank to boot from, as the ref manual seems to imply in one place, or does it merely put the system in a mode where you can select the bank using some other mechanism, as AN2606 (and the register description itself) implies?  And if the latter, how do you choose the bank to boot from?

2) When booting from bank 2, is flash memory actually remapped so that bank 2 appears at the bank 1 address and bank 1 appears at the bank 2 address?  Or does the bootloader merely jump into bank 2 instead bank 1?  In other words, must I build relocatable code and set VTOR, or not?  I find nothing in the ST docs to suggest a hardware-level remapping, but a previous comment by clive suggested it.

It would be nice to clear this up once and for all, since ST don't appear to be fixing their documentation.  (Search hits in this forum were from 2013 and 2014.)

14 REPLIES 14
Posted on November 23, 2017 at 13:44

Hey, I have a confusion regarding the BOOT0 configuration.

Do I need to change the BOOT0 level from 0-> 1 or 1-> 0 to enter the bootloader mode? Or is it the case that, setting the BFB2 bit is same as setting the BOOT0 pin? In my application, there is no external microcontroller which can control the BOOT0 pin in order to enter bootloader mode. Can you help me with this?

Maunik Patel
Associate II

Hello All,

I want to do FOTA with STM32L432KB and facing the same issue as of @mhaun​ .

It seems like many of you know very well how to switch between Flash banks.

Please don't mind, but can any of you give me reference to the document which states "how to switch between 2 Flash banks ?" for said part number?

OR at-least guide me where exactly this string "BFB2" written for STM32L4XX.

Somehow, I can't find it.

.

One more thing for you, @mhaun​ 

As you said you found FM_MODE in SYSCFG, can you please tell me in which document ?

I found MEM_MODE in SYSCFG in reference manual (RM0394, 9.2.1, page 276), and I can't find any thing there, relevant to Flash Bank.

Does the L432KB​ even have multiple banks?

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

I doubt. That's one of my questions.

I attended an ST seminar and there I came to know about multiple banks in STM32L4+, and so I presumed L432KB is having multiple banks.

Please correct me here.

It's not an L4+ part

The sell sheet is pretty specific

https://www.st.com/en/microcontrollers/stm32l432kb.html

"Up to 256 KB single bank Flash, proprietary code readout protection"

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