Hello,
I am trying to use the **persistent** flash area of my nRF52.
I created a separate zone (PERSISTENT_FLASH) in my LD script as follows:
MEMORY
{
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x52000
PERSISTENT_FLASH(rw): ORIGIN = 0x77000, LENGTH = 0x1000
RAM (rwx) : ORIGIN = 0x20002bf0, LENGTH = 0xd410
}
I try the following C code:
#define FSTORAGE_START 0x77000
#define FSTORAGE_LEN 0x01000
void callback(nrf_fstorage_evt_t * p_evt)
{
NRF_LOG_DEBUG("callback");
}
NRF_FSTORAGE_DEF(nrf_fstorage_t my_instance) =
{
.evt_handler = callback,
.start_addr = FSTORAGE_START,
.end_addr = FSTORAGE_START + FSTORAGE_LEN,
};
void test_flash()
{
ret_code_t rc;
rc = nrf_fstorage_init(
&my_instance, /* You fstorage instance, previously defined. */
&nrf_fstorage_sd, /* Name of the backend. */
NULL /* Optional parameter, backend-dependant. */
);
NRF_LOG_DEBUG("1===> %d %s", rc, nrf_strerror_get(rc));
char buf_i[] = "1234567890123456";
rc = nrf_fstorage_write(
&my_instance, /* The instance to use. */
FSTORAGE_START, /* The address in flash where to store the data. */
buf_i, /* A pointer to the data. */
16, /* Lenght of the data, in bytes. */
NULL /* Optional parameter, backend-dependent. */
);
NRF_LOG_DEBUG("2===> %d %s", rc, nrf_strerror_get(rc));
char buf_o[24];
rc = nrf_fstorage_read(
&my_instance, /* The instance to use. */
FSTORAGE_START, /* The address in flash where to read data from. */
buf_o, /* A buffer to copy the data into. */
16 /* Lenght of the data, in bytes. */
);
buf_o[16] = '\0';
NRF_LOG_DEBUG("3===> %d %s `%s'", rc, nrf_strerror_get(rc), buf_o);
}
I get the following output:
00> <debug> app: 1===> 0 NRF_SUCCESS 00> <debug> app: callback 00> <debug> app: 2===> 0 NRF_SUCCESS 00> <debug> app: 3===> 0 NRF_SUCCESS `'
What am I missing here?
I am using SDK nRF5_SDK_17.0.2_d674dde, with softdevice s132_nrf52_7.2.0_softdevice.hex.
Thanks a lot!