SlideShare a Scribd company logo
1 of 15
ST built-in Boot Loader
Applicable to STM32L1XX
Due to the technical limitations that will be detailed below,
Meprolight has decided not to use ST built in boot loader
Hence this presentation does not contain sensitive information
Agenda
• MCU Architerture 3 slides
• ST Built in Bootloader 3 slides
• Implementation Flowchart 1 slide
• Merging the code 3 slides
• External application 2 Slides
• Validation 1 Slide
© Hakim Weatherspoon, Computer Science, Cornell University
Basic Computer System
• A processor
is a device that executes instructions
Processor has some internal state in storage elements (registers)
• A memory
holds instructions and data
von Neumann architecture is assumed for simplicity
• A bus connects the two
regs
bus
processor memory
01010000
10010100
…
addr, data,
r/w
ARM Cortex-M Start up Sequence
• Electronically
– Fetch Stack Pointer from address 0x00
– Fetch Program Counter from address 0x04
• Software
– Execute assembly function Reset_Handler
(initialize vector table and call the followings)
– Execute c function SystemInit
Initializes clocks and VTOR
– Execute assembly function __iar_data_init3Initialize Initializes
variables
– Call function main
User program
But address 0x00 does not exist in Flash !
It is mapped to other address (0x08000000 in normal execution)
Where is the Vector Table located ?
System Memory
• Written in ROM within the Flash
• Has two functions:
– Firmware update
– Execute code from bank 2
(When nBFB2 = 0 at startup)
nBFB2 bit
• nBFB2 = 1 at startup  Normal Execution
• nBFB2 = 0 at startup
– Address 0x00 is mapped electronically
to System memory
– System memory Jumps to bank 2
• Undocumented important Takeaways:
– When running from bank 2 (nBFB2 = 0),
an attempt to update firmware from system memory
will FAIL, because it will result in jumping back to bank 2
– Unlike STM32L0XXX and STM32L4XXX,
nBFB2 does not result in bank swap
Bootloader limitations
ST bootloader has limited address range allowed to be written
(all of bank 1 and ½ of bank 2)
Thus,
If the application requires more than ½ the space of a bank,
only one version of the application may be updated.
Since the firmware update may only be conducted when
nBFB2 = 1, the code that initiates the firmware update must
reside in bank 1.
Due to the above limitations, it has been decided to use
custom boot loader, and therefore this presentation is
released for the public not to repeat our mistakes 
Memory banks in STM32L1XX
Two Banks
All of Bank 1 and Half of Bank 2 are accessible
by ST ROM Bootloader
Factory Code @ Bank1
(start address 0x08000000)
Updated Code @ Bank2
(start address 0x08040000)
Updated Reticles & Menus @ bank 1
(start address 0x08008000)
Factory Reticles & Menus @ bank2
(start address 0x08048000)
Wrtieto EEPROM:
Go_to_BL_Flag=1
Yes
Wake up
from Reset
Go_to_BL_Flag=0
Remap 0x00 to BLflash
Set stackpointer to BLStack
Jump to BL
Yes
Software
Reset
nBFB2 ==1 ?
Field Upgrade
Request ?
Normal code
Run from bank 2
No
Communication
with BL
Established ?
Establish
communication
with BL
Error message
(in application)
Reset (Opt. Byte)
No Writecodeto Bank2
And / Or Datato Bank1
Read To ValidateOK?
Set nBFB2 =0
(Initiatesreset)
Yes
No
Yes
Go_to_BL_Flag==1 ?
No
Remap 0x00
to Flash 2
Remap 0x00 to Flash1No
Set nBFB2 =1
Coderun from bank 1
Field Upgrade
Request ?
No
Yes
Yes
‫הקוד‬ ‫עם‬ ‫שילוב‬"‫הרגיל‬"
‫על‬ ‫שאחראי‬ ‫הקוד‬ ‫עם‬firmware update
BL.C
#include "BL.h"
void GoToBootLoader(void)
{
//Initializing the arguments for HAL functions
FLASH_AdvOBProgramInitTypeDef OBbank1;
OBbank1.BootConfig = OB_BOOT_BANK1;
OBbank1.OptionType = OPTIONBYTE_BOOTCONFIG;
// Write to EEPROM that BootLoader should be executed
HAL_FLASHEx_DATAEEPROM_Unlock();
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD,
EEPROM_Address_Mode_Of_Execution,
ShouldExecuteBootLoader);
//Change to (or stay at) bank1 and reset the device
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_AdvOBProgram(&OBbank1);
HAL_FLASH_Unlock();
HAL_FLASH_OB_Launch();
}
void SystemInit (void)
// Define our function pointer
void (__code*SysMemBootJump)(void);
// Set system memory address.
volatile uint32_t addr = BootLoaderMemoryLocation;
if(…) // MCU was Set to be boot from bank 1
if ( // Jump to boot loader request is registered
// Reset our trigger
HAL_FLASHEx_DATAEEPROM_Erase(FLASH_TYPEPROGRAM_WORD, EEPROM_Address_Mode_Of_Execution);
//Set jump memory location for system memory
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4 )));
//Remap system memory to address 0x0000 0000 in address space
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
SCB->VTOR = 0; // BootLoaderMemoryLocation; Since 0 is mapped to system memory
__set_MSP(*(uint32_t *)addr);
// Point the PC to the System Memory reset vector
SysMemBootJump();
}
else{ // Running Code from bank 1
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH.*/
}
}
else // run from bank2
{
SCB->VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET;
}
Requirement from external application
Input
The input to the external (smarthphone) is a binary file of size
X bytes,
where 0x38000 < X < 0x40000 changes from one update to
the other.
Goal
The binary file is to be copied into flash, where the first byte is
copied to address UpdateCodeStartAddress and the last
address is to be copied to UpdateCodeStartAddress + X, where
UpdateCodeStartAddress = 0x08008000.
After the file is copied (and verified that it is copied correctly),
the gun sight should be booted from bank 2 of the DM code.
The rest of the document is only a recommendation
Added value in brief
The following observation are not explicitly found in
ST Official documentation:
– When running from bank 2 (nBFB2 = 0),
an attempt to update firmware from system memory
will FAIL, because it will result in jumping back to bank 2
– Unlike STM32L0XXX and STM32L4XXX,
nBFB2 does not result in bank swap

