Nrf52840 use SPI Flash by SPIFBlockDevice fail -4002

Hi All

I’m coding on EByte_E73 module of nrf52840 core with mbed os, It’s work fine with MX25L12833FM2I external spi flash by SPIFBlockDevice class.

But I want to use this flash as secondary_bd for DFU function by mcuboot

I can make sure the bootloader is work, because it can load the first version with mcuboot bootloader. All other function is OK. But when I test DFU , I need use the external flash as secondary_bd to save update firmware. but SPIFBlockDevice can’t work fine now, the init function return -4002.

I searched on the Internet, and there was no useful information to help me. So I narrowed down my investigation. @Official Can you tell why the external flash init fail ? Anyone meet same situation ? thanks

This is my custom_targets.json:

{
    "EBYTE_E73": {
        "inherits": [
            "MCU_NRF52840"
        ],
        "detect_code": [
            "1102"
        ],
        "components_add": ["SPIF", "FLASHIAP", "SD"],
        "features_remove": ["CRYPTOCELL310"],
        "macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],
        "config": {
            "enable-objects-extensions": {
                "help": "Enable inclusion of objects_extensions.h",
                "value": false
            },
            "lf_clock_xtal_accuracy": {
                "value": "NRF_CLOCK_LF_XTAL_ACCURACY_250_PPM",
                "macro_name": "MBED_CONF_NORDIC_LF_CLOCK_XTAL_ACCURACY"
            }
        },
        "overrides": {
            "lf_clock_src": "NRF_LF_SRC_RC",
            "lf_clock_rc_calib_timer_interval": 16,
            "lf_clock_rc_calib_mode_config": 0
        },
        "supported_application_profiles": [
            "full", "bare-metal"
        ] 
    }
}

This is my mbed_app.json:

{
    "target_overrides": {
        "*": {
            "target.bootloader_img": null,
            "target.printf_lib": "std",
            "target.components_add": ["SD"]
        },
        "EBYTE_E73": {
            "target.mbed_app_start": "0x21000",
            "target.mbed_app_size": "0xBE000"
        }
    }
}
/** Enum spif standard error codes
 *
 *  @enum spif_bd_error
 */
enum spif_bd_error {
    SPIF_BD_ERROR_OK                    = 0,     /*!< no error */
    SPIF_BD_ERROR_DEVICE_ERROR          = mbed::BD_ERROR_DEVICE_ERROR, /*!< device specific error -4001 */
    SPIF_BD_ERROR_PARSING_FAILED        = -4002, /* SFDP Parsing failed */
    SPIF_BD_ERROR_READY_FAILED          = -4003, /* Wait for Memory Ready failed */
    SPIF_BD_ERROR_WREN_FAILED           = -4004, /* Write Enable Failed */
    SPIF_BD_ERROR_INVALID_ERASE_PARAMS  = -4005, /* Erase command not on sector aligned addresses or exceeds device size */
};

SPIF_BD_ERROR_PARSING_FAILED - unexpected format or values in one of the SFDP tables

Looking at SPIFBlockDevice.cpp there appears to be 3 possible related errors:

    /**************************** Parse SFDP headers and tables ***********************************/
    {
        _sfdp_info.bptbl.addr = 0x0;
        _sfdp_info.bptbl.size = 0;
        _sfdp_info.smptbl.addr = 0x0;
        _sfdp_info.smptbl.size = 0;

        if (sfdp_parse_headers(callback(this, &SPIFBlockDevice::_spi_send_read_sfdp_command), _sfdp_info) < 0) {
            tr_error("init - Parse SFDP Headers Failed");
            status = SPIF_BD_ERROR_PARSING_FAILED;
            goto exit_point;
        }

        if (_sfdp_parse_basic_param_table(callback(this, &SPIFBlockDevice::_spi_send_read_sfdp_command), _sfdp_info) < 0) {
            tr_error("init - Parse Basic Param Table Failed");
            status = SPIF_BD_ERROR_PARSING_FAILED;
            goto exit_point;
        }

        if (sfdp_parse_sector_map_table(callback(this, &SPIFBlockDevice::_spi_send_read_sfdp_command), _sfdp_info) < 0) {
            tr_error("init - Parse Sector Map Table Failed");
            status = SPIF_BD_ERROR_PARSING_FAILED;
            goto exit_point;
        }
    }

Yes , I only dig here. :joy: But I don’t know how to solve it.

Yes, I don’t know how to solve either :upside_down_face:
But two minds better than one.

I’m looking at the mbed-mcuboot-demo on GitHub. The mbed_app.json file has more overrides listed than shown in your mbed_app.json file. Are they not required… e.g. scratch-address and scratch-size is needed for secondary boot sector.

        "NRF52840_DK": {
            "target.features_remove": ["CRYPTOCELL310"],
            "target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],
            "mcuboot.primary-slot-address": "0x20000",
            "mcuboot.slot-size": "0xC0000",
            "mcuboot.scratch-address": "0xE0000",
            "mcuboot.scratch-size": "0x20000",
            "mcuboot.max-img-sectors": "0x180",
            "mcuboot.read-granularity": 4,
            "qspif.QSPI_MIN_PROG_SIZE": 4
        },

Did you refer to the mcuboot-blinky example for guidance?

In fact, I successfully tested with nrf52840-dk a long time ago, so I set all the configurations you mentioned. This time, the module with nrf52840 as the core is used, and the same external flash is also used. But there will be problems

It sounds like there is a problem with the MX25L12833FM2I external flash. What options have you tried. Looking at spec sheet:

  1. Supports SPI Mode 0 and Mode 3
  2. Supports QSPI
  3. Supports clock freq up to 133MHz
  4. Equal Sectors with 4K byte each, or Equal Blocks with 32K byte each or Equal Blocks with 64K byte each
  5. 256byte page buffer
  6. Configured as 16,777,216 x 8 internally