cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 flash problem

gstober9
Associate II
Posted on July 20, 2011 at 14:12

Hello,

in my application I use a part of the flash (0x8007C00 ... 0x8008000) as memory for my own data. I's all ok when I locate the application at address 0x8000000, but when I locate my application to address 0x8003000 the flash programming goes wrong, after the command ''erase page'' (FLASH->CR |= CR_STRT_Set) the system hangs.

Can anybody help me to solve this problem?

Regards,

Gert.

#stm32-flash
7 REPLIES 7
ivanov-i2
Associate II
Posted on July 20, 2011 at 16:10

Probably your program is longer than 19456 bytes (0x4C00) and you are erasing part of it.

You need to check the occupied address range from the linker listing.

gstober9
Associate II
Posted on July 20, 2011 at 16:51

The last address of my application is 0x80072b4. This error occurs also when I use another flash range e.g. 0x8002C00.

Regards,

Gert.

Posted on July 20, 2011 at 17:45

Can anybody help me to solve this problem?

 

 

Sure, what's your contractor rate?

You have provided insufficient information/code to give a clear diagnosis, so let's just guess.

You're touching memory in an inappropriate way, and the system is Hard Faulting. Did you move the vector table address when your application moved to 0x08003000? Do you have a Hard Fault handler to catch failures? Have you single stepped at an instruction level with a JTAG debugger? Have you checked the memory window for the data area in question? What's the flash page size for the part you are using?

Post some more complete code for the flash routine, may be there are some obvious issues there.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gstober9
Associate II
Posted on July 22, 2011 at 08:20

I have move the vector table address to the range where my application is run and I have also a hard fault handler. The flash page size is 1kByte. Now I have comment out the flash page erase command, because no hard fault handler was called and the JTAG debugger was hanging.

The next step, I tried, was programm the flash. Now the hard fault handler was called, when I try to write at the flash (no matter which flash range I use).

FLASH_Status ProgramWord(uint32_t Address, uint32_t Data)

{

  FLASH_Status status = FLASH_COMPLETE;

  __IO uint32_t tmp = 0;

  /* Wait for last operation to be completed */

  status = WaitForLastOperation(ProgramTimeout);

 

  if(status == FLASH_COMPLETE)

  {

    /* if the previous operation is completed, proceed to program the new first

    half word */

    FLASH->CR |= CR_PG_Set;

 

    *(__IO uint16_t*)Address = (uint16_t)Data; // after this command, hard fault handler called

   

    /* Wait for last operation to be completed */

    status = WaitForLastOperation(ProgramTimeout);

 

    if(status == FLASH_COMPLETE)

    {

      /* if the previous operation is completed, proceed to program the new second

      half word */

      tmp = Address + 2;

      *(__IO uint16_t*) tmp = Data >> 16;

   

      /* Wait for last operation to be completed */

      status = WaitForLastOperation(ProgramTimeout);

       

      /* Disable the PG Bit */

      FLASH->CR &= CR_PG_Reset;

    }

    else

    {

      /* Disable the PG Bit */

      FLASH->CR &= CR_PG_Reset;

    }

  }        

gstober9
Associate II
Posted on July 22, 2011 at 14:32

The flash problem is solved.

ozan_ozdemir
Associate II
Posted on March 28, 2014 at 13:35

I have the same issue , please tell us how to solve this problem..

chen
Associate II
Posted on March 28, 2014 at 14:00

Hi

''I have the same issue , please tell us how to solve this problem..''

Start a new thread and give us details about your problems.

If you can (ie no commercial code) - post your code for us to inspect.

My initial thoughts are : look carefully where your Flash programming code is located (which Flash Sector) and which sector the code is trying to erase/program!