Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


STM32F103C8T6 - problem with FLASH_ErasePage when variable declared in custom section

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

 

Newest Forum Posts

  1. reservation car service Seattle by Jamesprede, 10:06
  2. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  10. Build a project in "release" mode by tang, 2025-02-20 10:36

Last-Modified Blogs