OSDN Git Service

Update readme
[fast-forth/master.git] / MSP_EXP430FR2355.asm
index 72d882c..d4427a8 100644 (file)
@@ -90,9 +90,6 @@
 ; LFXTAL XOUT- P2.6
 ; LFXTAL XIN - P2.7
 
-
-
-
 ; ======================================================================
 ; MSP-EXP430FR2355 LAUNCHPAD    <--> OUTPUT WORLD
 ; ======================================================================
         
 ; P2.2  -             J2.18  -  <---- TSSOP32236 (IR RC5) 
 
-; P2.5  -             J2.12  -  ----> SD_CS (Card Select)
-; P4.4  -             J2.13  -  <---- SD_CD (Card Detect)
+; P2.5  -             J2.13  -  <---- SD_CD (Card Detect)
+; P4.4  -             J2.12  -  ----> SD_CS (Card Select)
 ; P4.5  - UCB1 CLK    J1.7   -  ----> SD_CLK
-; P4.7  - UCB1 SOMI   J2.14  -  <---- SD_SDO
 ; P4.6  - UCB1 SIMO   J2.15  -  ----> SD_SDI
+; P4.7  - UCB1 SOMI   J2.14  -  <---- SD_SDO
         
 ; P6.0  -             J4.39  -  ----> SCL I2C Soft_Master
 ; P6.1  -             J4.38  -  <---> SDA I2C Soft_Master
 ; POWER ON RESET AND INITIALIZATION : PORT1/2
 ; ----------------------------------------------------------------------
 
-; LED1 - P1.0   (red)
-
-; SW2  - P2.3
-
 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
 
 ; PORTA usage
 
-            MOV #-1,&PAREN      ; all inputs with pull resistors
-            BIS #00001h,&PADIR  ; all pins as input else LED1 as output
-            MOV #0FFFEh,&PAOUT  ; all pins with pullup resistors ekse LED1 = output low
-
+;               P1.0  -   LED1 red
+; UART RTS      P2.0  -   J2.19     ---->   CTS UARTtoUSB bridge (TERMINAL4WIRES)
+; UART CTS      P2.1  -   J4.40     <----   RTS UARTtoUSB bridge (TERMINAL5WIRES)
+;               P2.3  -   SW2
+;               P2.5  -   J2.10     <----   SD_CD (Card Detect)
 
-; P2.0  - RTS         J2.19   -  ----> CTS UARTtoUSB bridge (TERMINAL4WIRES)
-; P2.1  - CTS         J4.40   -  <---- RTS UARTtoUSB bridge (TERMINAL5WIRES)
+            MOV #-1,&PAREN      ; all inputs with pull resistors
+            MOV #1,&PADIR       ; all pins as input else LED1 as output
+            MOV #0FFFEh,&PAOUT  ; all pins with pullup resistors else LED1 = output low
+
+    .IFDEF UCA0_TERM
+; UCA0_RXD  -   P1.6    - J1.3      <----   TX  UARTtoUSB bridge
+; UCA0_TXD  -   P1.7    - J1.4      ---->   RX  UARTtoUSB bridge
+RXD         .equ 40h        ; P1.6 = RXD
+TXD         .equ 80h        ; P1.7 = TXD + FORTH Deep_RST pin
+TERM_BUS    .equ 0C0h
+TERM_IN     .equ P1IN
+TERM_REN    .equ P1REN
+TERM_SEL    .equ P1SEL0
+    .ENDIF
 
     .IFDEF TERMINAL4WIRES
-; RTS output must be wired to the CTS input of UART2USB bridge 
-; configure RTS as output high to disable RX TERM during start FORTH
-; notice that this pin RTS may be permanently wired on SBWTCK (TEST) without disturbing SBW 2 wires programming
+; RTS output is wired to the CTS input of UART2USB bridge 
+; configure RTS as output high (false) to disable RX TERM during start FORTH
 HANDSHAKOUT .equ    P2OUT
 HANDSHAKIN  .equ    P2IN
