6621D/F获取flash uid方法

yangzh · 81次点击 · 2个月前

我们使用6621D/F获取flash uid和6621CX/P有些不一样,因接口函数库里没有包含,需要加入到源码中,现介绍方法如下

1)复制sf用到的宏定义

#define SPI_CMD_WREN        0x06u /* Write enable */
#define SPI_CMD_WRDI        0x04u /* Write disable */
#define SPI_CMD_RDSR        0x05u /* Read status register */
#define SPI_CMD_RDSR2       0x35u /* Read status register (high byte) */
#define SPI_CMD_WRSR        0x01u /* Write status register */
#define SPI_CMD_READ        0x03u /* Read data bytes (low frequency) */
#define SPI_CMD_FAST_READ   0x0Bu /* Read data bytes (high frequency) */
#define SPI_CMD_DUAL_READ   0x3Bu /* Dual output fast read: HS6620 doesn't support 0xBB */
#define SPI_CMD_QUAD_READ   0x6Bu /* Quad output fast read: PN25F04C doesn't support 0x6B, but HS6620 doesn't support 0xEB */
#define SPI_CMD_PP          0x02u /* Page program (up to page in 256 bytes) */
#define SPI_CMD_RDID        0x9fu /* Read JEDEC ID */
#define SPI_CMD_RDUID       0x4Bu /* Read UID */

#define SPI_CMD_SE          0x20u /* Sector erase (usually 4KiB) */
#define SPI_CMD_BE_32K      0x52u /* Erase 32KiB block */
#define SPI_CMD_BE_64K      0xD8u /* Erase 64KiB block */
#define SPI_CMD_CE          0x60u /* Erase whole flash chip, or 0xC7 */

#define SPI_CMD_ENDP        0xB9u /* Enter Deep Power-Down */
#define SPI_CMD_EXDP        0xABu /* Exit Deep Power-Down */
#define SPI_CMD_RDSEC       0x48u /* Read Security Registers */
#define SPI_CMD_ERSEC       0x44u /* Erase Security Registers */
#define SPI_CMD_PPSEC       0x42u /* Program Security Registers */

#define SPI_CMD_EQPI        0x38u /* Enable Quad Peripheral Interface: HS6620 doesn't support */

#define SR_WIP              0x01  /* Write in progress */
#define SR_WEL              0x02  /* Write enable latch */
#define SR_BP0              0x04  /* Block protect 0 */
#define SR_BP1              0x08  /* Block protect 1 */
#define SR_BP2              0x10  /* Block protect 2 */
#define SR_SRP              0x80  /* SR write protect */
#define SR_QE               0x0200 /* Quad enable */

#define SF_READ_FAST_DMA_CLOCK_FREQ_HZ_THRESHOLD    20000000 // 20MHz

#define SF_WORKAROUND_PUYA_FLASH_OVERWRITE_ISSUE
#define SF_NOT_MODIFY_SF0CS0_LAST_SECTOR

#define SF_RW_PARAM_CMD_DECLARE(name, cmd, data, len) \
    sfb_rw_params_t name = {{{((cmd)<<24), 0}}, 8, (data), (len)}
#define SF_RW_PARAM_CMD_ADDR_DECLARE(name, cmd, addr, data, len) \
    sfb_rw_params_t name = {{{((cmd)<<24)|(addr), 0}}, 32, (data), (len)}
#define SF_RW_PARAM_CMD_ADDR_40BITS_DECLARE(name, cmd, addr, data, len) \
    sfb_rw_params_t name = {{{((cmd)<<24)|(addr), 0}}, 40, (data), (len)}

#define IFLASH_INFO (&sf_env.info[0][0])

#define SF_WRITE_BEGIN(sf, cs)   do{uint32_t irq_save = sf_write_begin(sf, cs)
#define SF_WRITE_END(sf, cs)     sf_write_end(sf, cs, irq_save);} while(0)

/**
 * @brief read uid
 *
 * @param[in] sf  sf object
 * @param[in] cs  cs (0 ~ SFB_CS_NUM-1)
 * @param[in] data  read uid buffer
 * @param[in] length  length
 **/
void sf_read_uid_ex(HS_SF_Type *sf, uint32_t cs, void *data, uint32_t length)
{
    SF_RW_PARAM_CMD_ADDR_40BITS_DECLARE(param, SPI_CMD_RDUID, 0, data, length);
    sfb_read_nodma(sf, cs, &param);
}

2)定义变量,打印输出

uint32_t id = 0;
uint32_t id1 = 0;

uint32_t id2[] = {0};

uint8_t m_chip_uuid[8];


3)main.c函数中打印输出

        sf_read_id(HS_SF, 0);
        sf_read_uid_ex(HS_SF, 0, id2, 16);      
        id = sf_read_id(HS_SF, 0);
        sf_read_uid_ex(HS_SF, 0, id2, 16);

        log_debug("id = 0x%x\r\n", id);

        log_debug_array_ex("id2[] = 0x", id2, 16);    

 

        log_debug("running %d\n", pmu_reboot_reason());


4)6621D/F也可以通过OTP的方式读ID

        //otp
    memset(m_chip_uuid, 0, sizeof(m_chip_uuid));
    otp_open();
    memcpy(m_chip_uuid, &CPFT_DATA_OTP->uuid.lot_number[0], 8);
    otp_close();
    log_debug_array_ex("OTP UUID", m_chip_uuid, 8);
    m_chip_uuid[0] += (m_chip_uuid[5]+m_chip_uuid[7]);
    m_chip_uuid[1] += (m_chip_uuid[4]+m_chip_uuid[6]);
    m_chip_uuid[2] += (m_chip_uuid[3]+m_chip_uuid[5]);
    log_debug_array_ex("[COM] uuid", m_chip_uuid, 3);

5)打印输出值

6621d 打印 id2[] = 0x: 1C 9A 1B 81 39 34 37 02 AB 02 80 BC 56 05 01 78 [16bytes]

6621f 打印 id2[] = 0x: 42 50 30 4B 38 34 34 14 02 23 7B 1C 56 02 23 78 [16bytes]

OTP UUID: 23 61 0F 32 39 51 4B 43 [8bytes]

[COM] uuid: B7 E5 92 [3bytes]



main-202409186174.c
被收藏 0  ∙  0 赞  
加入收藏
点赞
0 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站