Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Setting write latch of MT25Q SPI flash?

Any idea why I need to send write enable twice, without reading the status in between, to get the write latch set?

#define EXTFLASH_CMD_WRITE_ENABLE       0x06
#define EXTFLASH_CMD_WRITE_DISABLE      0x04
#define EXTFLASH_CMD_READ_STATUS        0x05
#define EXTFLASH_CMD_READ_FSTATUS       0x70

uint8_t extflash_cmd_read_status[] = {EXTFLASH_CMD_READ_STATUS};
uint8_t extflash_cmd_read_fstatus[] = {EXTFLASH_CMD_READ_FSTATUS};
uint8_t extflash_cmd_write_enable[] = {EXTFLASH_CMD_WRITE_ENABLE};

static nrf_spi_mngr_transfer_t const extflash_read_status_xfer[] = {
    NRF_SPI_MNGR_TRANSFER(extflash_cmd_read_status, sizeof(extflash_cmd_read_status), &(extflash_stat_buff[0]), 2),
    NRF_SPI_MNGR_TRANSFER(extflash_cmd_read_fstatus, sizeof(extflash_cmd_read_fstatus), &(extflash_stat_buff[2]), 2)
};

static nrf_spi_mngr_transfer_t const extflash_cmd_write_enable_xfer[] = {
    NRF_SPI_MNGR_TRANSFER(extflash_cmd_write_enable, sizeof(extflash_cmd_write_enable), &(extflash_stat_buff[4]), 1),
};

static nrf_spi_mngr_transaction_t extflash_trans_status =
{
    .begin_callback      = NULL,
    .end_callback        = extflash_conf_callback,
    .p_user_data         = (void *)EXTFLASH_TRANSACT_STATUS,
    .p_transfers         = extflash_read_status_xfer,
    .number_of_transfers = 2,
    .p_required_spi_cfg  = &spi_extflash_config
};

static nrf_spi_mngr_transaction_t extflash_trans_write_enable =
{
    .begin_callback      = NULL,
    .end_callback        = extflash_conf_callback,
    .p_user_data         = (void *)EXTFLASH_TRANSACT_WRITE_ENABLE,
    .p_transfers         = extflash_cmd_write_enable_xfer,
    .number_of_transfers = 1,
    .p_required_spi_cfg  = &spi_extflash_config
};

void extflash_conf_callback(ret_code_t result, void *p_user_data)
{
    extflash_transact_done = (uint8_t)(uint32_t)p_user_data;
    if (extflash_transact_done == HYP_EXTFLASH_TRANSACT_STATUS)
    {
        extflash_last_status = extflash_stat_buff[1];
        extflash_last_fstatus = extflash_stat_buff[3];
    }
}

static void extflash_read_status_blocking(void)
{
    uint32_t err_code;
    extflash_transact_done = HYP_EXTFLASH_TRANSACT_NONE;
    err_code = nrf_spi_mngr_schedule(&extflash_trans_status);
    APP_ERROR_CHECK(err_code);
    while (extflash_transact_done != HYP_EXTFLASH_TRANSACT_STATUS);
}

int main()
{
    ...
    err = nrf_spi_mngr_schedule(&extflash_trans_write_enable);
#if 0
    while (extflash_transact_done != EXTFLASH_TRANSACT_WRITE_ENABLE); /* wait */
//  read_status_blocking();
    err = nrf_spi_mngr_schedule(&extflash_trans_write_enable);
#endif
    while (extflash_transact_done != EXTFLASH_TRANSACT_WRITE_ENABLE); /* wait */
    extflash_read_status_blocking();
    extflash_read_status_blocking();
...
}

It doesn't work this way, but if I change "#if 0" to "#if 1", it works.

And if I uncomment the "//  read_status_blocking();", it stops working.

Parents Reply Children
No Data
Related