I am modifying the bootloader. I am not using DFU or any of that, but rather copying a FW image over from external flash through SPI. The area of my code that gives me problems is this:
pstorage_handle_t m_storage_handle_app;
pstorage_module_param_t storage_module_param = {.cb = pstorage_callback_handler};
storage_module_param.block_size = 0x100;
storage_module_param.block_count = fw_len / 256;
pstorage_init();
err_code = pstorage_raw_register(&storage_module_param, &m_storage_handle_app);
if (err_code != NRF_SUCCESS)
{
simple_uart_putstring("Something went very wrong when registering for pstorage \n");
}
APP_ERROR_CHECK(err_code);
//now clear the nrf51 flash
err_code = pstorage_raw_clear(&m_storage_handle_app, fw_len);
When I run this, I always get error code 4 thrown to app_error_handler when it tries to call pstorage_raw_clear. The function does call and return, but then I always end up right in the app_error_handler function and the error_code is always 4.
I am using serial debug, so I can see that values are getting filled in as I want. The fw_length is correct, and the block_size and block_count are correct.
I am using SDK7.2 with SD7.1. This is the bootloader, so I am trying to write the app to 0x16000. I have disabled all calls to the normal bootloader, so pstorage_init or pstorage_raw_register should not be getting called twice.
Any help is appreciated. Thanks