More Related Content

What's hot

Fetch decode-execute presentation
Fetch decode-execute presentationFetch decode-execute presentation
Fetch decode-execute presentation
chantellemallia
 
Memory & the fetch decode-execute cycle
Memory & the fetch decode-execute cycleMemory & the fetch decode-execute cycle
Memory & the fetch decode-execute cycle
chantellemallia
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
sheetal singh
 

What's hot (20)

Fetch decode-execute presentation
Fetch decode-execute presentationFetch decode-execute presentation
Fetch decode-execute presentation
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
 
presentation on timing diagram
presentation on timing diagrampresentation on timing diagram
presentation on timing diagram
 
Computer Architecture – An Introduction
Computer Architecture – An IntroductionComputer Architecture – An Introduction
Computer Architecture – An Introduction
 
Instruction cycle
Instruction cycleInstruction cycle
Instruction cycle
 
Memory & the fetch decode-execute cycle
Memory & the fetch decode-execute cycleMemory & the fetch decode-execute cycle
Memory & the fetch decode-execute cycle
 
Computer Organisation (DFT1113)
Computer Organisation (DFT1113)Computer Organisation (DFT1113)
Computer Organisation (DFT1113)
 
15 control-computer organization and archietecture-CO-COA
15 control-computer organization and archietecture-CO-COA15 control-computer organization and archietecture-CO-COA
15 control-computer organization and archietecture-CO-COA
 
Cpu & its execution of instruction
Cpu & its execution of instructionCpu & its execution of instruction
Cpu & its execution of instruction
 
Advanced Embedded System Subject seminar on SCB,DEBUG,RESET
Advanced Embedded System Subject seminar on SCB,DEBUG,RESETAdvanced Embedded System Subject seminar on SCB,DEBUG,RESET
Advanced Embedded System Subject seminar on SCB,DEBUG,RESET
 
Instruction cycle presentation
Instruction   cycle presentationInstruction   cycle presentation
Instruction cycle presentation
 
Computer Organization: Introduction to Microprocessor and Microcontroller
Computer Organization: Introduction to Microprocessor and MicrocontrollerComputer Organization: Introduction to Microprocessor and Microcontroller
Computer Organization: Introduction to Microprocessor and Microcontroller
 
Input & Output
Input & OutputInput & Output
Input & Output
 
Microprocessor systems (4)
Microprocessor systems (4)Microprocessor systems (4)
Microprocessor systems (4)
 
Computer Organization : CPU, Memory and I/O organization
Computer Organization : CPU, Memory and I/O organizationComputer Organization : CPU, Memory and I/O organization
Computer Organization : CPU, Memory and I/O organization
 
computer Architecture
computer Architecturecomputer Architecture
computer Architecture
 
Instruction set and instruction execution cycle
Instruction set and instruction execution cycleInstruction set and instruction execution cycle
Instruction set and instruction execution cycle
 
