Article count:46 Read by:160721

Account Entry

Talk about the definition of serial_nor--SFDP of the component of xianji hpm_sdk

Latest update time:2023-07-12
    Reads:

I. Overview

In serial flash, such as NOR flash, there are many flash manufacturers and brands. For users, some operations such as sector and block erase instructions, size, etc., it is better to have unified instructions, but in fact, not all manufacturers do so. Therefore, there is an organization called JEDEC that defines a set of standards applicable to serial flash for standardization, which is the JESD216 standard.

The standard has evolved from the original JESD216 to the latest JESD216F.02. The development history and differences in versions are also listed in the protocol document, so I won’t elaborate on them here. You can download the latest JESD216 document to learn more.

In this standard, for the above instruction differences, the standard defines a table, which is the focus of this article, SFDP. This table has many para tables, and each table will describe the parameter instructions related to the flash, such as the sector erase instruction mentioned above. As long as the flash complies with the standard, the sector erase instruction can be read in the para table.

This article takes the Winbond flash and JESD216D version of W25Q64JV as an example.

II. Definition

The JESD216 standard document is 162 pages long, not too many or too few. However, if you need to define so many tables in the source code yourself, it would be a bit difficult to accept in a short period of time.

In the components of the hpm_sdk, there is a serial_nor component folder, which contains a sfdp_def.h header file. From the name, we can know that this is a definition related to sfdp. These definitions and structures can help you quickly understand its JESD216 standard.

The latest standard described in this document is JESD216D. This article will briefly explain this version.

(I) SFDP table reading

In the standard document, the beginning describes the processing of reading SFDP instructions, which can be roughly understood as follows:

1. The SFDP read instruction is 0x5A, and the corresponding macro definition in hpm_sdk is kSerialFlash_ReadSFDP

2. In the SFDP area, the address space you want to read is a three-byte field, that is, a 24-bit address.

3. Before reading data, that is, after sending the address, there must be 8 SPI clocks of dummy waiting. For example, in the case of single-line SPI reading, a byte of dummy is required. In the case of four-line reading, 4 bytes of dummy are required. (Generally, single-line SPI reading is used)

4. The SPI clock should be controlled below 50M for reading.

From the above description, we can use the spi driver of hpm to encapsulate an API interface for reading sfdp.

static hpm_stat_t hpm_spi_nor_read_sfdp(SPI_Type *ptr, uint32_t addr, uint32_t *buffer, uint32_t bytes){    spi_control_config_t control_config = {0};    uint8_t cmd = kSerialFlash_ReadSFDP;    ptr->TRANSFMT |= SPI_TRANSFMT_ADDRLEN_SET(sizeof(uint32_t) - 2);    spi_master_get_default_control_config(&control_config);    control_config.master_config.cmd_enable = true;  /* cmd phase control for master */    control_config.master_config.addr_enable = true; /* address phase control for master */    control_config.master_config.addr_phase_fmt = spi_address_phase_format_single_io_mode;    control_config.common_config.trans_mode = spi_trans_dummy_read;    control_config.common_config.data_phase_fmt = spi_single_io_mode;    control_config.common_config.dummy_cnt = spi_dummy_count_1;    return spi_transfer(ptr, &control_config, &cmd, &addr, NULL, 0, (uint8_t *)buffer, bytes);}


(II) SFDP header structure

In the standard, the address of this structure is 0x000000. The header structure includes two headers: SFDP Header and Parameter Header. There can be multiple Parameter Headers, depending on the NPH parameter of the SFDP Header. This parameter determines the number of Parameter Headers, and the parameter length of the Parameter Header determines the number of parameter tables.

Therefore, if you need to read the parameter table, you must first read the SFDP Header and Parameter Header.


1、SFDP Header

It is defined in the standard document that the structure of SFDP Header is as follows, and sfdp_def in hpm_sdk also implements the definition.

The signature is the identifier, and the ASCII value is "SFDP". This identifier needs to be read before parsing.

param_hdr_num : refers to the number of parameter headers, length + 1.

minor_rev major version: In the above, hpm has defined the version, such as JESD216D is kSfdp_Version_Minor_D.

#define kSfdp_Version_Minor_0 (0U) /* JESD216 */#define kSfdp_Version_Minor_A (5U) /* JESD216A */#define kSfdp_Version_Minor_B (6U) /* JESD216B */#define kSfdp_Version_Minor_C (7U) /* JESD216C */#define kSfdp_Version_Minor_D (8U) /* JESD216D */#define kSfdp_BasicProtocolTableSize_Rev0 (36U)

Where can we see these definitions? We can see the section on version differences, where we can see that, for example, JESD216B is defined as 5

2、Parameter Header

Here, sfdp_def of hpm_sdk is also defined.

There are three parameters that require explanation.

parameter_id : This is the ID value of the prameter table that indicates the specified function supported by the current flash. For example, the ID value of Basic SPI protocol indicates that the flash supports conventional SPI operations under 24-bit addresses, such as whether 1-4-4 qspi reading is supported, the capacity of the flash, the erase sector instruction, etc. This parameter can be used to know the functions supported by the flash. This parameter is divided into MSB LSB and needs to be integrated together.

This parameter can be found in the standard and is also defined in sfdp_def in hpm_sdk.

table_length_in_32bit : The number of parameter tables. Note that this is four-byte aligned. For example, if the value is 2, then 2*4=8 is required, indicating 8 parameter tables.

parameter_table_pointer[3]: indicates the 24-bit address of the parameter table to be read. All parameter tables are read from this address.


3、Parameter table

There are many tables, especially the ID that supports the Basic SPI protocol, which supports 20 words of parameters. Each word has a specified meaning. However, the sfdp of hpm_sdk is also well defined.


3. Verification

For example, take the 3rd parameter table. This table defines a 1-4-4 (cmd line, address and data four lines) read instruction: required dummy clock, required mode dummy clock, instruction value.

Then we read the table value first, and we can see:

Then we open the manual of the flash model we are operating and find the 0xeb instruction, which is the read instruction under QSPI. We can see it from the timing diagram.

This indicates that the parameters read from the sfdp table are exactly the same as the corresponding command parameters in the flas manual.




Latest articles about

 
EEWorld WeChat Subscription

 
EEWorld WeChat Service Number

 
AutoDevelopers

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building,Block B, 18 Zhongguancun Street, Haidian District,Beijing, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号