STM32L082 dual bank - example code

Post here first, or if you can't find a relevant section!
Post Reply
Beuzekom
Posts: 15
Joined: Thu Jul 30, 2020 1:32 pm
Answers: 1

STM32L082 dual bank - example code

Post by Beuzekom »

Hello,

I am looking for your sample code on how to use the dual bank mechanism on the STM3L082.
  • My goal is to download the new firmware
  • Write it into bank 2 (starting from 0x0801 8000) (use the HEX generated by platformIO
  • Bank1 always remains as it is (with original firmware)
  • BFB2 is set to 1
  • MCU restarted
  • System memory loader will kick in
  • Boots from bank2 (unless there is no valid code on bank2. In that error case it will continue to boot from bank1)
My questions:
  • I assumed that to set the BFB2 bit was sufficient to boot from bank2. However it does not work. Do I miss something?
  • Does anybody know where I can find sample code to use both flash banks?
Thanks a lot
by Beuzekom » Fri Nov 18, 2022 10:35 am Go to full post
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: STM32L082 dual bank - example code

Post by ABOSTM »

Hi @Beuzekom,
Explanations of Bank2 mechanism is detailed in Reference Manual RM0376
paragraphe § 3.3.2 Dual-bank boot capability
So you need to take car of BOOT0 pin.

There is also an application note corresponding to your needs:
https://www.st.com/resource/en/applicat ... ronics.pdf

And there is an example:
https://github.com/STMicroelectronics/S ... H_DualBoot
It is not exactly on the same chip, but almost.
It is not based on Arduino core, but rather on STMicroelectronics HAL/LL drivers,
nevertheless, it could be an help to understand what needs to be done.
Beuzekom
Posts: 15
Joined: Thu Jul 30, 2020 1:32 pm
Answers: 1

Re: STM32L082 dual bank - example code

Post by Beuzekom »

Hi ABOSTM,

Thanks for the information
ABOSTM wrote: Thu Feb 10, 2022 9:33 am Explanations of Bank2 mechanism is detailed in Reference Manual RM0376
paragraphe § 3.3.2 Dual-bank boot capability
So you need to take car of BOOT0 pin.
The BOOT0 pin I have grounded on my PCB. In the STM docs (par 3.3.2 you refer to or AN2606) it is stated that dual bank can be used by:
  • BOOT0 = 0 and BFB2 = 1
  • In that case it will be booted from System memory to execute dual bank boot mechanism. If Bank 2 and Bank 1are not valid, bootloader is executed for Flash update.
Do anybody know when a bank is considered valid? In AN2606 (par 53.1.2, figure 65) it is considered valid when "If Value of first address of Bank2 is within int. SRAM address". Do I understand correct that when the first value of bank2 is an SRAM address it is considered valid?
ABOSTM wrote: Thu Feb 10, 2022 9:33 am And there is an example:
https://github.com/STMicroelectronics/S ... H_DualBoot
It is not exactly on the same chip, but almost.
It is not based on Arduino core, but rather on STMicroelectronics HAL/LL drivers,
nevertheless, it could be an help to understand what needs to be done.
Great! Did not come across this example. Will try to run in with the STM32L082 and see if we get dual bank working.
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: STM32L082 dual bank - example code

Post by ABOSTM »

Do I understand correct that when the first value of bank2 is an SRAM address it is considered valid?
Right. In Cortex M architecture, a binary always starts by Stack Pointer address, which should be in RAM.
Thus 1st U32 value of your bank2 should correspond to Stack Pointer, and is considered valid if it is in RAM.

One remark: I don't know how you proceed to write your software in Bank2, but you told about HEX file.
I hope you did not write HEX file as raw data into Bank2 ?
If you use a tool like STM32CubeProgrammer, it knows how to convert this HEX file to binary file that can then be written to Bank2.
But if you wrote HEX somehow with embeded sketch for example as raw data, this will not work, you should write a binary file. (*.bin)
Beuzekom
Posts: 15
Joined: Thu Jul 30, 2020 1:32 pm
Answers: 1

Re: STM32L082 dual bank - example code

Post by Beuzekom »

Do I understand correct that when the first value of bank2 is an SRAM address it is considered valid?
Right. In Cortex M architecture, a binary always starts by Stack Pointer address, which should be in RAM.
Thus 1st U32 value of your bank2 should correspond to Stack Pointer, and is considered valid if it is in RAM.
Thanks. I also need to learn how the binary is build. But will do that after I have the dual bank running :-)
One remark: I don't know how you proceed to write your software in Bank2, but you told about HEX file.
I hope you did not write HEX file as raw data into Bank2 ?
If you use a tool like STM32CubeProgrammer, it knows how to convert this HEX file to binary file that can then be written to Bank2.
But if you wrote HEX somehow with embeded sketch for example as raw data, this will not work, you should write a binary file. (*.bin)
Yes I do mean the bin file generated from platformio. I flash it with the st-link-utility (to bank2) and bank1 is flashed directly to bank1.
In this tool I also set the BFB2 option bit. As mentioned doing these action does not start bank2. So will go thru the examples you send
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: STM32L082 dual bank - example code

Post by ABOSTM »

@Beuzekom , you need to check the revision of your chip, because there is a Hardware issue on some version.
How to check revision: see datasheet https://www.st.com/resource/en/datashee ... l082cz.pdf
and look for "marking example" and "Revision code"
For bug details, see erratasheet:
https://www.st.com/resource/en/errata_s ... ronics.pdf

Bug concerns Rev A and Rev B.
2.1.8 BFB2 bit does not select boot from Bank 2 system memory
And there is a proposed workaround.
Beuzekom
Posts: 15
Joined: Thu Jul 30, 2020 1:32 pm
Answers: 1

Re: STM32L082 dual bank - example code

Post by Beuzekom »

Thanks. CubeProgrammer tells me rev Z // so should be all good.
However have not been able to get it running yet. Will update here once I made some progress

stm32l082-rev.png
stm32l082-rev.png (4.89 KiB) Viewed 9398 times
Beuzekom
Posts: 15
Joined: Thu Jul 30, 2020 1:32 pm
Answers: 1

Re: STM32L082 dual bank - example code

Post by Beuzekom »

Post Reply

Return to “General discussion”