cancel
Showing results for 
Search instead for 
Did you mean: 

Boot from Bank 2: nSWAP_BANK vs. BFB2

CRusc.1
Associate

I am trying to implement a "dual bank field upgrade" with a STM32G0B1CEU6 as described in AN4767, chapter 2.4 (for a STM32L0). As far as I know the STM32G4 also has this functionality, not 100% identically implemented but with the same intention. Seen here in the STM32G4 datasheet:

FLASH_OPTR

Bit20 BFB2:Dual-bankboot

0: Dual-bank boot disable

1: Dual-bank boot enable

But the STMG0B1, although a dual bank device might not. But I find in the STM32G0 datasheet the following:

FLASH_OPTR

Bit20 nSWAP_BANK:Empty check boot configuration

This bit selects the bank that is the subject of empty check upon boot.

0: Bank 1

1: Bank 2

In the memory map (table 11 of RM0444) there is nothing about this flag, also I can't find any other information.

Well, in the datasheet of the STM32H7 a flag SWAP_BANK is described quite well (table 19 RM0433), and seems to behave in the sense of BFB2: "The embedded Flash memory bank 1 and bank 2 can be swapped in the memory map [...]".

My questions:

- Is nSWAP_BANK comparable to BFB2? Or with the implementation of SWAP_BANK in STM32H7? And not just checking if code is present?

- If the answer to the first question is yes: why is this not described in the datasheet? If the answer is "No": Why on earth is the flag called the same as in STM32H7...?

-Can I implement the desired function with the STM32G0B1CEU6 with reasonable effort? So: "Program writes a new version in other bank and boots from there". Would I have to solve all address problems myself, which BFB2 (STM32G0) or SWAP_BANK (STM32H7) takes care of?

Thanks a lot,

Chris

3 REPLIES 3
GwenoleB
ST Employee

Hello @CRusc.1​,

On STM32G0x1, nSWAP_BANK allows user to remap the BANK1 or BANK2 at address 0x0800_0000.

Then, when user boots the empty check is processed on Bank mapped at this address. In case the bank is empty, the device jumps into the Bootloader.

Note that:

  • nSWAP_BANK = 1 ==> BANK1 is mapped at 0x0800_0000
  • nSWAP_BANK = 0 ==> BANK2 is mapped at 0x0800_0000

In addition, address remapping is effective in write and read process. For page erase and bank erase, nSWAP_BANK has no effect on remap as these features are linked to the hardware Flash bank. That's why it's mandatory to specify the page number and the physical bank number with HAL (i.e. FLASH_BANK_1 or FLASH_BANK_2).

To summary, G0x1 has no dual-boot capability and only bank swap capability.

  HAL_FLASH_Unlock();
  FLASH_EraseInitTypeDef EraseInitStruct = {0};
  EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
  EraseInitStruct.Banks       = FLASH_BANK_2;              
  EraseInitStruct.Page        = 127;               
  EraseInitStruct.NbPages     = 1;
  if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
  {
    
  }
  HAL_FLASH_Lock();

Let me know if you have any question.

Best Regards,

Gwénolé

First: thank you for your feedback, I appreciate this very much.

> To summary, G0x1 has no dual-boot capability and only bank swap capability.

This sentence I do not understand, sorry if I ask again here... I think I'm missing something trivial: 

  1. If BANK2 is mapped to 0x0800_0000 and address remapping is effective in write and read process, then isn't that a dual boot ability? Or is this mapping only used before the execution of the bootloader for the check and at the end the program starts in any case from BANK1, no matter what is in nSWAP_BANK?
  2. The datasheet of STM32H7 says "The embedded Flash memory bank 1 and bank 2 can be swapped in the memory map accessible through AXI interface. This feature can be used after a firmware upgrade to restart the device on the new firmware. Bank swapping is controlled by the SWAP_BANK bit of the FLASH_OPTCR register." This is exactly what I want (at least I think so ;-). Can STM32G0 do that? Does the flag nSWAP_BANK has the same/similar meaning here? Or asked differently: what would do "dual boot" even more than that? Does "dual boot" mean "boot from system memory" - and not "boot from one of the two banks" as I thought?

PS: I read https://community.st.com/s/question/0D53W00000LeYBeSAN/booting-with-dual-flash-banks-vs-bank-swap

Thank you,

Chris

GwenoleB
ST Employee

Hello @CRusc.1​,

  1. This is only mapping. The boot is done only at address 0x0800_0000 (done by hardware). At this location, if the empty check is set, the bank is empty and in this case you jump to the bootloader and never check the second one. If you need to boot on the second bank then you must change the nSWAP_BANK bit.
  2. You are right, at the end the behavior of G0 is aligned with H7. Then, you can be based on H7 for your application.

Best Regards,

Gwénolé