打印
[牛人杂谈]

使用Data Flash模拟EEPROM

[复制链接]
3110|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wanduzi|  楼主 | 2017-10-28 20:34 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
使用Data Flash模拟EEPROM.pdf (1020.21 KB)



沙发
wanduzi|  楼主 | 2017-10-28 20:34 | 只看该作者
这份文件介绍如何使用Data Flash模拟EEPROM,并且利用SRAM加速资料读写的速度。内容包含原理介绍、性能数据以及使用建议。附录提供范例程序源码以及函数库。

使用特权

评论回复
板凳
wanduzi|  楼主 | 2017-10-28 20:36 | 只看该作者
Init_EEPROM()
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Initial Data Flash as EEPROM.
* @param[in] data_size: The amount of user's data, unit in byte. The maximun amount is
128.
* @param[in] use_pages: The amount of page which user want to use.
* @retval Err_OverPageSize: The amount of user's data is over than the maximun amount.
* @retval Err_OverPageAmount: The amount of page which user want to use is over than
the maximun amount.
* @retval 0: Success
*/
uint32_t Init_EEPROM(uint32_t data_amount, uint32_t use_pages)
{
uint32_t i;
/* The amount of data includes 1 byte address and 1 byte data */
Amount_of_Data = data_amount;
/* The amount of page which user want to use */
Amount_Pages = use_pages;
/* Check setting is valid or not */
/* The amount of user's data is more than the maximun amount or not */
if(Amount_of_Data > Max_Amount_of_Data)
return Err_OverAmountData;
/* For M051 Series, the max. amount of Data Flash pages is 8 */
if(Amount_Pages > 8)
return Err_OverPageAmount;
/* Init SRAM for data */
Written_Data = (uint8_t *)malloc(sizeof(uint8_t) * Amount_of_Data);
/* Fill initial data 0xFF*/
for(i = 0; i < Amount_of_Data; i++)
{
Written_Data[i] = 0xFF;
}
return 0;
}
/**
* @brief Search which page has valid data and where is current cursor for the next
data to write.
*/
void Search_Valid_Page(void)
{
uint32_t i, temp;
uint8_t addr, data;
uint16_t *Page_Status_ptr;
/* Enable FMC ISP function */
FMC_Enable();
/* Set information of each pages to Page_Status */
Page_Status_ptr = (uint16_t *)malloc(sizeof(uint16_t) * Amount_Pages);
for(i = 0; i < Amount_Pages; i++)
{
Page_Status_ptr[i] = (uint16_t)FMC_Read(DataFlash_BaseAddr +
(FMC_FLASH_PAGE_SIZE * i));
}
/* Search which page has valid data */
for(i = 0; i < Amount_Pages; i++)
{
if(Page_Status_ptr[i] != Status_Unwritten)
Current_Valid_Page = i;
}
/* If Data Flash is used for first time, set counter = 0 */
if(Page_Status_ptr[Current_Valid_Page] == Status_Unwritten)
{
/* Set counter = 0 */
FMC_Write(DataFlash_BaseAddr + (FMC_FLASH_PAGE_SIZE *
Current_Valid_Page), 0xFFFF0000);
/* Set cursor to current Data Flash address */
Current_Cursor = 2;
}
else
{
/* Search where is current cursor for the next data to write and get the
data has been written */
/* Check even value */
temp = FMC_Read(DataFlash_BaseAddr + (FMC_FLASH_PAGE_SIZE *
Current_Valid_Page));
addr = (temp & Even_Addr_Mask) >> Even_Addr_Pos;
data = (temp & Even_Data_Mask) >> Even_Data_Pos;
/* Check Address is 0xFF (un-written) of not */
if(addr == 0xFF)
{
/* If Address is 0xFF, then set cursor to current Data Flash
address */
Current_Cursor = 2;
}
else
{
/* Copy the address and data to SRAM */
Written_Data[addr] = data;
/* Check the whole Data Flash */
for(i = 4; i < FMC_FLASH_PAGE_SIZE; i += 4)
{
/* Check odd value */
temp = FMC_Read(DataFlash_BaseAddr +
(FMC_FLASH_PAGE_SIZE * Current_Valid_Page) + i);
addr = (temp & Odd_Addr_Mask) >> Odd_Addr_Pos;
data = (temp & Odd_Data_Mask) >> Odd_Data_Pos;
/* Check Address is 0xFF (un-written) of not */
if(addr == 0xFF)
{
/* If Address is 0xFF, then set cursor to
current Data Flash address */
Current_Cursor = i;
break;
}
else
{
/* Copy the address and data to SRAM */
Written_Data[addr] = data;
}
/* Check even value */
addr = (temp & Even_Addr_Mask) >> Even_Addr_Pos;
data = (temp & Even_Data_Mask) >> Even_Data_Pos;
/* Check Address is 0xFF (un-written) of not */
if(addr == 0xFF)
{
/* If Address is 0xFF, then set cursor to
current Data Flash address */
Current_Cursor = i + 2;
break;
}
else
{
/* Copy the address and data to SRAM */
Written_Data[addr] = data;
}
}
}
}
}

使用特权

评论回复
地板
wanduzi|  楼主 | 2017-10-28 20:37 | 只看该作者

下载学习啊。

使用特权

评论回复
5
21mengnan| | 2017-10-28 21:17 | 只看该作者
一共用了4个函数实现,那么这四个函数在哪个地方可以找到?有头文件吗

使用特权

评论回复
6
dongnanxibei| | 2017-10-28 21:38 | 只看该作者
没看懂第四个函数,是统计被写过多少次了吗,这样是软件计数的还是硬件。

使用特权

评论回复
7
heelary| | 2017-10-31 09:21 | 只看该作者
谢谢楼主分享!

使用特权

评论回复
8
wanduzi|  楼主 | 2017-11-12 17:50 | 只看该作者
这个是新唐自己提供的学习资料。

使用特权

评论回复
9
role_2099| | 2018-3-25 14:48 | 只看该作者
这个资料很好。不知道还有没有其他外设的实际应用案例分享

使用特权

评论回复
10
zhuotuzi| | 2018-3-25 16:11 | 只看该作者
FMC技术嘛,这个用的挺多的。

使用特权

评论回复
11
jiekou001| | 2018-3-25 16:34 | 只看该作者
内部的接口技术。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

144

主题

1732

帖子

3

粉丝