Hi.
I modified the fstorage example to create the project.
I split Flash into three areas as shown below.
*Flash Area(0x26000 ~ 0x2ffff) : Bootloader
*Flash Area(0x30000 ~ 0x4DFFF) : Application 1 (written 34858 byte)
*Flash Area(0x4E000 ~ 0x6BFFF) : Application 2 (Empty)
I have written code to copy the App_1 area to the App_2 area for testing, but it doesn't work.
nrf_fstorage_write return 0x10(NRF_ERROR_INVALID_ADDR).
static void start_Update_Firmware(void) {
flash_Erase(fData.tFirmPage);
for (uint8_t wSEQ = 0; wSEQ < fData.tFirmPage; wSEQ++) {
flash_Read(wSEQ, rFData);
flash_Write(wSEQ, rFData, sizeof(rFData));
}
}
/******************************************************************************/
/* Flash Event Handler Function */
/******************************************************************************/
static void fstorage_evt_handler(nrf_fstorage_evt_t *p_evt) {
switch (p_evt->id) {
case NRF_FSTORAGE_EVT_READ_RESULT:
//Read Success
isRead = true;
break;
case NRF_FSTORAGE_EVT_WRITE_RESULT:
//Write Success
printf("Flash\t: Write Result : %08x\r\n", p_evt->result);
isWrite = true;
break;
case NRF_FSTORAGE_EVT_ERASE_RESULT:
//Erase Success
printf("Flash\t: Erase Result : %08x\r\n", p_evt->result);
isErase = true;
break;
default:
printf("Flash\t: ???? Result : %08x\r\n", p_evt->result);
break;
}
}
NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
/* Set a handler for fstorage events. */
.evt_handler = fstorage_evt_handler,
.start_addr = 0x30000,
.end_addr = 0x6BFFF,
};
/******************************************************************************/
/* Flash Init Function */
/******************************************************************************/
void flash_Init(void) {
ret_code_t rc;
#if Bootloader
p_fs_api = &nrf_fstorage_sd;
#endif
rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
APP_ERROR_CHECK(rc);
printf("Flash\t: Init Done\r\n");
}
/******************************************************************************/
/* Flash Write Function */
/******************************************************************************/
uint8_t flash_Write(uint8_t seq, uint8_t *pData, uint32_t dLen) {
uint8_t rc;
isWrite = false;
#if Bootloader
//uint32_t wAddr = 0x30000 + (0x1000 * seq);
uint32_t wAddr = 0x4E000 + (0x800 * seq); //Test Code
#else
uint32_t wAddr = 0x4E000 + (0x800 * seq);
#endif
rc = nrf_fstorage_write(&fstorage, wAddr, pData, dLen, NULL);
while (nrf_fstorage_is_busy(&fstorage)) {
__WFE();
}
printf("Flash\t: Write Result : %08x %08x %08x\r\n", rc, wAddr, dLen);
APP_ERROR_CHECK(rc);
return rc;
}
/******************************************************************************/
/* Flash Read Function */
/******************************************************************************/
uint8_t flash_Read(uint8_t seq, uint8_t *pData) {
uint8_t rc;
isRead = false;
//uint32_t rAddr = 0x4E000 + (0x1000 * seq); //Read 4KB
uint32_t rAddr = 0x30000 + (0x800 * seq); //Read 4KB //TestCode
rc = nrf_fstorage_read(&fstorage, rAddr, pData, 0x800); //Read 4KB
printf("Flash\t: Read Result : %08x\r\n", rc);
while (nrf_fstorage_is_busy(&fstorage)) {
__WFE();
}
APP_ERROR_CHECK(rc);
return rc;
}
/******************************************************************************/
/* Flash Erase Function */
/******************************************************************************/
uint8_t flash_Erase(uint8_t tPage) {
uint8_t rc;
isErase = false;
#if Bootloader
//rc = nrf_fstorage_erase(&fstorage, 0x30000, tPage, NULL);
rc = nrf_fstorage_erase(&fstorage, 0x4E000, tPage, NULL);
#else
//rc = nrf_fstorage_erase(&fstorage, 0x30000, tPage, NULL);
rc = nrf_fstorage_erase(&fstorage, 0x4E000, tPage, NULL);
#endif
while (!isErase) {
__WFE();
}
return rc;
}
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Use SDKs: 15.2
IDE : SEGGER Embedded Studio for ARM 4.12
Hardware : nRF52832(BMD-300)