-RTS         .equ    1           ; P2.0 bit position
-
-            BIS.B #1,&P2OUT     ; P2.0 RTS as output high
-
+RTS         .equ    1           ; P2.0
+            BIS.B #RTS,&P2DIR   ; RTS as output high
         .IFDEF TERMINAL5WIRES
-
 ; CTS input must be wired to the RTS output of UART2USB bridge 
-; configure CTS as input low
-CTS         .equ    2           ; P2.1 bit position
-            BIC.B  #2,&P2DIR    ; CTS input pull down resistor
-
+; configure CTS as input low (true) to avoid lock when CTS is not wired
+CTS         .equ    2           ; P2.1
+            BIC.B #CTS,&P2OUT   ; CTS input pulled down
         .ENDIF  ; TERMINAL5WIRES
-
     .ENDIF  ; TERMINAL4WIRES
 
-; SD_CS - P2.5 (Card Select)
-SD_CS           .equ  20h
-SD_CSOUT        .equ P2OUT
-SD_CSDIR        .equ P2DIR
 
+SD_CD       .equ  20h           ; P2.5
+SD_CDIN     .equ  P2IN
 
 ; ----------------------------------------------------------------------
 ; POWER ON RESET AND INITIALIZATION : PORT3-4
 ; ----------------------------------------------------------------------
 
-          
-
-; P4.1  - SW1
-
 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
 
-; PORT3 usage
-            MOV.B #-1,&P3OUT  ; OUT1 for all pins
-            BIS.B #-1,&P3REN  ; all pins with pull resistors
-
-; P4.2  - UCA1 RXD    J101.8 -  <---- TX  UARTtoUSB bridge
-; P4.3  - UCA1 TXD    J101.6 -  <-+-> RX  UARTtoUSB bridge
-
-Deep_RST_IN .equ P4IN
-Deep_RST    .equ 8 ; = TX
-TERM_TXRX   .equ 0Ch
-TERM_SEL    .equ P4SEL0
+; PORTB usage
+
+;               P4.1    -   SW1
+; UCA1 RXD      P4.2    -   J101.8  <----   TX  UARTtoUSB bridge
+; UCA1 TXD      P4.3    -   J101.6  ---->   RX  UARTtoUSB bridge
+;               P4.4    -   J2.9    ---->   SD_CS(Card Select)
+; UCB1 CLK      P4.5    -   J1.7    ---->   SD_CLK
+; UCB1 SIMO     P4.6    -   J2.15   ---->   SD_SDI
+; UCB1 SOMI     P4.7    -   J2.14   <----   SD_SDO
+
+            MOV.B #-1,&PBOUT  ; pullup resistors for all pins
+            BIS.B #-1,&PBREN  ; all pins with pull resistors
+
+    .IFDEF UCA1_TERM
+; UCA1 RXD      P4.2    -   J101.8  <----   TX  UARTtoUSB bridge
+; UCA1 TXD      P4.3    -   J101.6  ---->   RX  UARTtoUSB bridge
+RXD         .equ 4      ; P4.2 = RXD
+TXD         .equ 8      ; P4.3 = TXD + FORTH Deep_RST pin
+TERM_BUS    .equ 0Ch
+TERM_IN     .equ P4IN
 TERM_REN    .equ P4REN
+TERM_SEL    .equ P4SEL0
+    .ENDIF
 
-; P4.4  -             J2.13  -  <---- SD_CD (Card Detect)
-SD_CD           .equ  10h
-SD_CDIN         .equ  P4IN
+    .IFDEF UCB1_SD
+SD_CS       .equ 10h    ; P4.4
+SD_CSOUT    .equ P4OUT
+SD_CSDIR    .equ P4DIR
 
-; P4.5  - UCB1 CLK    J1.7   -  ----> SD_CLK
-; P4.6  - UCB1 SIMO   J2.15  -  ----> SD_SDI
-; P4.7  - UCB1 SOMI   J2.14  -  <---- SD_SDO
-        
 SD_SEL      .equ PBSEL0 ; to configure UCB1
 SD_REN      .equ PBREN  ; to configure pullup resistors
 SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1SOMI