MicroProgrammed Explained .
MicroProgrammed Explained .MicroProgrammed Explained .
MicroProgrammed Explained .
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 

Similar to ST Built in Boot loader

CODE BLUE 2014 : A security assessment study and trial of Tricore-powered aut...
CODE BLUE 2014 : A security assessment study and trial of Tricore-powered aut...CODE BLUE 2014 : A security assessment study and trial of Tricore-powered aut...
CODE BLUE 2014 : A security assessment study and trial of Tricore-powered aut...
CODE BLUE
 
micro controllers 1.ppt
micro controllers 1.pptmicro controllers 1.ppt
micro controllers 1.ppt
siminkhan
 

Similar to ST Built in Boot loader (20)

Boot loader for STM32L1XX
Boot loader for STM32L1XXBoot loader for STM32L1XX
Boot loader for STM32L1XX
 
4bit pc report[cse 08-section-b2_group-02]
4bit pc report[cse 08-section-b2_group-02]4bit pc report[cse 08-section-b2_group-02]
4bit pc report[cse 08-section-b2_group-02]
 
4bit PC report
4bit PC report4bit PC report
4bit PC report
 
Pic full note
Pic full notePic full note
Pic full note
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
 
01 introduction to_microprocessor
01 introduction to_microprocessor01 introduction to_microprocessor
01 introduction to_microprocessor
 
2.computer org.
2.computer org.2.computer org.
2.computer org.
 
ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3
 
Presentation_Final
Presentation_FinalPresentation_Final
Presentation_Final
 
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxINDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
 
AAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System StartupAAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System Startup
 
Module 5 embedded systems,8051
Module 5 embedded systems,8051Module 5 embedded systems,8051
Module 5 embedded systems,8051
 
embedded system introduction to microcontrollers
embedded system introduction to microcontrollersembedded system introduction to microcontrollers
embedded system introduction to microcontrollers
 
Hardware
HardwareHardware
Hardware
 
CODE BLUE 2014 : A security assessment study and trial of Tricore-powered aut...
CODE BLUE 2014 : A security assessment study and trial of Tricore-powered aut...CODE BLUE 2014 : A security assessment study and trial of Tricore-powered aut...
CODE BLUE 2014 : A security assessment study and trial of Tricore-powered aut...
 
micro controllers 1.ppt
micro controllers 1.pptmicro controllers 1.ppt
micro controllers 1.ppt
 
Pic16f84
Pic16f84Pic16f84
Pic16f84
 
CSA PPT UNIT 1.pptx
CSA PPT UNIT 1.pptxCSA PPT UNIT 1.pptx
CSA PPT UNIT 1.pptx
 
Introduction to-microprocessor
Introduction to-microprocessorIntroduction to-microprocessor
Introduction to-microprocessor
 
Introduction to-microprocessor
Introduction to-microprocessorIntroduction to-microprocessor
Introduction to-microprocessor
 

Recently uploaded

Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
drm1699
 

Recently uploaded (20)

architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmux
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 

