I've followed this for assistance, but I'm stuck: https://devzone.nordicsemi.com/question/17846/nonvolatile-memory-access/
I can read from flash, but I can't write to flash. Let me layout what I do first:
S130 SDK 7.2
In main(...):
if(NRF_SUCCESS != pstorage_init())
{
APP_ASSERT (false);
//nrf_gpio_pin_set(PSTORAGE_ERROR_LED_PIN_NO);
}
param.block_size = 16; //Select block size of 16 bytes
param.block_count = 10; //Select 10 blocks, total of 160 bytes
param.cb = flash_handler; //Set the pstorage callback handler
if (NRF_SUCCESS != pstorage_register(¶m, &handle))
{
APP_ASSERT (false);
//nrf_gpio_pin_set(PSTORAGE_ERROR_LED_PIN_NO);
}
When I set a flag for write event, in my do loop:
if(rtc1_timeout())
{
gs_advertising_is_running = false;
gs_scanning_is_running = false;
if(write_flag == 1)
{
//just in case, kill advertise and scan
sd_ble_gap_scan_stop();
sd_ble_gap_adv_stop();
//writing halts CPU
write_flash();
write_flag = 0;
}
}
My actual write event (simplistic):
static void write_flash(void)
{
uint32_t volatile error = 0;
error = pstorage_block_identifier_get(&handle, 0, &block_0_handle);
error = pstorage_clear(&block_0_handle, 16); //Clear 16 bytes
error = pstorage_store(&block_0_handle, source_data_0, 16, 0);
pstorage_wait_handle = block_0_handle.block_id; //Specify which pstorage handle to wait for
pstorage_wait_flag = 1;
while(pstorage_wait_flag){power_manage();} //Sleep until store operation is finished.
}
Where am I going wrong? My asserts don't catch anything. I can read flash, but after trying to write it gets stuck in a loop. It never enters into my "flash_handler" but my read flash function does.
Any help would be appreciated.