-
-
+    .ENDIF
 ; ----------------------------------------------------------------------
 ; POWER ON RESET AND INITIALIZATION : PORT5-6
 ; ----------------------------------------------------------------------
@@ -230,26 +231,21 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
 
 ; PORT6 usage
 
-; LED2 - P6.6   (green)
+;           P6.6    -   LED2 green
 
             BIS.B #0BFh,&P6REN  ; all pins with pull up resistors else P6.6
-            MOV.B #040h,&P6DIR
             MOV.B #0BFh,&P6OUT  ; OUT high for all pins else P6.6
-
+            MOV.B #040h,&P6DIR  ; all pins with pullup resistors else LED2 = output low
 
 ; ----------------------------------------------------------------------
 ; FRAM config
 ; ----------------------------------------------------------------------
 
-    .IF FREQUENCY = 16
-;NWAITS            = 1
+    .IF (FREQUENCY >8 ) && ( FREQUENCY <= 16)
             MOV.B   #0A5h, &FRCTL0_H     ; enable FRCTL0 access
             MOV.B   #10h, &FRCTL0         ; 1 waitstate @ 16 MHz
             MOV.B   #01h, &FRCTL0_H       ; disable FRCTL0 access
-    .ENDIF
-
-    .IF FREQUENCY = 24
-;NWAITS            = 2
+    .ELSEIF FREQUENCY > 16
             MOV.B   #0A5h, &FRCTL0_H     ; enable FRCTL0 access
             MOV.B   #20h, &FRCTL0         ; 2 waitstate @ 24 MHz
             MOV.B   #01h, &FRCTL0_H       ; disable FRCTL0 access
@@ -259,9 +255,7 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
 ; POWER ON RESET SYS config
 ; ----------------------------------------------------------------------
 
-; SYS code                                  
-;    BIC #1,&SYSCFG0 ; enable write program in FRAM
-    MOV #0A500h,&SYSCFG0 ; enable write MAIN and INFO
+    MOV #0A500h,&SYSCFG0    ; enable write MAIN + INFO
 
 ; ----------------------------------------------------------------------
 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
@@ -269,10 +263,13 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
 
 ; CS code for MSP430FR2355
 
-; to measure REFO frequency, output the ACLK on P1.1: 
+; to measure SMCLK frequency, wires SMCLK on P1.0: 
+;    BIS.B #1,&P1SEL1
+;    BIS.B #1,&P1DIR
+
+; to measure REFO frequency, wires ACLK on P1.1: 
 ;    BIS.B #2,&P1SEL1
 ;    BIS.B #2,&P1DIR
-; result : REFO = xx.xxx kHz
 
 
     .IF FREQUENCY = 0.5
@@ -348,8 +345,6 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
             MOV     #1EFFh,&CSCTL0       ; preset MOD=31, DCO=255  
             MOV     #00B6h,&CSCTL1      ; Set 8MHZ DCORSEL,enable DCOFTRIM=3h ,enable Modulation to reduce EMI
 ; ===================================== ;  fCOCLKDIV = REFO x (FLLN+1)
-;            MOV     #00F2h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=F2h
-                                        ; fCOCLKDIV = 32768 x (242+1) = 7.963 MHz ; measured : 7.943MHz
 ;            MOV     #00F3h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=F3h
                                         ; fCOCLKDIV = 32768 x (243+1) = 7.995 MHz ; measured : 7.976MHz
             MOV     #00F4h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=F4h
@@ -357,10 +352,6 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
 
 ;            MOV     #00F5h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=F5h
                                         ; fCOCLKDIV = 32768 x (245+1) = 8.061 MHz ; measured : 8.042MHz
-
-;            MOV     #00F8h,&CSCTL2      ; don't work with cp2102 (by low value)
-;            MOV     #00FAh,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=FAh
-
 ; =====================================
             MOV     #128,X
 
