Comments (3)
The blow is my program inherit from you.
bool bootLoaderEraseFlash(void)
{
/**
* @brief 定义FLASH每个Bank有多少Pages
* STM32L4系列分为两个Bank,每个Bank=256Pages 每个Page=2K
*/
uint32_t numberOfPages = 0;
uint32_t pageError = 0;
FLASH_EraseInitTypeDef flashEraseInit;
HAL_StatusTypeDef halStatus = HAL_OK;
HAL_FLASH_Unlock();
numberOfPages = (FLASH_BASE+FLASH_SIZE-USR_APP_ADDRESS)/FLASH_PAGE_SIZE;
flashEraseInit.Banks = FLASH_BANK_1; // 擦除指定的Bank 目前用的L476RC只有一个Bank
flashEraseInit.NbPages = numberOfPages % (FLASH_BANK_SIZE/FLASH_PAGE_SIZE); // 一次性擦除多少页
flashEraseInit.Page = (USR_APP_ADDRESS-FLASH_BASE)/FLASH_PAGE_SIZE; // 擦除的起始页,从除去BootLoader开始
flashEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; // 擦除类型是“Page Erase”
halStatus = HAL_FLASHEx_Erase(&flashEraseInit, &pageError);
if ((halStatus == HAL_OK)&&(numberOfPages > (FLASH_BANK_SIZE/FLASH_PAGE_SIZE)))
{
flashEraseInit.Banks = FLASH_BANK_2;
flashEraseInit.NbPages = numberOfPages - flashEraseInit.NbPages; // 减去上次擦除的Pages得到剩余的
flashEraseInit.Page = USR_APP_ADDRESS-(FLASH_BASE+FLASH_BANK_SIZE)/FLASH_PAGE_SIZE;
flashEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
halStatus = HAL_FLASHEx_Erase(&flashEraseInit, &pageError);
}
HAL_FLASH_Lock();
if (halStatus == HAL_OK)
{
logInfo("IAP Erase the flash [0x%08X-0x%08X] successfully!", USR_APP_ADDRESS, FLASH_SIZE);
return true;
}
else
{
logError("IAP Erase the flash error!");
return false;
}
}
from stm32-bootloader.
Hi @KiraVerSace,
If you use a microcontroller that has flash banks with number of pages other than 256, then you need to change that in the bootloader.h
file.
I quickly double-checked the datasheet of the STM32L476RC, and it states explicitly that each flash bank contains 256 pages. See page 19:
STM32L476xx devices feature up to 1 Mbyte of embedded Flash memory available for storing programs and data. The Flash memory is divided into two banks allowing read-while-write operations. [...] Each bank contains 256 pages of 2 Kbyte.
However, digging into the reference manual of the microcontroller, this does not seem to be true for devices with 512KB flash size... See page 98 here: https://www.st.com/resource/en/reference_manual/rm0351-stm32l47xxx-stm32l48xxx-stm32l49xxx-and-stm32l4axxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
So yes, you need to adapt the configuration in the bootloader.h
so that the FLASH_PAGE_NBPERBANK
reflects the correct number of flash pages in a bank.
from stm32-bootloader.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
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
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.