2013-02-20 05:56 AM
Hi , everyone ...
I have a problem when using stm32 flash routines.
My problem is , when I change vector table after bootloader starts,
FLASH_Status FLASH_ErasePage(u32 Page_Address) function doesnt work and MCU is reset for some reason.
As I explain my code, my memory map like this,
----------0x08000000H ---------------
BOOTLOADER
----------0x08002000H ---------------
USER APP.
----------0x08020000H ---------------
DATA STORAGE
----------0x08040000H ---------------
Bootloader is for copy from pages DATA STORAGE to USER APP. ( Bootloader also check firmware version etc from storage area )
There was a two different scenario with bootloader and without bootloader.
1 - with out bootloader
If I compile User App. for ( Vector Table OFSET is 0 and ROM1 START is 0x08000000 - 0x20000)
I can write / read and erase flash page on data storage. Flash library and code works fine !
2 with bootloader
If I compile User App. for ( 0x08002000 ), Flash routines get fault and MCU restart ( Vector Table OFSET is 2000 and ROM1 START is 0x08002000 - 0x20000 or 1E000)
Bootloader works, and can use flash routines and jump USER APP.
USER APP starts set vektor table ofset to 0x2000h,
APP. can read Flash page for some configuration. USART and timers works fine.
But When APP. has to be write something on flash. MCU restart itself. ( its stuck when using flash_FLASH_ErasePage (u32 page) )
I don't understand, why FLASH firmware library made this error .
Am I misses some pre-configuration for flash library?
Also , I check page with using SMT32-STlink Utility , there wasnt any option byte configration for storage area
I'm using Keil mVison 4 , User APP use RTX and bootloader not.
.. I dont thinks this is about compiler. Its looks like interrupts and configuration.
If somebody help me about that .. I will be very glad..
Best Regards.
#stm32-bootloader-flash2013-02-20 07:37 AM
Clocks, Interrupts? What part? Isn't minimum erase size 16KB on an F4?
Clearing status? Try outputting diagnostic information, debugging. Try also without debugger, it messes with things. Erasing area where execution is occurring, vector table or overlapping the page? What if you define IROM length as 0x2000 (ie 8KB not 128KB) for the Boot Loader? Does it fit? Does it crash, or enter Hard Fault?2013-02-20 08:44 AM
2013-02-20 09:05 AM
I can't say I've had many problems with ST-Link and Keil. (4.xx ST-Link deprecated) current drivers, and firmware.
May be compute and print out the erase address in your loop, and check the for() range. I can't say I've had problems with flashing a 512KB F103 part, usually you'll get an error if you do something wrong, or crash is you erase code/interrupts that are trying to function. You could perhaps examine the memory after the failing condition (ST-LINK or Keil SAVE) and see if you nuked any memory you didn't expect.2013-02-20 05:31 PM
You might also want to consider what the CMSIS library is doing with the vector table in SystemInit(), which is called before main(). See V3.5.0 library
The following is how I might do this in a less ambiguous fashion// Quick STM32F103 512KB Flash Erase Demo - sourcer32@gmail.com
// Erases 256K to 512K region #define FLASH_PAGE_SIZE 0x800 FLASH_Status FLASH_EraseAppDataSpace(void) { uint32_t Addr; FLASH_Status FLASHStatus = FLASH_COMPLETE; /* Unlock the Flash Program Erase controller */ FLASH_Unlock(); /* Clear All pending flags */ FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); for(Addr=0x08040000; Addr<0x08080000; Addr += FLASH_PAGE_SIZE) // Space we're not running in { // Kick Watch Dog Here, be conscious how long it takes to erase pages // Would be smart to blank check first and skip already blank pages FLASHStatus = FLASH_ErasePage(Addr); if (FLASHStatus != FLASH_COMPLETE) break; } /* Lock the Flash controller */ FLASH_Lock(); return(FLASHStatus); }2013-02-21 01:54 AM
Maybe I got a clue, When I try to use debug , flash routines work properly and it write sample data to flash. But debug doesnt work couse MCU starts.
I'm using STM32_Init.c file to initialize MCU, //=========================================================================== Nested Vectored Interrupt Controller// <e0> Nested Vectored Interrupt Controller (NVIC)// <e1.0> Vector Table Offset Register // <o2.29> TBLBASE: Vector Table Base // <i> Default: FLASH// <0=> FLASH// <1=> RAM// <o2.7..28> TBLOFF: Vector Table Offset <0x0-0x1FFFFFC0:0x80><#/0x80>// <i> Default: 0x00000000// </e>// </e> End of Clock Configuration#define __NVIC_SETUP 1#define __NVIC_USED 0x00000001#define __NVIC_VTOR_VAL 0x00002000I will try simple code , without RTX serial etc... Maybe problem is about RTX or rtx pre-configration. When I use flash routines with RTX , it get stuck.( base adress and vector table is not 0x08000000 ) But why , When base adress and vector table is 0x0800000 everything is smooth..thanks your help.2013-02-21 05:14 AM
I just wrote a small code for USER APP and its size about 3K. Still I have same problem.
Now I can use Keil and STlink with debug options. /******************************************************************************/int main (void) { int i=0; stm32_Init (); /* STM32 setup - Vector Table 0x08002000 / * printf (''\nUSER APP STARTED\n''); while (1) { sprintf(data,''FLASH PAGE WRITTEN %d'',i); Flash_EEPROM_Write_Data_8(DataAddress,data,strlen(data)); // printf (''%s\n'',data); i++; delay_ms(1000); }} When I debug it , code is working properly and nothing crashed. But hard reset or repower its crushed again while FLASH_ErasePage() ; 0x08020000 page is**********************************464C4153482050414745205752495454 F L A S H P A G E W R I T T 454E2034FFFFFFFFFFFFFFFFFFFFFF E N 4 ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ***********************************When using debug mode and step by step why is it working ? I dont use any interupts, timers or wathdog..2013-02-22 07:20 AM
[Edit]: Sorry, this hasn't to deal with your issue. Forget about my suggestion.
----------------------------------------------------------------------------------------- Hi Veysel, May be the following FAQ can bring you some help: ST.MCUTo give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2013-02-22 09:27 AM
But exactly how is it crashing? Is it ending up in a Hard Fault or Abort routine? You need to pin this down.
Does the code example I provided work AS-IS? Have you cleared any current errors status from the flash controller (4 = Program Error)? The debugger probably downloads your code before starting, and deals with the controllers initial state better than your code? Perhaps you can dump out registers, and compare/contrast your failing condition vs the debugger attached working condition. Is there an issue with the wait states, or supply? Probably not, but I'll throw it out there. What speed is the processor running at?2013-02-24 11:35 PM
Hi Clive ,
Its about Bootloader codes. When I add RCC_DeInit() line before jump User APP. I dont get a same problem anymore. I saw that information on youtube video. AN2557 doesnt use RCC_DeInit. Now , Flash routines write and read properly. Hope there wont be any other problem.. Thanks best Regards.