147 lines
4.0 KiB
Plaintext
147 lines
4.0 KiB
Plaintext
; --------------------------------------------------------------------------------
|
|
; @Title: SPI FLASH Programming script for AT91RM9200
|
|
; @Description:
|
|
; SPI FLASH(Spansion, S25FL64) is connected NPCS0 (PA3)
|
|
;
|
|
; PA0 MISO
|
|
; PA1 MOSI
|
|
; PA2 SCLK
|
|
; PA3 SS0
|
|
;
|
|
; Internal SRAM : 0x00200000 (16KB)
|
|
; Tx Register : 0xFFFE0000+0x0C
|
|
; Rx Register : 0xFFFE0000+0x08
|
|
; CS Register : 0xFFFE0000+0x00 ; SPI flash Enable/Disable register
|
|
;
|
|
; @Author: jjeong
|
|
; @Chip:
|
|
; @Keywords:
|
|
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
|
|
; --------------------------------------------------------------------------------
|
|
; $Id: at91rm9200-spi.cmm 10516 2022-02-02 11:39:30Z bschroefel $
|
|
|
|
LOCAL &arg1
|
|
ENTRY &arg1
|
|
&arg1=STRing.UPpeR("&arg1") // for example "PREPAREONLY"
|
|
|
|
&SPI_BASE=0xFFFE0000
|
|
|
|
SYStem.CPU AT91RM9200 ; AT91RM9200 core
|
|
SYStem.Option.ResBreak OFF ; hardware dependent (see manual)
|
|
SYStem.Option.WaitReset ON ; hardware dependent (see manual)
|
|
SYStem.Option.BigEndian OFF ; this demo is in little endian
|
|
SYStem.JtagClock 10.MHz
|
|
|
|
SYStem.Up
|
|
|
|
PER.Set.simple ASD:0xFFFFFD08 %Long 0x0 ;Watch dog diasable
|
|
PER.Set.simple ASD:0xFFFFFC20 %Long 0x1 ;enable main clock
|
|
PER.Set.simple ASD:0xFFFFFC30 %Long 0x1 ;select main clock
|
|
|
|
GOSUB SPI_INIT
|
|
|
|
GOSUB READ_ID_TEST
|
|
|
|
//S(D)RAM TEST for algorithm file
|
|
GOSUB SDRAM_INIT
|
|
Data.Test 0x00200000++0x3FFF /Prime ;s(d)ram test
|
|
IF FOUND()
|
|
(
|
|
PRINT "s(d)ram is NOT initialized around 0x" ADDRESS.OFFSET(TRACK.ADDRESS())
|
|
ENDDO
|
|
)
|
|
|
|
|
|
Break.RESet
|
|
|
|
FLASHFILE.RESet
|
|
|
|
//FLASFILE.CONFIG <Tx Reg> <Rx Reg> <CS> 0
|
|
FLASHFILE.CONFIG &SPI_BASE+0x0C &SPI_BASE+0x08 &SPI_BASE 0
|
|
|
|
// FLASHFILE.TARGET <code range> <data range> <Algorithm file>
|
|
FLASHFILE.TARGET 0x00200000++0x1FFF 0x00202000++0x1FFF ~~/demo/arm/flash/byte/spi64_at91sam.bin /KEEP ;SPI Flash
|
|
;FLASHFILE.TARGET 0x00200000++0x1FFF 0x00202000++0x1FFF ~~/demo/arm/flash/byte/at45p256_at91sam.bin /KEEP ;AT45 Flash
|
|
|
|
FLASHFILE.GETID
|
|
|
|
//End of the test prepareonly
|
|
IF "&arg1"=="PREPAREONLY"
|
|
ENDDO
|
|
|
|
;FLASHFILE.DUMP 0x0
|
|
|
|
//Erase Serial FLASH
|
|
;FLASHFILE.ERASE 0x0--0xFFFFF
|
|
|
|
//Write
|
|
;FLASHFILE.LOAD * 0x0
|
|
;FLASHFILE.LOAD * 0x0 /ComPare ;verify
|
|
|
|
ENDDO
|
|
|
|
SPI_INIT:
|
|
(
|
|
//Clock Enable for SPI
|
|
//AT91C_BASE_PMC->PMC_PCER = 1 << 13;
|
|
PER.Set.simple A:0xFFFFFC00+0x10 %Long Data.Long(A:(0xFFFFFC00+0x10))|0x1<<13.|(0x1<<4)|(0x1<<3)|(0x1<<2) ;PMC_PCER
|
|
|
|
//pin mux
|
|
PER.Set.simple A:0xFFFFF400+0x70 %Long 0x1F ;PIO_ASR, PA[3:0] assigns to periperial A function.
|
|
PER.Set.simple A:0xFFFFF400+0x4 %Long 0x1F ;PIO_PDR, PIO Disable PA[3:0]
|
|
|
|
// Reset the SPI
|
|
PER.Set.simple A:&SPI_BASE+0x00 %Word 0x80
|
|
PER.Set.simple A:&SPI_BASE+0x00 %Word 0x80
|
|
|
|
PER.Set.simple ASD:0xFFFE0014 %Long -1
|
|
|
|
// Configure SPI in Master Mode with No CS selected !!! */
|
|
//AT91C_BASE_SPI->SPI_MR = AT91C_SPI_MSTR | AT91C_SPI_MODFDIS | AT91C_SPI_PCS;
|
|
PER.Set.simple A:&SPI_BASE+0x0004 %Long 0xE0011 ; for NPCS0
|
|
; PER.Set.simple A:&SPI_BASE+0x0004 %Long 0xD0011 ; for NPCS1
|
|
|
|
// Configure CSR0
|
|
PER.Set.simple A:&SPI_BASE+0x0030 %Long 0x10010201 ; make a dealy for keeping the NPCS0 low until next spi data
|
|
; PER.Set.simple A:&SPI_BASE+0x0034 %Long 0x10010201 ; make a dealy for keeping the NPCS1 low until next spi data
|
|
|
|
RETURN
|
|
)
|
|
|
|
READ_ID_TEST:
|
|
(
|
|
&tx_reg=&SPI_BASE+0x0C
|
|
&rx_reg=&SPI_BASE+0x08
|
|
&cs_reg=&SPI_BASE+0x00
|
|
&st_reg=&SPI_BASE+0x10
|
|
|
|
PER.Set.simple A:&SPI_BASE+0x0030 %Long 0xFFFF0801 ; make a max dealy for keeping the NPCS0 low until next spi data
|
|
PER.Set.simple A:&SPI_BASE+0x0034 %Long 0xFFFF0801 ; make a max dealy for keeping the NPCS1 low until next spi data
|
|
|
|
Data.Set &cs_reg %Long 0x1 ;CS Eable
|
|
|
|
RePeaT 4.
|
|
(
|
|
WHILE (Data.Long(A:&st_reg)&0x2)!=0x2
|
|
(
|
|
)
|
|
Data.Set A:&tx_reg %Long 0x9F ; Write command
|
|
|
|
WHILE (Data.Long(A:&st_reg)&0x1)!=0x1
|
|
(
|
|
)
|
|
PRINT "read :0x" Data.Long(SD:&rx_reg)&0xFF ; dummy
|
|
)
|
|
|
|
Data.Set &cs_reg %Long 0x2 ;CS disable
|
|
|
|
GOSUB SPI_INIT
|
|
|
|
RETURN
|
|
)
|
|
|
|
SDRAM_INIT:
|
|
|
|
RETURN
|
|
|