External Flash W25Q64 with USBD_MSC example on NRF52840

Hi All,

        I have an external flash W25Q64 on which I have to mount a file system. I am using USBD_MSC example of NRF52840. My main goal is to create a file inside the flash memory chip. And when USB is plugged into the device it should be seen as a drive on laptop/desktop and I should be able to access the file which was created in the flash chip.I have made the connections on the NRF52840 using the pin configurations below:-


#define SDC_SCK_PIN     (25) 
#define SDC_MOSI_PIN   (23) 
#define SDC_MISO_PIN   (24) 
#define SDC_CS_PIN       (15) 

I have also configured the details in nrf_serial_flash_params.c file. 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static const nrf_serial_flash_params_t m_sflash_params[] = {
{
.read_id = { 0xEF,0x40,0x17 },
.capabilities = 0x00,
.size = 8 * 1024 * 1024,
.erase_size = 2 * 1024,
.program_size = 256,
}
};
nrf_serial_flash_params_t const * nrf_serial_flash_params_get(const uint8_t * p_read_id)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(m_sflash_params); ++i)
{
if (memcmp(m_sflash_params[i].read_id, p_read_id, sizeof(m_sflash_params[i].read_id)) == 0)
{
return &m_sflash_params[i];
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

When I run the example , i get the following error:-

<info> app: Initializing disk 0 (QSPI)...

 <error> app: Disk initialization failed.

1) Will this example run for W25Q64 IC??

2) This example also includes FATfs files. Will it automatically create a file system on the external SPI W25Q64 flash memory??

3) Why am I getting "Disk initialization failed." error?

4) Inside sdk_config.h do I also need to enable pin configurations for Qspi??

5) How to test this application? Currently I am using NRF52840 DK and then connecting external spi flash to it. But for USB detection how will it work?

I have attached few files here to check for the configurations

https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-07b22aa9f6fe492cbaf5dd082cf33f82/usb_5F00_msc.c

04162.sdk_config.h

5287.W25Q64BV.PDF

Please help me to solve this issue. I need to solve this issue on an urgent basis. Your help will be appreciated. I have also attached W25Q64 datasheet for your reference.

Thanks & Regards,

Snehal

Parents
  • Hi,

    Take look at this case, where the configuration needed for this flash chip is discussed:
    RE: QSPI and w25q64fv flash

  • Hi Sigurd,

                  The thread you mentioned shows QSPI with flash directly. I am struggling for USB MSC code. Can you please help me with USB MSC code?

    Thanks & Regards,

    Snehal

  • Just have to look at how e.g. sd-card or QSPI backend does it, and replicate that using the SPI driver instead.

  • Hi Sigurd,

    I tried to change 

    NRF_BLOCK_DEV_QSPI_DEFINE(
    m_block_dev_qspi,
    NRF_BLOCK_DEV_QSPI_CONFIG(
    512,
    NRF_BLOCK_DEV_QSPI_FLAG_CACHE_WRITEBACK,
    NRF_DRV_QSPI_DEFAULT_CONFIG
    ),
    NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "QSPI", "1.00")
    );

    to 

    NRF_BLOCK_DEV_SPI_DEFINE(
    m_block_dev_spi,
    NRF_BLOCK_DEV_SPI_CONFIG(
    512,
    NRF_BLOCK_DEV_SPI_FLAG_CACHE_WRITEBACK,
    NRF_DRV_SPI_DEFAULT_CONFIG
    ),
    NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "SPI", "1.00")
    );

    but I am getting compiling errors.

    probably because there is no file for SPI under sdk\components\libraries\block_dev. 

    How to solve?

  • Hi,

    sne_333 said:
    probably because there is no file for SPI under sdk\components\libraries\block_dev. 

    block_dev library have support for QSPI and sd-cards. you would need to implement support for SPI yourself. 

  • But on the same SPI lines I am having MAX3421e IC also. It might create a conflict. I am very tensed now.

    I saw the example of sd card, it uses SPI drivers internally. So I modified my file this way. 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include <stdint.h>
    #include <stdbool.h>
    #include <stddef.h>
    #include <inttypes.h>
    #include <stdlib.h>
    #include "nrf.h"
    #include "nrf_block_dev.h"
    #include "nrf_block_dev_ram.h"
    #include "nrf_block_dev_empty.h"
    #include "nrf_block_dev_qspi.h"
    #include "nrf_block_dev_sdc.h"
    #include "nrf_drv_usbd.h"
    #include "nrf_drv_clock.h"
    #include "nrf_gpio.h"
    #include "nrf_atomic.h"
    #include "nrf_drv_power.h"
    #include "ff.h"
    #include "diskio_blkdev.h"
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Will this work?

    Thanks & Regards,

    Snehal.

  • I will convert the Qspi to SPI but can you please guide me on steps and which files to create/edit to do so? I don't know how to change qspi to spi.. I need your help.

    Thanks.

Reply
  • I will convert the Qspi to SPI but can you please guide me on steps and which files to create/edit to do so? I don't know how to change qspi to spi.. I need your help.

    Thanks.

Children
  • Sigurd. Please reply.

  • You could e.g. start by replacing QSPI read/write operations with SPI read/write operations.  We don't have any guides for this. You just have to use the other implementations as a reference.

  • Hi Sigurd, Thanks for the suggestion. I will try converting it. 

    One the same SPI lines I have one more chip MAX3421e. SS pin is different for both flash chip and MAX3421. Will it conflict if I implement block drivers for flash chip SPI?? 

    Just don't want to get in any trouble later. So confirming from you.

    P0.22 SPI_SS
    P0.23 SPI_MOSI
    P0.24 SPI_MISO
    P0.25 SPI_CLK
    P0.26 SPI_WP
    P0.27

    SPI_HOLD

    P0.15 SPI_SS_FLSH
    P0.22 SPI_SS_MAX3421

    Thanks & Regards,

    Snehal.

  • Hi,

    As long as you use SS, and have different SS-line for each SPI device, it should be okay.

  • Okay, Thank you. 

    According to your suggestion I have tried converting qspi to spi drivers.I am not sure if my conversion is right. I have uploaded 2 files here. Can you please check if the conversion is okay?? 

    Also one thing is left to convert in the file which is regarding "nrf_qspi_cinstr_conf_t" which is custom configuration structure for QSPI and "nrf_drv_qspi_cinstr_xfer" . How do I convert this part for SPI?? 

     

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    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);
    /* Send reset command */
    cinstr_cfg.opcode = QSPI_STD_CMD_RST;
    ret = nrf_drv_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
    ]
    /* Get 3 byte identification value */
    uint8_t rdid_buf[3] = {0, 0, 0};
    cinstr_cfg.opcode = QSPI_STD_CMD_READ_ID;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    /**
    * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
    *
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without modification,
    * are permitted provided that the following conditions are met:
    *
    * 1. Redistributions of source code must retain the above copyright notice, this
    * list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form, except as embedded into a Nordic
    * Semiconductor ASA integrated circuit in a product or a software update for
    * such product, must reproduce the above copyright notice, this list of
    * conditions and the following disclaimer in the documentation and/or other
    * materials provided with the distribution.
    *
    * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
    * contributors may be used to endorse or promote products derived from this
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    nrf_block_dev_spi.h

    I will be glad if you please verify my changes. Waiting for your reply.

    Thanks & Regards,

    Snehal.