Comments (8)
So the idea is to check the following: does the stack pointer of the application (located at 0x08008000) lie between the RAM start address and RAM end address? It could be "translated" to the following:
is (0x20000000) <= (*(APP_ADDRESS)) <= (0x20000000 + RAM_SIZE - 1) ?
However if you consider the code in the CheckForApplication function, you can verify that it does exactly the same, but this method is a creative and (more importantly) faster way than actually performing the above mentioned two comparisons.
from stm32-bootloader.
Hi,
The RAM_SIZE define should have been named more exact - namely SRAM1_SIZE. Those numbers represent the size of the SRAM1 (used by default) in the MCU, which are 256kB for the L496xx and 96kB for the L476xx.
In the case of the L496, you can just simply specify and use the full RAM size (320kB), because the SRAM1 and SRAM2 are continuously defined in the memory space and you don't have to switch in between the two. (Please refer to the MCU's reference manual and datasheet.)
In the case of the L476, the SRAM2 is not continuous to the SRAM1, it is placed elsewhere in the memory space, therefore you cannot simply use the full RAM size 'continuously' as it is in the L496.
Best,
Akos
from stm32-bootloader.
Ok - that makes sense. Thanks!
I have another question though: the only place RAM_SIZE is used is in this function:
uint8_t Bootloader_CheckForApplication(void)
{
return ( ((*(__IO uint32_t*)APP_ADDRESS) & ~(RAM_SIZE-1)) == 0x20000000 ) ? BL_OK : BL_NO_APP;
}
For the STM32L496xx, for example, the equation is
- APP_ADDRESS = 0x08008000
- RAM_SIZE = 0x00040000
0x08008000 & ~(0x00040000) = 0x08000000
Why does the address 0x08000000 evaluate to 0x20000000 when the Bootloader has loaded a program? And why such a roundabout way of calculating this address?
Thanks heaps for your help.
from stm32-bootloader.
The CheckForApplication function uses the following principle to check accurately whether the application space contains valid application firmware: when you compile&build an application and check the output binary, the very first DWORD (first 4 bytes) of the firmware always represents the location of the stack pointer. Therefore at startup, the microcontroller knows where to initialize the stack pointer. This value is very specific, in fact the value must be within the SRAM range, which starts at 0x2000000 and the size depends on the actual microcontroller variant. For example, the L476VG has 96k SRAM1 starting from the above mentioned location, so in the CheckForApplication verifies that the first 4 bytes of the binary lies within its SRAM1 memory space. This method gives a very accurate guess whether the application space contains garbage or an actual, valid application firmware.
Best,
Akos
from stm32-bootloader.
Okay, but according to your memory diagram in the README (Figure 2)
0x08000000 is the first DWORD of the Bootloader, not the first DWORD of the Program. So how does this address end up as part of the Program?
Sorry for being confused!
from stm32-bootloader.
I get it, thanks for your help!
from stm32-bootloader.
Hello @akospasztor . I read the above comments. I tried the same code to check if the application is present, but it always fails.
The values I'm using are:
#define BOOTLOADER_ADDRESS ((uint32_t)0x08000000)
#define APPLICATION_ADDRESS ((uint32_t)0x08008000) /* Start user code address: ADDR_FLASH_PAGE_13 */
#define RAM_BASE SRAM1_BASE /*!< Start address of RAM */
#define RAM_SIZE SRAM1_SIZE_MAX /*!< RAM size in bytes */
uint8_t Bootloader_CheckForApplication(void)
{
return (((*(uint32_t*)APPLICATION_ADDRESS) - RAM_BASE) <= RAM_SIZE) ? BL_OK : BL_NO_APP;
}
from stm32-bootloader.
Hey @fatalcoder524,
Can you check why does it fail?
- What kind of MCU do you use?
- What kind of compiler / IDE do you use?
- What kind of value is present at the address of
APPLICATION_ADDRESS
(0x08008000) just before calling theBootloader_CheckForApplication
function? - Are the
SRAM1_BASE
andSRAM1_SIZE_MAX
defines correctly defined? - Are the bootloader project options properly configured? (i.e. is the RAM start address and size properly configured so that it reflects those defines?)
from stm32-bootloader.
Related Issues (20)
- Add command line argument to provide path to clang-format
- Add support for GNU Arm Embedded Toolchain
- Fix clang-format issue on CI HOT 1
- Add GCC build job to CI pipeline
- Add support for building the projects with scons
- Linker Script Question HOT 2
- Add stale bot to repository
- Add yamllint to repository HOT 1
- Update clang-format version to 11
- Add pull request template
- CI: Use docker image for jobs
- CI: Add style check job
- Support for STM32F4 series HOT 2
- How to build the firmware image HOT 4
- OTA firmware update on stm8s HOT 2
- Not an issue - a question - SCB->VTOR issue with F103? HOT 3
- use of stm32-Bbootloader HOT 1
- CI: Fix editorconfig-checker command not found issue
- HardFault at f_read HOT 1
- Is it a bug in function Bootloader_Erase()? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stm32-bootloader.