新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ARM編程中Flash ROM驅(qū)動(dòng)示例

ARM編程中Flash ROM驅(qū)動(dòng)示例

作者: 時(shí)間:2013-12-04 來(lái)源:網(wǎng)絡(luò) 收藏

Intel 芯片 i28f160,i28f320:

i28F320B: 64*64K,64個(gè)blocks,4M空間,每個(gè)block 64K,第一個(gè)64K由8個(gè)8*8K小blocks組成.

每個(gè)Black可以被獨(dú)立擦寫(xiě)(壽命周期) 100,000次以上

操作的大概步驟:

flash讀寫(xiě)操作中,讀應(yīng)該很簡(jiǎn)單,和RAM一樣,寫(xiě)就復(fù)雜一點(diǎn).
IntelTE28F320C3的flash是4M空間
flash空間,劃分成許多的block,IntelTE28F320C3的flash是4M空間,64個(gè)block,每個(gè)block由64K.
要對(duì)所有的block單獨(dú)進(jìn)行操作,每個(gè)操作結(jié)束,都需要判斷狀態(tài),
每個(gè)block操作的大概步驟如下:
1.unlock
2.erase
3.checkempty
所有的block完成上述操作,且狀態(tài)正確,才能進(jìn)行下一步,寫(xiě)
4.write

arm匯編程序

LDR r2,=Base ;Flash起始地址

//第一步,UNLOCK的64個(gè)block,步驟和上邊一樣


MOV r1,#63 ;63x64kblock 計(jì)數(shù)


01 LDRB r3,=X16_FLASH_COMMAND_CONFIG_SETUP

STRB r3,[r2] ;該block的首地址

LDRBr3,=X16_FLASH_COMMAND_UNLOCK_BLOCK

STRB r3,[r2] ;將Unlock命令寫(xiě)入

ADD r2,r2,#0x10000 ;64K
SUBS r1,r1,#1
BNE %b01
;UnlockOK ;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;檢查寄存器狀態(tài)
STRB r3, [r0]
02 LDRB r3, [r0] ;讀狀態(tài)
TST r3, #X16_FLASH_STATUS_READY
BEQ %b02 ;若狀態(tài)ready,執(zhí)行下一個(gè)
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 ;比較地址內(nèi)容和0xffffffff
BNE empty_error
ADD r4, r4, #4
CMP r4, r5
BLO loop_1
B CheckOK
empty_error
.................
CheckOK
.................

;Check empty OK ;檢查完成

//第四步,寫(xiě)flash

;Burn data to Flash ROM

LDR r6, =Length_Flash ;定義數(shù)據(jù)長(zhǎng)度
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] ;把寫(xiě)命令放入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] ;讀狀態(tài)寄存器狀態(tài)
TST r3, #X16_FLASH_STATUS_READY
BEQ %b02 ;若狀態(tài)ready,執(zhí)行下一個(gè)

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



評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