新闻  |   论坛  |   博客  |   在线研讨会
Flash ROM驱动示例
shadowind | 2008-07-22 22:13:13    阅读:552   发布文章

Intel Flash芯片 i28f160,i28f320:

 
i28F320B: 64*64K,64个blocks,4M空间,每个block 64K,第一个64K由8个8*8K小blocks组成.
每个Black可以被独立擦写(寿命周期) 100,000次以上
Flash操作的大概步骤:
flash读写操作中,读应该很简单,和RAM一样,写就复杂一点.  
Intel TE28F320C3的flash是4M空间
flash空间,划分成许多的block,Intel TE28F320C3的flash是4M空间,64个block,每个block由64K.
要对所有的block单独进行操作, 每个操作结束,都需要判断状态,  
每个block操作的大概步骤如下:  
1.unlock  
2.erase  
3.check empty  
所有的block完成上述操作,且状态正确,才能进行下一步,写  
4.write
ARM汇编程序
    LDR r2, =FlashBase                     ;Flash起始地址

//第一步,UNLOCK的64个block,步骤和上边一样

         MOV r1,#63                       ;63x64k block 计数  

01     LDRB   r3, =X16_FLASH_COMMAND_CONFIG_SETUP
         STRB          r3, [r2]           ;该block的首地址  
         LDRB          r3, =X16_FLASH_COMMAND_UNLOCK_BLOCK
         STRB          r3, [r2]           ;将Unlock命令写入

         ADD r2, r2, #0x10000             ;64K
         SUBS          r1, r1, #1
         BNE %b01                             
;Unlock OK                                 ;Unlock 完成

//第二布,擦除blocks
       LDR         r0, =FlashBase
       LDR         r1,=63                       ;擦除 63x64k block
01    LDR     r3, =X16_FLASH_COMMAND_ERASE
       LDR     r2, =X16_FLASH_COMMAND_CONFIRM    
       ORR         r3, r3, r2, LSL #16
       STR         r3, [r0]
       LDR     r3, =X16_FLASH_COMMAND_STATUS ;检查寄存器状态
       STRB    r3, [r0]
02    LDRB    r3, [r0]                              ;读状态
       TST         r3, #X16_FLASH_STATUS_READY  
       BEQ     %b02                          ;若状态ready,执行下一个    
       TST     r3, #X16_FLASH_STATUS_ERROR
       BNE     error_erase_block
       ADD         r0, r0, #0x10000
       SUBS    r1, r1, #1
       BNE         %b01
       B         EraseOK
error_erase_block
..............
;EraseOK                               ;擦除完成
//第三步,检查flash是否为空
;Check Flash Empty
       LDR         r4, =FlashBase
       LDR         r5, =0x100000                    ;检查 1MB
       LDR         r0, =0xffffffff
loop_1
       LDR         r1, [r4]
       CMP         r1, r0                     ;比较地址内容和0xffffffff
       BNE         empty_error
      ADD         r4, r4, #4
       CMP         r4, r5
       BLO         loop_1
       B         CheckOK
empty_error
.................
CheckOK
.................
;Check empty OK                        ;检查完成   
//第四步,写flash
;Burn data to Flash ROM

       LDR         r6, =Length_Flash           ;定义数据长度
       LDR         r0, =FlashBase
       LDR         r1, =BufferBase
       MOV         r9, #0
       LDR         r4,=0x10000000
       LDR         r7,=0xc0001000
       STR         r4,    [r7]
       LDR         r1, [r1, r9]

03    LDR     r3, =X16_FLASH_COMMAND_WRITE
       STRB    r3, [r0]                                         ;把写命令放入Block首地址
      LDR     r3, =X16_FLASH_COMMAND_STATUS    
       LDR         r2, [r7]                                           
       LDR         r5, =0x0000ffff             
       AND         r2, r2, r5
       ORR         r2, r2, r3, LSL #16
       STR         r2, [r0]         
02    LDR         r3, [r0]                                 ;读状态寄存器状态
       TST         r3, #X16_FLASH_STATUS_READY    
       BEQ     %b02                          ;若状态ready,执行下一个

       LDR     r3, =X16_FLASH_COMMAND_WRITE
       LDR         r2, [r7]             
       LDR         r5, =0xffff0000                             ;
       AND         r2, r2, r5
       ORR         r3, r3, r2
       STR         r3, [r0]

       LDR     r3, =X16_FLASH_COMMAND_STATUS
       STRB    r3, [r0]             
02    LDR         r3, [r0]                             ; read status
       TST         r3, #X16_FLASH_STATUS_READY
       BEQ     %b02

       LDR     r4, =X16_FLASH_COMMAND_READ
       STRB    r4, [r0]
       ADD         r0, r0, #4
       LDR         r8, [r7]
       ADD         r8, r8,#1
       STR         r8, [r7]
       ADD         r8, r8, #4
writenext

       SUBS     r6, r6, #4         ;if no finished goto 03
       BHI         %b03
       TST     r3, #X16_FLASH_STATUS_ERROR
       BNE     error_write
       LDR     r3, =X16_FLASH_COMMAND_READ
       STRB    r3, [r0]
       B         BurnOK
error_write
   ..........
BurnOK

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客