Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_fdb_write_status()函数执行前是否先擦除再写入? #66

Closed
mysterywolf opened this issue Feb 28, 2021 · 15 comments
Closed

_fdb_write_status()函数执行前是否先擦除再写入? #66

mysterywolf opened this issue Feb 28, 2021 · 15 comments

Comments

@mysterywolf
Copy link
Contributor

由于最近github间歇性被墙,我代 @xql923 提问:

硬件环境:
MCU:STM32F413;SPI Flash:W25Q256

  配置FlashDB参数:FDB_WRITE_GRAN == 1

   W25Q256每次按照一个扇区擦除4096字节,一个扇区只有在擦除后才能再次写入,如果扇区内数据没有擦除而直接写入,会写入失败。

问题描述:
移植FlashDB保存参数和数据,但是在实际仿真调试时,fdb_utils.c文件中_fdb_write_status()函数总是执行失败,仿真发现,_fdb_write_status()函数每次值写入一个字节,写入前FlashDB并没有考虑擦除所在扇区数据,而是直接写入,这样会导致写入失败。

   请问,_fdb_write_status()函数没有考虑在写入前,擦除相应扇区的数据吗?
   是否需要在移植接口函数中特殊考虑?
@armink
Copy link
Owner

armink commented Feb 28, 2021

理论上不存在这种情况,默认都是上电会检测 Flash 是否有做过格式化,必要时,系统会自动对 Flash 完成格式化动作

格式化时就会对 Flash 执行擦除动作

@xql923
Copy link

xql923 commented Feb 28, 2021 via email

@armink
Copy link
Owner

armink commented Feb 28, 2021

手动 fdb_kv_set_default 试一下?

@xql923
Copy link

xql923 commented Feb 28, 2021 via email

@xql923
Copy link

xql923 commented Feb 28, 2021 via email

@xql923
Copy link

xql923 commented Mar 1, 2021

朱经理你好,在fdb_utils.c文件中,请问:
fdb_err_t _fdb_write_status(fdb_db_t db, uint32_t addr, uint8_t status_table[], size_t status_num, size_t status_index)
{
......

       #if (FDB_WRITE_GRAN == 1)

       -------//这个函数在运行之前,程序中,由针对addr + byte_index这个地址所在扇区进行格式化了吗?
       result = _fdb_flash_write(db, addr + byte_index, (uint32_t *)&status_table[byte_index], 1);

     #endif

........
}

@armink
Copy link
Owner

armink commented Mar 1, 2021

写之前肯定是有擦除,否则也没法写入的

@xql923
Copy link

xql923 commented Mar 1, 2021 via email

@armink
Copy link
Owner

armink commented Mar 1, 2021

用户不需要考虑擦写的时机,只需提供好移植函数就好,建议详细参考下 demo 文件下的示例,并在真机上试用

@xql923
Copy link

xql923 commented Mar 1, 2021 via email

@armink
Copy link
Owner

armink commented Mar 1, 2021

gitee 上也有,可以搜一下

@xql923
Copy link

xql923 commented Mar 2, 2021

朱先生你好,我的SPI Flash并没有采用SFUD,而是FlashDB的fal port接口直接以扇区读、写和删除nor Flash,请问:
/* the flash write granularity, unit: bit

  • only support 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1) */
    #define FDB_WRITE_GRAN 1

----请问这个需要设置为多少?

@xql923
Copy link

xql923 commented Mar 2, 2021

使用的是SPI Flash:W25Q256,每个扇区的大小为:4096字节

@xql923
Copy link

xql923 commented Mar 3, 2021

结帖。
将程序实现看了一遍,学习了朱先生的设计精巧之处。特别是针对Nor Flash的写入特点,巧妙的以bit设置状态位实现KV状态的设置,进而实现了所谓“掉电恢复”的功能。

@xql923
Copy link

xql923 commented Mar 3, 2021

“磨损均衡”的实现也很巧妙。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants