2015-04-17 01:53 AM
Hi all,
I am stuck with an issue about MCU Flash erase. Could you help to instruct me how to solve it? At first, I run my main application 'AA' at address 0x08000000 and this main program just copy another image(called 'UU', stored in SPI flash) into SRAM to jump to 'UU'. So at this moment time, 'UU' is running well on SRAM(at address 0x200000000). I wonder if Prgram 'UU' can erase MCU flash(especially, those sectors used by main program 'AA'). In fact, my program 'UU' is failed to erase MCU Flash(memory sectors occupied by main program 'AA'). Could you give me some hint or example to solve this trouble issue. [P.S.] I develop those programs on Keil/MDK for MCU STM32F429. And I am sure program 'UU' (running on SRAM at address 0x20000000) can erase MCU Flash sectors 0 and 1 successfully when entering debug session of Keil/MDK. #stm32f4292015-04-17 03:38 AM
Most likely you are not unlocking and clearing the current state of the flash controller. The debugger may alter the perceived initial state.
Have your test code report error states returned by the flash functions, and status from the controller. Check also if sectors are wrote protected, though I suspect this is less probable.2015-04-17 03:48 AM
FLASH_Unlock();
/* Clear All pending flags */ FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);2015-04-24 05:39 AM
Hi there
I have just completed developing a bootloader using the STM32F For this application I am running my IAP code in the last 128kB block and the bootloader/factory code in the lower 128kB block.#define NO_OF_FLASH_SECTORS 6
#define IAP_START_SECTOR 5
#define IAP_END_SECTOR 5
#define START_OF_FLASH 0x08000000
#define END_OF_FLASH 0x0803FFFF
typedef struct {
uint32_t sector_base_address;
uint32_t sector_size;
uint16_t flash_sector;
} FlashModuleOrganizationStruct;
static const FlashModuleOrganizationStruct flash_module_org[NO_OF_FLASH_SECTORS+1] = {
{0x08000000, 0x4000, FLASH_Sector_0}, // Sector 0, 16kB
{0x08004000, 0x4000, FLASH_Sector_1}, // Sector 1, 16kB
{0x08008000, 0x4000, FLASH_Sector_2}, // Sector 2, 16kB
{0x0800C000, 0x4000, FLASH_Sector_3}, // Sector 3, 16kB
{0x08010000, 0x10000, FLASH_Sector_4}, // Sector 4, 64KB
{0x08020000, 0x20000, FLASH_Sector_5}, // Sector 5, 128KB
{0x08040000, 0} // ** END OF MEMORY **
};
int bootloaderEraseIAPFlash(uint32_t start_sector, unit32_t stop_sector) {
uint32_t i;
if((start_sector >= IAP_START_SECTOR) && (stop_sector <= IAP_END_SECTOR)) {
FLASH_Unlock();
for(i=start_sector; i<=stop_sector; i++) {
//__disable_irq();
FLASH_EraseSector(flash_module_org[i].flash_sector, VoltageRange_3);
//__enable_irq();
}
FLASH_Lock();
return 1;
}
else return -1;
}
This is working fine, but please note that I am not running this code in the block I am upgrading. I have done similar things in the past, reflashing from an external SPI FLASH device and did have to run from RAM.
I use Ride7/GCC and to run from RAM:
void bootloaderEraseIAPFlash(uint32_t start_sector, unit32_t stop_sector)__attribute__( ( section( ''.RAMtext'' ) ) );
Note the commented IRQ disable/enable sections. This is a fallback to earlier versions of the code when the code for some interrupts was located in the FLASH area I was erasing. Be careful about this, and locate the interrupt code either in RAM or a section of FLASH you are not upgrading. Hope this helps. For the code above, I have edited it from my routine which is a little more involved, so please forgive any minor errors. So in answer to your question, ''Can a standalone program running on SRAM erase MCU FLASH'' the answer is Yes. Regards Grant