cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8T6 - problem with FLASH_ErasePage when variable declared in custom section

DK.3
Associate

Hi All

I am trying to store variable in custom section withn FLASH.

In ld file I have the following

  	.flash_crc (LENGTH(FLASH) + ORIGIN(FLASH) - 1K):  
  	{
        . = ALIGN(4); 	
    *(.flash_crc)
    *(.flash_crc.*)
        . = ALIGN(4); 	
  } >FLASH = 0x00
 

Which (I believe) creates custom section at the last 1K page of 64K FLASH.

Then I am trying to declare a variable in my main.cpp

	volatile uint32_t __attribute__((section(".flash_crc"), used)) __flash_crc;

The map file gives me correct section location at 0x800fc00 and variabke fits inicely inside

.flash_crc      0x000000000800fc00        0x4
                0x000000000800fc00                . = ALIGN (0x4)
 *(.flash_crc)
 .flash_crc     0x000000000800fc00        0x4 ./src/main.o
                0x000000000800fc00                __flash_crc
 *(.flash_crc.*)
                0x000000000800fc04                . = ALIGN (0x4)

In the code I am trying just to erase the FLASH page where the variable is located

  FLASH_PrefetchBufferCmd( FLASH_PrefetchBuffer_Enable);
  FLASH_SetLatency( FLASH_Latency_0);
  FLASH_Status flashStatus;
  FLASH_Unlock();
  flashStatus = FLASH_ErasePage((uint32_t)0x800fc00);
  FLASH_Lock();

flashStatus is set to FLASH_COMPLETE, so I would expect everything is fine, and location 0x800fc00 is filled with 0xff.

In reality this does not happen, and contents of 0x800fc00 stays untouched after ERASE.

Strange enough, if I comment out variable declaration, then everything works fine and 0x800fc00 gets filled with 0xff after ERASE.

The same happens when I am trying to write something to 0x800fc00 using

FLASH_ProgramWord(0x800fc00, 0x12345678)

With variable declared inside .flash_crc section nothing is written, when variable commnted out write succesfully occures.

Any help appreciated, thanks in advance

0 REPLIES 0