How to get UID in external flash via QSPI?

Hi,

I'm using QSPI to control an external flash (w25q128).

Is there any API that can help me get the UID of the external flash?

For w25q128, there is a command for read the UID.

https://www.pjrc.com/teensy/W25Q128FV.pdf

SDK: NCS 2.3.0

Thanks.

Andy

Parents
  • Hi,

    Is there any API that can help me get the UID of the external flash?

    The flash driver has API functions to read SFDP and JEDEC ID, sfdp_read()/read_jedec_id(), but there is no API function to read the this "UID".

  • Since different manufacturers read UIDs in different ways, it is reasonable not to have this API.

    That is to say, there is no way to read UID through QSPI?

    Or is there another way?
    For example, use QSPI API or dynamically switch SPI QSPI ...

  • Hi,

    Andy Chang said:
    That is to say, there is no way to read UID through QSPI?

    Even if the flash API does not have this API function, it should be possible to use the QSPI driver to read it.

    Here is the function for how the JEDEC id is read

    https://github.com/nrfconnect/sdk-zephyr/blob/v3.2.99-ncs2/drivers/flash/nrf_qspi_nor.c#L776

    So you can create a qspi_read_uid() similar to that function, but instead of opcode SPI_NOR_CMD_RDID (0x9F) , you use 0x4B instead (Read Unique ID Number)

  • Thanks for your information.
    I implemented qspi_read_uid.
    And successfully read the UID of the external flash.

    Here is what I made:

    int qspi_read_uid(const struct device *dev,
                      uint8_t opcode, 
                      uint8_t *tx, uint8_t tx_len,
                      uint8_t *id, uint8_t id_len )
    {
        nrf_qspi_cinstr_conf_t cinstr_cfg = {
            .opcode = opcode,
            .length = NRF_QSPI_CINSTR_LEN_1B,
            .io2_level = true,
            .io3_level = true,
        };
    
        int ret = qspi_device_init(dev);
        nrfx_err_t res = NRFX_SUCCESS;
    
        if (ret != 0) {
            LOG_DBG("qspi_device_init: %d", ret);
            qspi_device_uninit(dev);
            return ret;
        }
    
        qspi_lock(dev);
        res = nrfx_qspi_lfm_start(&cinstr_cfg);
        if (res != NRFX_SUCCESS) {
            LOG_DBG("lfm_start: %x", res);
            goto out;
        }
    
        res = nrfx_qspi_lfm_xfer(tx, NULL, tx_len, false);
        if (res != NRFX_SUCCESS) {
            LOG_DBG("lfm_xfer addr: %x", res);
            goto out;
        }
    
        res = nrfx_qspi_lfm_xfer(NULL, id, id_len, true);
        if (res != NRFX_SUCCESS) {
            LOG_DBG("lfm_xfer read: %x", res);
            goto out;
        }
    
    out:
        qspi_unlock(dev);
        qspi_device_uninit(dev);
        return qspi_get_zephyr_ret_code(res);
    }
    
    

Reply
  • Thanks for your information.
    I implemented qspi_read_uid.
    And successfully read the UID of the external flash.

    Here is what I made:

    int qspi_read_uid(const struct device *dev,
                      uint8_t opcode, 
                      uint8_t *tx, uint8_t tx_len,
                      uint8_t *id, uint8_t id_len )
    {
        nrf_qspi_cinstr_conf_t cinstr_cfg = {
            .opcode = opcode,
            .length = NRF_QSPI_CINSTR_LEN_1B,
            .io2_level = true,
            .io3_level = true,
        };
    
        int ret = qspi_device_init(dev);
        nrfx_err_t res = NRFX_SUCCESS;
    
        if (ret != 0) {
            LOG_DBG("qspi_device_init: %d", ret);
            qspi_device_uninit(dev);
            return ret;
        }
    
        qspi_lock(dev);
        res = nrfx_qspi_lfm_start(&cinstr_cfg);
        if (res != NRFX_SUCCESS) {
            LOG_DBG("lfm_start: %x", res);
            goto out;
        }
    
        res = nrfx_qspi_lfm_xfer(tx, NULL, tx_len, false);
        if (res != NRFX_SUCCESS) {
            LOG_DBG("lfm_xfer addr: %x", res);
            goto out;
        }
    
        res = nrfx_qspi_lfm_xfer(NULL, id, id_len, true);
        if (res != NRFX_SUCCESS) {
            LOG_DBG("lfm_xfer read: %x", res);
            goto out;
        }
    
    out:
        qspi_unlock(dev);
        qspi_device_uninit(dev);
        return qspi_get_zephyr_ret_code(res);
    }
    
    

Children
Related