ST Built in Boot loader

  • 1. ST built-in Boot Loader Applicable to STM32L1XX Due to the technical limitations that will be detailed below, Meprolight has decided not to use ST built in boot loader Hence this presentation does not contain sensitive information
  • 2. Agenda • MCU Architerture 3 slides • ST Built in Bootloader 3 slides • Implementation Flowchart 1 slide • Merging the code 3 slides • External application 2 Slides • Validation 1 Slide
  • 3. © Hakim Weatherspoon, Computer Science, Cornell University Basic Computer System • A processor is a device that executes instructions Processor has some internal state in storage elements (registers) • A memory holds instructions and data von Neumann architecture is assumed for simplicity • A bus connects the two regs bus processor memory 01010000 10010100 … addr, data, r/w
  • 4. ARM Cortex-M Start up Sequence • Electronically – Fetch Stack Pointer from address 0x00 – Fetch Program Counter from address 0x04 • Software – Execute assembly function Reset_Handler (initialize vector table and call the followings) – Execute c function SystemInit Initializes clocks and VTOR – Execute assembly function __iar_data_init3Initialize Initializes variables – Call function main User program But address 0x00 does not exist in Flash ! It is mapped to other address (0x08000000 in normal execution)
  • 5. Where is the Vector Table located ?
  • 6. System Memory • Written in ROM within the Flash • Has two functions: – Firmware update – Execute code from bank 2 (When nBFB2 = 0 at startup)
  • 7. nBFB2 bit • nBFB2 = 1 at startup  Normal Execution • nBFB2 = 0 at startup – Address 0x00 is mapped electronically to System memory – System memory Jumps to bank 2 • Undocumented important Takeaways: – When running from bank 2 (nBFB2 = 0), an attempt to update firmware from system memory will FAIL, because it will result in jumping back to bank 2 – Unlike STM32L0XXX and STM32L4XXX, nBFB2 does not result in bank swap
  • 8. Bootloader limitations ST bootloader has limited address range allowed to be written (all of bank 1 and ½ of bank 2) Thus, If the application requires more than ½ the space of a bank, only one version of the application may be updated. Since the firmware update may only be conducted when nBFB2 = 1, the code that initiates the firmware update must reside in bank 1. Due to the above limitations, it has been decided to use custom boot loader, and therefore this presentation is released for the public not to repeat our mistakes 
  • 9. Memory banks in STM32L1XX Two Banks All of Bank 1 and Half of Bank 2 are accessible by ST ROM Bootloader Factory Code @ Bank1 (start address 0x08000000) Updated Code @ Bank2 (start address 0x08040000) Updated Reticles & Menus @ bank 1 (start address 0x08008000) Factory Reticles & Menus @ bank2 (start address 0x08048000)
  • 10. Wrtieto EEPROM: Go_to_BL_Flag=1 Yes Wake up from Reset Go_to_BL_Flag=0 Remap 0x00 to BLflash Set stackpointer to BLStack Jump to BL Yes Software Reset nBFB2 ==1 ? Field Upgrade Request ? Normal code Run from bank 2 No Communication with BL Established ? Establish communication with BL Error message (in application) Reset (Opt. Byte) No Writecodeto Bank2 And / Or Datato Bank1 Read To ValidateOK? Set nBFB2 =0 (Initiatesreset) Yes No Yes Go_to_BL_Flag==1 ? No Remap 0x00 to Flash 2 Remap 0x00 to Flash1No Set nBFB2 =1 Coderun from bank 1 Field Upgrade Request ? No Yes Yes
  • 11. ‫הקוד‬ ‫עם‬ ‫שילוב‬"‫הרגיל‬" ‫על‬ ‫שאחראי‬ ‫הקוד‬ ‫עם‬firmware update
  • 12. BL.C #include "BL.h" void GoToBootLoader(void) { //Initializing the arguments for HAL functions FLASH_AdvOBProgramInitTypeDef OBbank1; OBbank1.BootConfig = OB_BOOT_BANK1; OBbank1.OptionType = OPTIONBYTE_BOOTCONFIG; // Write to EEPROM that BootLoader should be executed HAL_FLASHEx_DATAEEPROM_Unlock(); HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD, EEPROM_Address_Mode_Of_Execution, ShouldExecuteBootLoader); //Change to (or stay at) bank1 and reset the device HAL_FLASH_OB_Unlock(); HAL_FLASHEx_AdvOBProgram(&OBbank1); HAL_FLASH_Unlock(); HAL_FLASH_OB_Launch(); }
  • 13. void SystemInit (void) // Define our function pointer void (__code*SysMemBootJump)(void); // Set system memory address. volatile uint32_t addr = BootLoaderMemoryLocation; if(…) // MCU was Set to be boot from bank 1 if ( // Jump to boot loader request is registered // Reset our trigger HAL_FLASHEx_DATAEEPROM_Erase(FLASH_TYPEPROGRAM_WORD, EEPROM_Address_Mode_Of_Execution); //Set jump memory location for system memory SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4 ))); //Remap system memory to address 0x0000 0000 in address space __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); SCB->VTOR = 0; // BootLoaderMemoryLocation; Since 0 is mapped to system memory __set_MSP(*(uint32_t *)addr); // Point the PC to the System Memory reset vector SysMemBootJump(); } else{ // Running Code from bank 1 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH.*/ } } else // run from bank2 { SCB->VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET; }
  • 14. Requirement from external application Input The input to the external (smarthphone) is a binary file of size X bytes, where 0x38000 < X < 0x40000 changes from one update to the other. Goal The binary file is to be copied into flash, where the first byte is copied to address UpdateCodeStartAddress and the last address is to be copied to UpdateCodeStartAddress + X, where UpdateCodeStartAddress = 0x08008000. After the file is copied (and verified that it is copied correctly), the gun sight should be booted from bank 2 of the DM code. The rest of the document is only a recommendation
  • 15. Added value in brief The following observation are not explicitly found in ST Official documentation: – When running from bank 2 (nBFB2 = 0), an attempt to update firmware from system memory will FAIL, because it will result in jumping back to bank 2 – Unlike STM32L0XXX and STM32L4XXX, nBFB2 does not result in bank swap