static void pstorage_callback_handler(pstorage_handle_t * handle, uint8_t op_code, uint32_t result, uint8_t * p_data, uint32_t data_len) { // If we are in BOOTLOADER_SETTINGS_SAVING state and we receive an PSTORAGE_STORE_OP_CODE // response then settings has been saved and update has completed. if ((m_update_status == BOOTLOADER_SETTINGS_SAVING) && (op_code == PSTORAGE_STORE_OP_CODE) && (handle->block_id == BOOTLOADER_SETTINGS_ADDRESS)) // { m_update_status = BOOTLOADER_COMPLETE; /*Clears bootloader_settings critical flag*/ if (*((uint32_t *)BOOT_SETTINGS_PEND_ADDRESS) == BOOT_SETTINGS_PEND_VALUE) { nrf_nvmc_page_erase(BOOT_SETTINGS_PEND_ADDRESS); } } APP_ERROR_CHECK(result); }
int32_t flash_erase_sector(flash_t *obj, uint32_t address) { (void)(obj); /* Return value defaults to error. */ uint32_t result = NRF_ERROR_BUSY; if (NRF_HAL_SD_IS_ENABLED()) { /* Convert address to page number. */ uint32_t page_number = address / NRF_FICR->CODEPAGESIZE; /* Setup stop watch for timeout. */ uint32_t start_us = lp_ticker_read(); uint32_t now_us = start_us; /* Retry if flash is busy until timeout is reached. */ while (((now_us - start_us) < PAGE_ERASE_TIMEOUT_US) && (result == NRF_ERROR_BUSY)) { result = sd_flash_page_erase(page_number); /* Read timeout timer. */ now_us = lp_ticker_read(); } } else { /* Raw API doesn't return error code, assume success. */ nrf_nvmc_page_erase(address); result = NRF_SUCCESS; } /* Convert Nordic error code to mbed HAL error code. */ return (result == NRF_SUCCESS) ? 0 : -1; }
void gzp_erase_pairing_data(void) { // Erase database flash page so that it can be later written to. nrf_nvmc_page_erase((uint32_t)database); }
/** @brief Internal function to initialize DFU BLE transport */ fs_ret_t nrf_dfu_flash_erase(uint32_t const * p_dest, uint32_t num_pages, dfu_flash_callback_t callback) { fs_ret_t ret_val = FS_SUCCESS; NRF_LOG_INFO("Erasing: 0x%08x, num: %d\r\n", (uint32_t)p_dest, num_pages); #ifdef BLE_STACK_SUPPORT_REQD if ((m_flags & FLASH_FLAG_SD_ENABLED) != 0) { // Check if there is a pending error if ((m_flags & FLASH_FLAG_FAILURE_SINCE_LAST) != 0) { NRF_LOG_ERROR("Erase: Failure since last\r\n"); return FS_ERR_FAILURE_SINCE_LAST; } m_flags |= FLASH_FLAG_OPER; ret_val = fs_erase(&fs_dfu_config, p_dest, num_pages, (void*)callback); if (ret_val != FS_SUCCESS) { NRF_LOG_ERROR("Erase failed: %d\r\n", ret_val); m_flags &= ~FLASH_FLAG_OPER; return ret_val; } // Set the flag to indicate ongoing operation m_flags |= FLASH_FLAG_OPER; } else #endif { #ifndef NRF51 // Softdevice is not present or activated. Run the NVMC instead if (((uint32_t)p_dest & (CODE_PAGE_SIZE-1)) != 0) { NRF_LOG_ERROR("Invalid address\r\n"); return FS_ERR_UNALIGNED_ADDR; } #endif uint16_t first_page = ((uint32_t)p_dest / CODE_PAGE_SIZE); do { nrf_nvmc_page_erase((uint32_t)p_dest); p_dest += CODE_PAGE_SIZE/sizeof(uint32_t); } while(--num_pages > 0); if (callback) { #if (__LINT__ != 1) fs_evt_t evt = { .id = FS_EVT_ERASE, .p_context = (void*)callback, .erase = { .first_page = first_page, .last_page = ((uint32_t)p_dest / CODE_PAGE_SIZE) } }; callback(&evt, FS_SUCCESS); #else (void)first_page; #endif } } return ret_val; }
void nrf_utils_erase_flash_page(uint32_t addr) { nrf_nvmc_page_erase(addr); }
otError nrf5FlashPageErase(uint32_t aAddress) { nrf_nvmc_page_erase(aAddress); return OT_ERROR_NONE; }