Writing uint64_t on a specific memory address.

Hello all,

i need to save uint64_t in to a specific memory address.

in main. c
__attribute__((section(".flash_id_number"))) const uint64_t my_id_number = 0x1500080507032592;
i have create my .ld file named: my_memory.ld
SECTIONS
{
   .flash_id_number 0x40000 :
   {
      *(.flash_id_number)
      KEEP(*(.flash_id_number*))
   } > FLASH
}
i have edited CMakeList.txt as follow:
#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
cmake_minimum_required(VERSION 3.20.0)

set(LINKER_SCRIPT "C:/Users/Enrico/PTT_Dual_2_0/my_memory.ld")

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
but when i build the project i can not see in zephyr.hex the number that i writte.
I made another attempt and modified the linker.cmd file as follows:
....
ztest :
{
 _ztest_expected_result_entry_list_start = .; KEEP(*(SORT_BY_NAME(._ztest_expected_result_entry.static.*))); _ztest_expected_result_entry_list_end = .;
 _ztest_suite_node_list_start = .; KEEP(*(SORT_BY_NAME(._ztest_suite_node.static.*))); _ztest_suite_node_list_end = .;
 _ztest_unit_test_list_start = .; KEEP(*(SORT_BY_NAME(._ztest_unit_test.static.*))); _ztest_unit_test_list_end = .;
 _ztest_test_rule_list_start = .; KEEP(*(SORT_BY_NAME(._ztest_test_rule.static.*))); _ztest_test_rule_list_end = .;
} > FLASH

.flash_id_number 0x40000 :
{
   *(.flash_id_number)
   KEEP(*(.flash_id_number*))
} > FLASH
....

It works, and I can see the values written at the correct memory address, but when I recompile the main.c it deletes the changes in the linker.cmd file, and I no longer have the values at the correct memory address.

I'm using nrf52840 and ncs 2.6.1

Can you help me in some way?

Related