@@ -371,8 +362,6 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
             MOV     #1EFFh,&CSCTL0       ; preset MOD=31, DCO=255  
             MOV     #00B8h,&CSCTL1      ; Set 12MHZ DCORSEL,enable DCOFTRIM=3h ,enable Modulation to reduce EMI
 ; ===================================== ;  fCOCLKDIV = REFO x (FLLN+1)
-;            MOV     #016Ch,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=1E6h
-                                        ; fCOCLKDIV = 32768 x 364+1) = 12.960 MHz ; measured : 11.xxxMHz
 ;            MOV     #016Dh,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=1E7h
                                         ; fCOCLKDIV = 32768 x 365+1) = 11.993 MHz ; measured : 11.xxxMHz
             MOV     #016Eh,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=1E8h
@@ -389,8 +378,6 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
             MOV     #1EFFh,&CSCTL0       ; preset MOD=31, DCO=255  
             MOV     #00BAh,&CSCTL1      ; Set 16MHZ DCORSEL,enable DCOFTRIM=3h ,enable Modulation to reduce EMI
 ; ===================================== ;  fCOCLKDIV = REFO x (FLLN+1)
-;            MOV     #01E6h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=1E6h
-                                        ; fCOCLKDIV = 32768 x 486+1) = 15.958 MHz ; measured : 15.92MHz
 ;            MOV     #01E7h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=1E7h
                                         ; fCOCLKDIV = 32768 x 487+1) = 15.991 MHz ; measured : 15.95MHz
             MOV     #01E8h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=1E8h
@@ -407,8 +394,6 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
             MOV     #1EFFh,&CSCTL0       ; preset MOD=31, DCO=255  
             MOV     #00BCh,&CSCTL1      ; Set 20MHZ DCORSEL,enable DCOFTRIM=3h ,enable Modulation to reduce EMI
 ; ===================================== ;  fCOCLKDIV = REFO x (FLLN+1)
-;            MOV     #0260h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=260h
-                                        ; fCOCLKDIV = 32768 x 608+1) = 19.956 MHz ; measured : 19.xxxMHz
 ;            MOV     #0261h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=261h
                                         ; fCOCLKDIV = 32768 x 609+1) = 19.988 MHz ; measured : 19.xxxMHz
             MOV     #0262h,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=262h
@@ -425,8 +410,6 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
             MOV     #1EFFh,&CSCTL0       ; preset MOD=31, DCO=255  
             MOV     #00BEh,&CSCTL1      ; Set 24MHZ DCORSEL,enable DCOFTRIM=3h ,enable Modulation to reduce EMI
 ; ===================================== ;  fCOCLKDIV = REFO x (FLLN+1)
-;            MOV     #02DAh,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=2DAh
-                                        ; fCOCLKDIV = 32768 x 730+1) = 23.953 MHz ; measured : 23.xxxMHz
 ;            MOV     #02DBh,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=2DBh
                                         ; fCOCLKDIV = 32768 x 731+1) = 23.986 MHz ; measured : 23.xxxMHz
             MOV     #02DCh,&CSCTL2      ; Set FLLD=0 (DCOCLKCDIV=DCO),set FLLN=2DCh
@@ -449,9 +432,10 @@ SD_BUS      .equ 0E000h ; pins P4.5 as UCA1CLK, P4.6 as UCA1SIMO & P4.7 as UCA1S
     .ENDIF
 
             BIS &SYSRSTIV,&SAVE_SYSRSTIV; store volatile SYSRSTIV preserving a pending request for DEEP_RST
-            CMP #2,&SAVE_SYSRSTIV       ; POWER ON ?
-            JZ      ClockWaitX          ; yes
-            .word   0749h               ; no  RRUM #1,X --> wait anyway 250 ms because FLL lock time = 200 ms
+;            MOV &SAVE_SYSRSTIV,TOS  ;
+;            CMP #2,TOS              ; POWER ON ?
+;            JZ      ClockWaitX      ; yes
+;            RRUM    #1,X            ; wait only 250 ms
 ClockWaitX  MOV     #5209,Y             ; wait 0.5s before starting after POR
 
 ClockWaitY  SUB     #1,Y                ;1