|
本帖最后由 uyrfdcv 于 2010-12-18 13:23 编辑
无操作系统下nand flash驱动开发,附S3C2440开发板下测试源代码(针对K9F2G08芯片,ADS1.2开发)
写nand flash芯片之前一般需要先擦除相应的块,并且nand flash通常以页为单位进行读写,还要考虑坏块,因此访问nand flash和访问内存差别很大。下面这组函数可以实现对nand flash的大部分操作:- extern ML_ERR Flash_Init_Device(FLASH_DEVICE * device);
- extern ML_ERR Flash_Creat_Redirect_Table(FLASH_DEVICE * device, ML_U32 method);
- extern void Flash_Redirect(FLASH_DEVICE * device, ML_U32 block_base);
- extern ML_ERR Flash_Erase_Chip(FLASH_DEVICE * device, ML_U32 option);
- extern ML_ERR Flash_Read(FLASH_DEVICE * device, void * buffer, ML_U32 start_address, ML_U32 number);
- extern ML_ERR Flash_Write(FLASH_DEVICE * device, const void * buffer, ML_U32 start_address, ML_U32 number);
复制代码 以上函数实现了nand flash设备初始化, 坏块管理,擦除、读写等功能。
下面是测试主程序:- #include "ML_Flash.h"
- void Main(void)
- {
- FLASH_DEVICE * device = &Flash_K9F2G08;
-
- //# 初始化开发板
- Board_Init();
-
- while(1)
- {
- char info[] = "MultiSilicon Link.Flash v1_1_3";
- char string[] = "0123456789";
- char buffer[512] = "";
-
- //# 初始化设备
- Flash_Init_Device(device);
- //# 创建重定向表,如果Flash存在坏块,这一步是必要的
- Flash_Creat_Redirect_Table(device, 1);
- //# 在0x100000地址处写入字符串info
- Flash_Write(device, info, 0x100000, sizeof(info));
- //# 在0x234567地址处写入字符串string
- Flash_Write(device, string, 0x234567, sizeof(string));
- //# 在0x100000地址处读入sizeof(info)个字节并存入buffer
- Flash_Read(device, buffer, 0x100000, sizeof(info));
- Uart_Printf("\n%s", buffer);
- //# 在0x234567 + 3地址处读入sizeof(string)个字节并存入buffer
- Flash_Read(device, buffer, 0x234567 + 3, sizeof(string));
- Uart_Printf("\n%s", buffer);
- while(1);
- }
- }
复制代码 运行程序,在超级终端上可以看到以下输出结果:- MultiSilicon Link.Flash v1_1_3
- 3456789
复制代码 读者对照测试程序不难看出输出结果是正确的。
下载测试源代码(针对TQ2440开发板(256M nand flash),K9F2G08芯片,使用ADS1.2进行编译):
原文链接,转载请注明出处:
http://www.cnblogs.com/multisili ... /12/17/1909549.html |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|