📄 spi_prog.psm
字号:
COMPARE sD, sE ;check for last on line
JUMP NZ, program_byte ;fetch next byte to program
STORE s9, page_address_h ;remember next address in sequence
STORE s8, page_address_m
STORE s7, page_address_l
JUMP next_prog_line ;read next line for programming
MCS_address_boundary: COMPARE sA, 00 ;check if page needs to be closed
JUMP Z, next_prog_line
CALL close_prog_page_spi
JUMP program_MCS
end_program_MCS: COMPARE sA, 00 ;check if page needs to be closed
RETURN Z
CALL close_prog_page_spi
RETURN
;
;**************************************************************************************
;Read one line of an MCS file into scratch pad memory
;**************************************************************************************
;
;Reads one line of MCS file format into scratch pad memory starting at location 'line_start'.
;
;The routine detects the line start character ':' ignoring any preceding characters. This
;will remove any additional CR or LF characters.
;
;It then reads each subsequent pair of ASCII characters, converts them to true hex in the
;range 00 to FF and stores them in scratch pad memory.
;
;The end of the line is determined by either a CR or LF character.
;
;The value last returned in register 'sE' will be the pointer to the location in
;scratch pad memory following the last byte for the line read.
;
read_MCS_line: LOAD sE, line_start ;initialise SPM memory pointer
wait_MCS_line_Start: CALL read_from_UART ;read character
COMPARE UART_data, character_colon ;test for start character
JUMP NZ, wait_MCS_line_Start
read_MCS_byte: CALL read_from_UART ;read character
COMPARE UART_data, character_CR ;test for end of line
RETURN Z
COMPARE UART_data, character_LF ;test for end of line
RETURN Z
LOAD s3, UART_data ;upper nibble character
CALL read_from_UART ;read character
LOAD s2, UART_data ;lower nibble character
CALL ASCII_byte_to_hex ;convert to true hex value
STORE s0, (sE) ;write to SPM
ADD sE, 01 ;increment pointer
JUMP read_MCS_byte
;
;
;**************************************************************************************
;Determine the current address for the line of an MCS file in scratch pad memory
;**************************************************************************************
;
;Checks the existing line data stored in scratch pad memory starting at location
;'line_start' and determines the current address.
;
;The address is in the register set [s9,s8,s7] before and after this routine is
;executed because not all address bits are defined by a given line of MCS and
;the undefined bits remain constant.
;
;A record type of 04 will update [s9].
;A record type of 00 will update [s8,s7].
;
;On return, the register sB will contain the record type and
;register sC will indicate the number of data bytes stored.
;
MCS_address: LOAD sD, line_start ;initialise SPM memory pointer
FETCH sC, (sD) ;read number of bytes on line
ADD sD, 03 ;move to record type
FETCH sB, (sD) ;read record type
COMPARE sB, 00 ;test for data record
JUMP Z, new_low_address
COMPARE sB, 04 ;test for data record
RETURN NZ
ADD sD, 02 ;read upper 8-bits
FETCH s9, (sD)
RETURN
new_low_address: SUB sD, 01 ;read lower 8-bits
FETCH s7, (sD)
SUB sD, 01 ;read middle 8-bits
FETCH s8, (sD)
RETURN
;
;**************************************************************************************
;Read a page from SPI FLASH memory and display
;**************************************************************************************
;
;The start address should be provided in register set [s9,s8,s7].
;The display will be next 256 bytes displayed as 16 lines of 16 bytes
;with each line commencing with the address of the first byte.
;
;
send_spi_page: LOAD s6, 10 ;16 lines to display
send_spi_line: CALL send_CR
CALL send_hex_3bytes ;display address
CALL send_space
LOAD s5, 10 ;16 lines to display
send_spi_byte: CALL send_space
CALL read_spi_byte ;read byte into s2
ADD s7, 01 ;increment SPI FLASH address
ADDCY s8, 00
ADDCY s9, 00
LOAD s0, s2 ;display byte
CALL send_hex_byte
SUB s5, 01 ;count bytes per line
JUMP NZ, send_spi_byte
SUB s6, 01 ;count lines
JUMP NZ, send_spi_line
CALL send_CR
RETURN
;
;**************************************************************************************
;Test of SPI FLASH memory operations
;**************************************************************************************
;
;Sector 18 (120000 to 12FFFF) is used.
;A page (123400 to 1234FF) is programmed with a test pattern 00 to FF.
;The pattern is verified and then the sector erased and a blank check performed.
;
;Note that the page used is already blank (all locations contain FF hex)
;as with any device supplied (initial delivery state).
;
;Program page with test pattern
;
memory_test: LOAD s9, 12 ;select page address 123400
LOAD s8, 34
LOAD s7, 00
CALL open_prog_page_spi ; program test pattern 00 to FF
pattern_loop: LOAD s2, s7
CALL SPI_FLASH_tx_rx
ADD s7, 01
JUMP NC, pattern_loop
CALL close_prog_page_spi ; program test pattern 00 to FF
;
;Verify test pattern by reading back page
;
LOAD UART_data, character_p ;p for pass
LOAD s9, 12 ;select page address 123400
LOAD s8, 34
LOAD s7, 00
verify_test_page: CALL read_spi_byte ;read byte into s2
COMPARE s2, s7 ;check test pattern data value
JUMP NZ, memory_verify_fail
ADD s7, 01 ;next location
JUMP NZ, verify_test_page ;loop until roll over page
JUMP memory_verify_result
memory_verify_fail: LOAD UART_data, character_f ;f for fail
memory_verify_result: CALL send_to_UART
RETURN
;
;Erase sector with test pattern and verify blank
;
erase_test_sector: LOAD s9, 12 ;sector 18 start address 120000
LOAD s8, 00
LOAD s7, 00
CALL erase_spi_sector
LOAD UART_data, character_p ;p for pass
LOAD s9, 12 ;select page address 123400
LOAD s8, 34
LOAD s7, 00
verify_blank_page: CALL read_spi_byte ;read byte into s2
COMPARE s2, FF ;check blank 'FF'
JUMP NZ, memory_blank_fail
ADD s7, 01 ;next location
JUMP NZ, verify_blank_page ;loop until roll over page
JUMP memory_blank_result
memory_blank_fail: LOAD UART_data, character_f ;f for fail
memory_blank_result: CALL send_to_UART
RETURN
;
;
;
;**************************************************************************************
;Test of SPI FLASH memory communications
;**************************************************************************************
;Link must be installed in J11 to link ROM-CS to CSO_B
;
;Read the identification ID from SPI FLASH memory (ST type M25P16)
;and compare with expected response.
; s9 = Manufacturer Identification = 20 hex
; s8 = Memory Type = 20 hex
; s7 = Memory Capacity = 15 hex
;
memory_comms_test: CALL read_spi_flash_ID
LOAD UART_data, character_p ;p for pass
COMPARE s9, 20
JUMP NZ, SPI_FLASH_ID_fail
COMPARE s8, 20
JUMP NZ, SPI_FLASH_ID_fail
COMPARE s7, 15
JUMP NZ, SPI_FLASH_ID_fail
JUMP SPI_FLASH_ID_result
SPI_FLASH_ID_fail: LOAD UART_data, character_f ;f for fail
SPI_FLASH_ID_result: CALL send_to_UART
RETURN
;
;
;
;
;
;
;**************************************************************************************
;SPI FLASH memory routines
;**************************************************************************************
;
;These routines will work with two output ports and one input port which should be
;defined as follows using CONSTANT directives.
; (replace 'pp' with appropriate port address in each case)
;In the list of CONSTANT directives, only the ones marked with a * are really required
;in an SPI FLASH memory system. The other directives are to control (disable) or
;communicate with the other SPI components on the same SPI bus of the Spartan-3E Starter Kit.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -