cancel
Showing results for 
Search instead for 
Did you mean: 

FLASH_ErasePage NOT WORK WITH BOOTLOADER

veyselka
Associate II
Posted on February 20, 2013 at 14:56

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-flash
9 REPLIES 9
Posted on February 20, 2013 at 16:37

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?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
veyselka
Associate II
Posted on February 20, 2013 at 17:44

Hi clive,

MCU is STM32F103RCT6 , minumum erase size is  0x800h ( 2 KB ) for thisseries.  External high speed clock enable  8Mhz osc. CPU worked 72Mhz

IWDG is enable and set 2s ( 2000000 ) ..

STM32F1X series bootloader example is AN2557 and its total less then  6Kb. My bootloader is more simple..it doesnt have Ymodem etc.. its lower then 2KB.  

3 usart interrupt is enable , Timer 1-2-3 interrupt is enable.  If I dont use , flash erase User APP work properly..

I cant use debug. STlink doesnt work Keil properly.  but I try one serial for system out hope it will help.

************************************************************                      

printf(''FLASH ERASE TEST\n'');

printf(''FLASH STATUS:%d\n'',FLASH_GetStatus());  

for(EraseCounter=0; EraseCounter<Flash_EEPROM_Nb_Of_Page; EraseCounter++) {

        FLASHStatus = FLASH_ErasePage(Start_Address+(FL_EEPROM_PageSize* EraseCounter));  // Start_Address is 0x08020000   PAGE size is 800 and Erase Counter is how many page will be erased 

        if (FLASHStatus != FLASH_COMPLETE) {

                return FLASHStatus;

        }

}

printf(''Format Complete\n'');

FLASH_Lock();

*****************************************

Sytem out IWDG disable if enable this will repeat itself.               

FLASH ERASE TEST

FLASH STATUS:4

********************************************

I try to define IROM for bootloader ( 0x08000000 to 20000 ) and its same nothing chance..

User APP work with flash lib without bootloader but if I use bootloader it doesnt work .

 I will try to debug and share result..

Thanks. 

Posted on February 20, 2013 at 18:05

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 21, 2013 at 02:31

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); }
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
veyselka
Associate II
Posted on February 21, 2013 at 10:54

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           0x00002000

I 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. 

 

veyselka
Associate II
Posted on February 21, 2013 at 14:14

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..  

 

Amel NASRI
ST Employee
Posted on February 22, 2013 at 16:20

[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:

https://my.st.com/public/Faq/Lists/faqlst/DispForm.aspx?ID=21&level=1&objectid=141&type=product&Source=/public/FAQ/default.aspx

ST.MCU

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on February 22, 2013 at 18:27

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?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
veyselka
Associate II
Posted on February 25, 2013 at 08:35

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.