;Compute CMD ;
; ----------------------------------;
MOV #1,&SD_CMD_FRM ;3 $(01 00 xx xx xx CMD) set stop bit in CMD frame
- CMP #2,&FATtype ;3 FAT32 ?
- JZ FAT32_CMD ;2 yes
-FAT16_CMD ; FAT16 : CMD17/24 byte address = Sector * BPB_BytsPerSec
- ADD W,W ;1 shift left one Sector
- ADDC.B X,X ;1
- MOV W,&SD_CMD_FRM+2 ;3 $(01 00 ll LL xx CMD)
- MOV.B X,&SD_CMD_FRM+4 ;3 $(01 00 ll LL hh CMD)
- JMP WaitIdleBeforeSendCMD ;
+; CMP #2,&FATtype ;3 FAT32 ?
+; JZ FAT32_CMD ;2 yes
+;FAT16_CMD ; FAT16 : CMD17/24 byte address = Sector * BPB_BytsPerSec
+; ADD W,W ;1 shift left one Sector
+; ADDC.B X,X ;1
+; MOV W,&SD_CMD_FRM+2 ;3 $(01 00 ll LL xx CMD)
+; MOV.B X,&SD_CMD_FRM+4 ;3 $(01 00 ll LL hh CMD)
+; JMP WaitIdleBeforeSendCMD ;
FAT32_CMD ; FAT32 : CMD17/24 sector address
MOV.B W,&SD_CMD_FRM+1 ;3 $(01 ll xx xx xx CMD)
SWPB W ;1
ADD.B #1,W ; expected value = FFh <==> MISO = 1 = SPI idle state
JNZ WaitIdleBeforeSendCMD ; loop back if <> FFh
; ==================================; W = 0 = expected R1 response = ready, for CMD41,CMD16, CMD17, CMD24
-sendCommand ;
+sendCommand ;
; ==================================;
- ; input : SD_CMD_FRM : {CRC,byte_l,byte_L,byte_h,byte_H,CMD}
+ ; input : SD_CMD_FRM : {CRC,byte_l,byte_L,byte_h,byte_H,CMD}
; W = expected return value
; output W is unchanged, flag Z is positionned
; reverts CMD bytes before send : $(CMD hh LL ll 00 CRC)
; ----------------------------------;
Send_CMD_PUT ; performs little endian --> big endian conversion
; ----------------------------------;
- MOV.B SD_CMD_FRM(X),&SD_TXBUF ;5
+ MOV.B SD_CMD_FRM(X),&SD_TXBUF ;5
CMP #0,&SD_BRW ;3 full speed ?
JZ FullSpeedSend ;2 yes
Send_CMD_Loop ; case of low speed during memCardInit
; host must provide height clock cycles to complete operation
; here X=255, so wait for CMD return expected value with PUT FFh 256 times
-; MOV #4,X ; to pass made in PRC SD_Card init
+; MOV #4,X ; to pass made in PRC SD_Card init
; MOV #16,X ; to pass Transcend SD_Card init
; MOV #32,X ; to pass Panasonic SD_Card init
; MOV #64,X ; to pass SanDisk SD_Card init
; ==================================;
SPI_PUT ; PUT(W) X times, output : W = last received byte, X = 0
; ==================================;
- SWPB W ;1
+ SWPB W ;1
MOV.B W,&SD_TXBUF ;3 put W high byte then W low byte and so forth, that performs little to big endian conversion
CMP #0,&SD_BRW ;3 full speed ?
- JZ FullSpeedPut ;2
+ JZ FullSpeedPut ;2
SPI_PUTWAIT BIT #RX_SD,&SD_IFG ;3
JZ SPI_PUTWAIT ;2
CMP.B #0,&SD_RXBUF ;3 reset RX flag
MOV @RSP+,PC ;4
; ----------------------------------;
- ASMWORD "READ_SWX"
+ ASMWORD "R_SECT_WX" ; Read SECTor W=lo, X=Hi
; ==================================;
ReadSectorWX ; SWX read a logical sector
; ==================================;
BIS #1,S ; preset sd_read error
MOV.B #51h,&SD_CMD_FRM+5 ; CMD17 = READ_SINGLE_BLOCK
CALL #RW_Sector_CMD ; which performs logical sector to physical sector then little endian to big endian conversion
- JNE SD_CARD_ERROR ; time out error if R1 <> 0
+ JNE SD_CARD_ERROR ; time out error if R1 <> 0
; ----------------------------------;
-WaitFEhResponse ; wait SD_Card response FEh
+WaitFEhResponse ; wait for SD_Card response = FEh
; ----------------------------------;
CALL #SPI_GET ;
- ADD.B #2,W ;1 FEh expected value
- JZ ReadSectorFirstByte ; 2
+ ADD.B #2,W ;1 W = 0 ?
+ JZ ReadSectorFirstByte ;2 yes
JNZ WaitFEhResponse ;2
; ----------------------------------;
ReadSectorLoop ; get 512+1 bytes, write 512 bytes in SD_BUF
; ----------------------------------;
MOV.B &SD_RXBUF,SD_BUF-1(X) ; 5
-ReadSectorFirstByte ;
+ReadSectorFirstByte ; W=0
MOV.B #-1,&SD_TXBUF ; 3 put FF
NOP ; 1 NOPx adjusted to avoid read SD_error
ADD #1,X ; 1
; ----------------------------------;
BIC #3,S ; reset read and write errors
BIS.B #CS_SD,&SD_CSOUT ; Chip Select high
- MOV @RSP+,PC ;
+ MOV @RSP+,PC ; W = 0
; ----------------------------------;
.IFDEF SD_CARD_READ_WRITE
- ASMWORD "WRITE_SWX"
+ ASMWORD "W_SECT_WX" ; Write SECTor W=lo, X=Hi
; ==================================;
WriteSectorWX ; write a logical sector
; ==================================;
CheckWriteState ;
; ----------------------------------;
BIC.B #0E1h,W ; apply mask for Data response
- CMP.B #4,W ; data accepted
+ SUB.B #4,W ; data accepted
JZ ReadWriteHappyEnd ;
; ----------------------------------;
; SD Error n°
; High byte
; 1 = CMD17 read error
-; 2 = CMD24 write error
+; 2 = CMD24 write error
; 4 = CMD0 time out (GO_IDLE_STATE)
; 8 = ACMD41 time out (APP_SEND_OP_COND)
; $10 = CMD16 time out (SET_BLOCKLEN)
; 7th bit = parameter error
; Data Response Token
-; Every data block written to the card will be acknowledged by a data response token.
+; Every data block written to the card will be acknowledged by a data response token.
; It is one byte long and has the following format:
; %xxxx_sss0 with bits(3-1) = Status
;The meaning of the status bits is defined as follows:
ADD &SD_RXBUF,S ; add SPI(GET) return value as low byte error
SD_CARD_ID_ERROR ; <=== SD_INIT error $20 from forthMSP430FR_SD_INIT.asm
BIS.B #CS_SD,&SD_CSOUT ; Chip Select high
- mDOCOL ;
+; mDOCOL ;
+ mASM2FORTH ;
.word ECHO
.word XSQUOTE ; don't use S register
.byte 11,"< SD Error!" ;
; ----------------------------------;
ABORT_SD ; <=== OPEN file errors from forthMSP430FR_SD_LOAD.asm
; ----------------------------------;
- .word $+2 ;
+ mNEXTADR ;
SUB #2,PSP ;
MOV TOS,0(PSP) ;
- MOV #10h,&BASE ; select hex
+ MOV #10h,&BASEADR ; select hex
MOV S,TOS ;
- ASMtoFORTH ;
+; MOV #TIB_ORG,&CIB_ADR ; restore TIB as Current Input Buffer
+; MOV #BODYACCEPT,&PFAACCEPT ; restore default ACCEPT
+ mASM2FORTH ;
.word UDOT,ABORT_TERM ; no return...
; ----------------------------------;