I'm using SDK 15.3, nRF52840, with the ext-flash read/write QSPI demo project.
block_dev_qspi_init(), in nrf_block_dev_qspi.c, does not uninitialize the QSPI (by calling nrf_drv_qspi_uninit), if it fails after calling nrf_drv_qspi_init(), in every place calling return ret;
ret = nrf_drv_qspi_init(p_qspi_cfg, qspi_handler, (void *)p_blk_dev);
if (ret != NRF_SUCCESS)
{
NRF_LOG_INST_ERROR(p_qspi_dev->p_log, "QSPI init error: %"PRIu32"", ret);
return ret;
}
nrf_qspi_cinstr_conf_t cinstr_cfg = {
.opcode = QSPI_STD_CMD_RSTEN,
.length = NRF_QSPI_CINSTR_LEN_1B,
.io2_level = true,
.io3_level = true,
.wipwait = true,
.wren = true
};
/* Send reset enable */
ret = nrf_drv_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
if (ret != NRF_SUCCESS)
{
NRF_LOG_INST_ERROR(p_qspi_dev->p_log, "QSPI reset enable command error: %"PRIu32"", ret);
return ret;
}
/* Send reset command */
cinstr_cfg.opcode = QSPI_STD_CMD_RST;
ret = nrf_drv_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
if (ret != NRF_SUCCESS)
{
NRF_LOG_INST_ERROR(p_qspi_dev->p_log, "QSPI reset command error: %"PRIu32"", ret);
return ret;
}
/* Get 3 byte identification value */
uint8_t rdid_buf[3] = {0, 0, 0};
cinstr_cfg.opcode = QSPI_STD_CMD_READ_ID;
cinstr_cfg.length = NRF_QSPI_CINSTR_LEN_4B;
ret = nrf_drv_qspi_cinstr_xfer(&cinstr_cfg, NULL, rdid_buf);
if (ret != NRF_SUCCESS)
{
NRF_LOG_INST_ERROR(p_qspi_dev->p_log, "QSPI get 3 byte id error: %"PRIu32"", ret);
return ret;
}
nrf_serial_flash_params_t const * serial_flash_id = nrf_serial_flash_params_get(rdid_buf);
if (!serial_flash_id)
{
NRF_LOG_INST_ERROR(p_qspi_dev->p_log, "QSPI FLASH not supported");
return NRF_ERROR_NOT_SUPPORTED;
}
if (serial_flash_id->erase_size != NRF_BLOCK_DEV_QSPI_ERASE_UNIT_SIZE)
{
NRF_LOG_INST_ERROR(p_qspi_dev->p_log, "QSPI FLASH erase unit size not supported");
return NRF_ERROR_NOT_SUPPORTED;
}
/* Calculate block device geometry.... */
uint32_t blk_size = p_qspi_dev->qspi_bdev_config.block_size;
uint32_t blk_count = serial_flash_id->size / p_qspi_dev->qspi_bdev_config.block_size;
if (!blk_count || (blk_count % BD_BLOCKS_PER_ERASEUNIT(blk_size)))
{
NRF_LOG_INST_ERROR(p_qspi_dev->p_log, "QSPI FLASH block size not supported");
return NRF_ERROR_NOT_SUPPORTED;
}
It can solved by calling uninit() of the block device as a whole, but I feel that the block_dev_qspi_init() should be more tidy and cleanup after itself (like every function should).