armink / SFUD

An using JEDEC's SFDP standard serial (SPI) flash universal driver library | 一款使用 JEDEC SFDP 标准的串行 (SPI) Flash 通用驱动库
MIT License
1.29k stars 452 forks source link

SFUD会添加Block Protect功能支持吗? #44

Open dmsg opened 3 years ago

dmsg commented 3 years ago

SFUD是否有计划支持Flash的Block Protect功能?

armink commented 3 years ago

暂不支持的,这块处理不同芯片差异很大的

lazyguoguo commented 3 years ago

暂不支持的,这块处理不同芯片差异很大的

发现驱动SST26VF016B 这玩意默认开启Block Protect,调用写成功,但数据始终不对,一直查硬件问题,后来仔细看手册才发现这个问题。。。

armink commented 3 years ago

暂不支持的,这块处理不同芯片差异很大的

发现驱动SST26VF016B 这玩意默认开启Block Protect,调用写成功,但数据始终不对,一直查硬件问题,后来仔细看手册才发现这个问题。。。

是的,所以这类芯片 SFUD 里都有特殊处理

https://github.com/armink/SFUD/blob/4b41297127ec27ba9c08358fa072629e1c08ca1c/sfud/src/sfud.c#L351-L362

lazyguoguo commented 3 years ago

根据手册直接增加解锁函数,加入初始化最后面。

image

static sfud_err set_ULBPR(const sfud_flash *flash){
    uint8_t cmd;
    sfud_err result = SFUD_SUCCESS;
    const sfud_spi *spi = &flash->spi;
    SFUD_ASSERT(flash);
    if (spi->lock) {
          spi->lock(spi);
      }
    result = set_write_enabled(flash, true);
       if (result != SFUD_SUCCESS) {
           goto __exit;
       }
    cmd = 0x98;
    result = flash->spi.wr(&flash->spi, &cmd, 1, NULL, 0);
__exit:
        /* set the flash write disable */
        set_write_enabled(flash, false);
        /* unlock SPI */
        if (spi->unlock) {
            spi->unlock(spi);
        }
    return result;
}

放在sfud_device_init最后面

sfud_err sfud_device_init(sfud_flash *flash) {
    sfud_err result = SFUD_SUCCESS;
    /* hardware initialize */
    result = hardware_init(flash);
    if (result == SFUD_SUCCESS) {
        result = software_init(flash);
    }
    if (result == SFUD_SUCCESS) {
        flash->init_ok = true;
        SFUD_INFO("%s flash device is initialize success.", flash->name);
    } else {
        flash->init_ok = false;
        SFUD_INFO("Error: %s flash device is initialize fail.", flash->name);
    }
    result = set_ULBPR(flash);    // 全局解锁block保护
    return result;
}