Skip to main content
TPier
Associate III
November 30, 2021
Solved

Trouble to locate data section in flash (STM32F207)

  • November 30, 2021
  • 5 replies
  • 1622 views

Hi,

I attempt to locate information about the firmware in flash. To do so, the data are stored in a dedicated section (called CONTROL_UNIT_SECTION):

/** @brief Definition of the firmware info. */
typedef struct firmware_info_t {
 uint8_t id; /**< Identifier of the control unit. */
 uint8_t major; /**< Major version number. */
 uint8_t minor; /**< Minor version number. */
 uint8_t rc; /**< Release candidate number, 0 if production release. */
} FirmwareInfo;
 
 
/* Declare the sections in flash that stores the core configuration. */
#pragma section = "CONTROL_UNIT_SECTION"
 
#pragma location = "CONTROL_UNIT_SECTION"
static const FirmwareInfo firmware_info = {
 CONTROL_UNIT_ID,
 FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR,
 DEVELOPMENT_VERSION
};

This section is then located in ROM, using the following statements in the linker file :

define symbol _CU_INFO_REGION_START_ = 0x0803FFF0;
define symbol _CU_INFO_REGION_END_ = 0x0803FFFB;
 
define region CU_INFO_region = mem:[from _CU_INFO_REGION_START_ to _CU_INFO_REGION_END_ ];
 
place in CU_INFO_region { readonly section CONTROL_UNIT_SECTION };

This is used in 2 different projects with the same target (STM32F207VC) and with the same linker file. In one of the projects, the data are not available at the expected location. In the map file, I can find this :

No sections matched the following patterns:
 
 ro section CONTROL_UNIT_SECTION in "P2"

Did I proceed in a wrong way ? What could be the reason of such different behaviors between the projects ?

    This topic has been closed for replies.
    Best answer by TPier

    OK. Found the reason : as soon as optimization is enabled, data placement does not work. Did not find which one yet.

    5 replies

    MM..1
    Super User
    November 30, 2021

    For what this complicated arangement ? Your firmware loads longest way as exist, overwrite full flash ... Why

    TPier
    TPierAuthor
    Associate III
    December 1, 2021

    Could you tell me more ?

    TPier
    TPierAuthorBest answer
    Associate III
    December 1, 2021

    OK. Found the reason : as soon as optimization is enabled, data placement does not work. Did not find which one yet.

    TPier
    TPierAuthor
    Associate III
    December 1, 2021

    Thanks for this answer.

    I already tried to the "keep" directive (in the IAR environment). No success. No error as well, but everything happens as if the section already disappeared at the linking time.

    I have the feeling (and it is only a feeling ;) ) that optimization at compile time removes the data that are expected for the section.