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. Provides its users with guidance and responses by ClaudiaAlgof, 2026-03-31 21:55
  2. I2S DMA Audio stuttering/repeating snippets on STM32G071RB by fillnether, 2026-03-17 19:06
  3. Unable to build project by septimusbob, 2026-02-08 20:27
  4. New installations is now uploaded ! by karushifa, 2025-12-25 00:53
  5. Analog servomotors with nucleo f334r8 by SkelePaw, 2025-11-01 05:57
  6. STM32 MCU model shortlisting for Making RC remote by Palvish, 2025-07-07 15:05
  7. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  8. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  9. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  10. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33

Last-Modified Blogs