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


Cannot debug application that uses FLASH for parameter storage

I’m experiencing some difficulty trying to use the SW4STM32 debugger with an application that allocates a portion of the internal FLASH memory for non-volatile parameter storage.

I’ve worked out all the details on how to set up the GCC linker (via the LinkerScript) to reserve a portion of the FLASH for parameter storage, creating a section for variables/objects to be stored in FLASH, using GCC’s __attribute__ ((section ()) directive to designate objects to be stored in the FLASH parameter block, and have successfully created functions to erase and program individual FLASH pages. The project builds, and runs properly if the MCU is programmed outside the SW4STM32 environment and run in standalone mode.

My problem comes when I attempt to run/debug the application within SW4STM32. OpenOCD issues the following error:

Info : Padding image section 0 with 253592 bytes
Error: flash write algorithm aborted by target
Error: flash write failed at address 0x800200a
Error: flash memory not erased before writing
Error: error writing to flash at address 0x08000000 at offset 0x00000000

This problem occurs if the code attempts to reference any variable placed in the .param_flash section (see below).

Note that objects placed in the .param_flash section (P_FLASH region, see linker script below) will be located in the 2K region of FLASH starting at 0x0803F800 (the last 2K of FLASH on a STM32F091RC).

What changes, if any, should I make to the run/debug configuration and/or the OpenOCD configuration script to get it to ignore the last 2K (or any other page-sized region) of FLASH when it writes the application code to the MCU?

The linker script file (LinkerScript.ld) contains the following modifications (not shown in its entirety, just the relevant changes/additions):

/* Memories definition - STM32F091RC */

MEMORY
{
  RAM (rwx)    : ORIGIN = 0x20000000, LENGTH = 32K
  ROM (rx)     : ORIGIN = 0x08000000, LENGTH = 254K
  P_FLASH (rw) : ORIGIN = 0x0803F800, LENGTH = 2K     /* Reserve last page for NVM parameters */
}

/* Sections */

...

  /* Non-volatile parameter data in FLASH */

  .param_flash :
  {
    . = ALIGN(0x800);
    __param_flash_start = .;
    *(.param_flash)
    *(.param_flash*)
    . = ALIGN(4);
    __param_flash_end = .;
  } >P_FLASH

...

An example of a variable definition in the .param_flash section:

param_t param_flash __attribute__ ((section (".param_flash"),used));

The OpenOCD error shown above occurs only if the param_flash variable, or any other variable placed in the .param_flash section, is referenced somewhere in the code.

set NOLOAD atribbute for param_flash section like for bss section...

 

Newest Forum Posts

  1. Монтаж камина с грилем в Москве - установка и барбекю by KpddomErorb, 2025-05-10 18:28
  2. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  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. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  9. Build a project in "release" mode by tang, 2025-02-20 10:36
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35

Last-Modified Blogs