OSDN Git Service

V201, added MSP-EXP430FR2433
[fast-forth/master.git] / MSP_EXP430FR5994.asm
1 ; -*- coding: utf-8 -*-
2 ; MSP_EXP430FR5994.inc
3
4 ; Fast Forth For Texas Instrument MSP430FR5994
5 ;
6 ; Copyright (C) <2014>  <J.M. THOORENS>
7 ;
8 ; This program is free software: you can redistribute it and/or modify
9 ; it under the terms of the GNU General Public License as published by
10 ; the Free Software Foundation, either version 3 of the License, or
11 ; (at your option) any later version.
12 ;
13 ; This program is distributed in the hope that it will be useful,
14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ; GNU General Public License for more details.
17 ;
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21
22 ; ======================================================================
23 ; MSP_EXP430FR5994 board
24 ; ======================================================================
25 ;
26 ; J101 Target     <---> eZ-FET
27 ; GND             14-13   GND
28 ; +5V             12-11
29 ; 3V3             10-9
30 ; P2.1 UCA0_RX     8-7         <---- TX   UARTtoUSB bridge
31 ;                                +--4k7-< DeepRST <-- GND
32 ;                                |            
33 ; P2.0 UCA0_TX     6-5         <-+-> RX   UARTtoUSB bridge
34 ; /RST             4-3
35 ; TEST             2-1
36 ;
37 ;
38 ; P5.6    - sw1                <--- LCD contrast + (finger :-)
39 ; P5.5    - sw2                <--- LCD contrast - (finger ;-)
40 ; RST     - sw3 
41 ;
42 ; P1.0    - led1 red
43 ; P1.1    - led2 green
44 ;
45 ; J1 - left ext.
46 ; 3v3
47 ; P1.2/TA1.1/TA0CLK/COUT/A2/C2 <--- OUT IR_Receiver (1 TSOP32236)     
48 ; P6.1/UCA3RXD/UCA3SOMI        ------------------------->  4 LCD_RS
49 ; P6.0/UCA3TXD/UCA3SIMO        ------------------------->  5 LCD_R/W
50 ; P6.2/UCA3CLK                 ------------------------->  6 LCD_EN0
51 ; P1.3/TA1.2/UCB0STE/A3/C3            
52 ; P5.2/UCB1CLK/TA4CLK
53 ; P6.3/UCA3STE
54 ; P7.1/UCB2SOMI/UCB2SCL        ---> SCL I2C MASTER/SLAVE
55 ; P7.0/UCB2SIMO/UCB2SDA        <--> SDA I2C MASTER/SLAVE
56 ;
57 ; J3 - left int.
58 ; 5V
59 ; GND
60 ; P3.0/A12/C12                 <------------------------> 11 LCD_DB4   
61 ; P3.1/A13/C13                 <------------------------> 12 LCD_DB5
62 ; P3.2/A14/C14                 <------------------------> 13 LCD_DB5
63 ; P3.3/A15/C15                 <------------------------> 14 LCD_DB7
64 ; P1.4/TB0.1/UCA0STE/A4/C4
65 ; P1.5/TB0.2/UCA0CLK/A5/C5     >---||--+--^/\/\/v--+---->  3 LCD_Vo (=0V6 without modulation)    
66 ; P4.7
67 ; P8.0
68 ;
69 ; J4 - right int.
70 ; P3.7/TB0.6                          
71 ; P3.6/TB0.5                          
72 ; P3.5/TB0.4/COUT                     
73 ; P3.4/TB0.3/SMCLK
74 ; P7.3/UCB2STE/TA4.1
75 ; P2.6/TB0.1/UCA1RXD/UCA1SOMI 
76 ; P2.5/TB0.0/UCA1TXD/UCA1SIMO 
77 ; P4.3/A11
78 ; P4.2/A10       RTS ----> CTS  UARTtoUSB bridge (optional hardware control flow)
79 ; P4.1/A9        CTS <---- RTS  UARTtoUSB bridge (optional hardware control flow)
80 ;
81 ; J2 - right ext.
82 ; GND
83 ; P5.7/UCA2STE/TA4.1/MCLK
84 ; P4.4/TB0.5
85 ; P5.3/UCB1STE
86 ; /RST
87 ; P5.0/UCB1SIMO/UCB1SDA
88 ; P5.1/UCB1SOMI/UCB1SCL
89 ; P8.3
90 ; P8.2                          <--> SDA I2C SOFTWARE MASTER
91 ; P8.1                          <--> SCL I2C SOFTWARE MASTER
92 ;
93 ; SD_CARD
94 ; P7.2/UCB2CLK                        <--- SD_CD
95 ; P1.6/TB0.3/UCB0SIMO/UCB0SDA/TA0.0   ---> SD_MOSI
96 ; P1.7/TB0.4/UCB0SOMI/UCB0SCL/TA1.0   <--- SD_MISO
97 ; P4.0/A8                             ---> SD_CS
98 ; P2.2/TB0.2/UCB0CLK                  ---> SD_CLK
99 ;
100 ; XTAL LF 32768 Hz
101 ; PJ.4/LFXIN
102 ; PJ.5/LFXOUT
103 ;
104 ; XTAL HF
105 ; PJ.6/HFXIN
106 ; PJ.7/HFXOUT
107
108
109 ; -----------------------------------------------
110 ; LCD config
111 ; -----------------------------------------------
112                                     
113 ;       <-------+---0V0---------->  1 LCD_Vss
114 ;       >------ | --3V6-----+---->  2 LCD_Vdd
115 ;               |           |
116 ;             |___    470n ---
117 ;               ^ |        ---
118 ;              / \ BAT54    |
119 ;              ---          |
120 ;          100n |    2k2    |
121 ; TB0.2 >---||--+--^/\/\/v--+---->  3 LCD_Vo (=0V6 without modulation)
122 ;       ------------------------->  4 LCD_RS
123 ;       ------------------------->  5 LCD_R/W
124 ;       ------------------------->  6 LCD_EN0
125 ;       <------------------------> 11 LCD_DB4
126 ;       <------------------------> 12 LCD_DB5
127 ;       <------------------------> 13 LCD_DB5
128 ;       <------------------------> 14 LCD_DB7
129
130
131
132 ; ----------------------------------------------------------------------
133 ; INIT order : LOCK I/O, WDT, GPIOs, FRAM, Clock, UARTs
134 ; ----------------------------------------------------------------------
135
136 ; ----------------------------------------------------------------------
137 ; POWER ON RESET AND INITIALIZATION : LOCK PMM_LOCKLPM5
138 ; ----------------------------------------------------------------------
139
140 ;              BIS     #LOCKLPM5,&PM5CTL0 ; unlocked by WARM
141
142 ; ----------------------------------------------------------------------
143 ; POWER ON RESET AND INITIALIZATION : WATCHDOG TIMER A
144 ; ----------------------------------------------------------------------
145
146         MOV #WDTPW+WDTHOLD+WDTCNTCL,&WDTCTL    ; stop WDT
147
148 ; ----------------------------------------------------------------------
149 ; POWER ON RESET AND INITIALIZATION : I/O
150 ; ----------------------------------------------------------------------
151
152 ; ----------------------------------------------------------------------
153 ; POWER ON RESET AND INITIALIZATION : PORT1/2
154 ; ----------------------------------------------------------------------
155
156 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
157
158 ; PORTA usage
159 SD_SEL      .equ PASEL1  ; word access, to configure UCB0
160 SD_REN      .equ PAREN   ; word access, to configure pullup resistors
161 SD_BUS      .equ 04C0h   ; pins P2.2 as UCB0CLK, P1.6 as UCB0SIMO & P1.7 as UCB0SOMI
162
163
164 ; PORT1 FastForth usage
165 ; P1.0    - led1 red
166 ; P1.1    - led2 green
167
168
169 ; PORT2 FastForth usage
170
171 Deep_RST_IN .equ P2IN   ; TERMINAL TX  pin as FORTH Deep_RST 
172 Deep_RST    .equ 2      ; P2.0 = TX
173 TERM_TXRX   .equ 003h   ; P2.1 = RX
174 TERM_SEL    .equ P2SEL1
175 TERM_REN    .equ P2REN
176
177 ; PORTx default wanted state : pins as input with pullup resistor
178
179             BIS #3,&PADIR       ; all pins 0 as input else LEDs
180             MOV #0FFFCh,&PAOUT  ; all pins high  else LEDs
181             BIC #3,&PAREN       ; all pins 1 with pull resistors else LEDs
182
183 ; ----------------------------------------------------------------------
184 ; POWER ON RESET AND INITIALIZATION : PORT3/4
185 ; ----------------------------------------------------------------------
186
187 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
188
189 ; PORT3 FastForth usage
190
191 ; PORT4 FastForth usage
192 SD_CS       .equ 1        ; P4.0 as SD_CS     
193 SD_CSOUT    .equ P4OUT
194 SD_CSDIR    .equ P4DIR
195
196
197
198     .IFDEF TERMINAL4WIRES
199
200 ; RTS output is wired to the CTS input of UART2USB bridge 
201 ; CTS is not used by FORTH terminal
202 ; configure RTS as output high to disable RX TERM during start FORTH
203
204 HANDSHAKOUT .equ  P4OUT
205 HANDSHAKIN  .equ  P4IN
206
207 RTS         .equ  4 ; P4.2
208
209             BIS     #00400h,&PBDIR  ; all pins as input else P4.2 (RTS)
210             BIS     #-1,&PBREN      ; all input pins with resistor
211
212         .IFDEF TERMINAL5WIRES
213
214 CTS         .equ  8 ; P4.3
215
216             MOV     #0F7FFh,&PBOUT  ; P4.2 (RTS) as output HIGH, P4.3 (CTS) I pull down, others I pull up, 
217
218         .ELSEIF
219
220             MOV     #-1,&PBOUT      ; P4.2 (RTS) as output HIGH, others I pull up, 
221
222         .ENDIF  ; TERMINAL5WIRES
223
224     .ELSEIF
225
226 ; PORTx default wanted state : pins as input with pullup resistor
227             MOV     #-1,&PBOUT   ; OUT1
228             BIS     #-1,&PBREN   ; REN1 all pullup resistors
229
230     .ENDIF  ; TERMINAL4WIRES
231
232 ; ----------------------------------------------------------------------
233 ; POWER ON RESET AND INITIALIZATION : PORT5/6
234 ; ----------------------------------------------------------------------
235
236 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
237
238 ; PORT5 FastForth usage
239 ; P5.6 Switch S1
240 ; P5.5 Switch S2
241 SWITCHIN    .set P5IN    ; port
242 s1          .set 020h    ; P5.5 bit position
243
244 ; PORT6 FastForth usage
245
246
247 ; PORTx default wanted state : pins as input with pullup resistor
248
249             MOV #-1,&PCOUT    ; all pins output high
250             BIS #-1,&PCREN    ; all pins with pull resistors
251
252 ; ----------------------------------------------------------------------
253 ; POWER ON RESET AND INITIALIZATION : PORT7/8
254 ; ----------------------------------------------------------------------
255
256 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
257
258 ; PORT7 FastForth usage
259 SD_CD       .equ 4        ; P7.2 as SD_CD
260 SD_CDIN     .equ P7IN
261
262
263 ; PORT8 FastForth usage
264
265
266 ; PORTx default wanted state : pins as input with pullup resistor
267
268             MOV #-1,&PDOUT    ; all pins output high
269             BIS #-1,&PDREN    ; all pins with pull resistors
270
271
272 ; ----------------------------------------------------------------------
273 ; POWER ON RESET AND INITIALIZATION : PORTJ
274 ; ----------------------------------------------------------------------
275
276 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
277
278 ; PORTJ FastForth usage
279
280 ; PORTx default wanted state : pins as input with pullup resistor
281
282             MOV.B #-1,&PJREN    ; enable pullup/pulldown resistors
283             BIS.B #-1,&PJOUT    ; pullup resistors
284
285
286 ; ----------------------------------------------------------------------
287 ; FRAM config
288 ; ----------------------------------------------------------------------
289
290     .IF FREQUENCY = 16
291             MOV.B   #0A5h, &FRCTL0_H     ; enable FRCTL0 access
292             MOV.B   #10h, &FRCTL0         ; 1 waitstate @ 16 MHz
293             MOV.B   #01h, &FRCTL0_H       ; disable FRCTL0 access
294     .ENDIF
295
296 ; ----------------------------------------------------------------------
297 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
298 ; ----------------------------------------------------------------------
299
300 ; DCOCLK: Internal digitally controlled oscillator (DCO).
301 ; Startup clock system in max. DCO setting ~8MHz
302
303
304 ; CS code for MSP430FR5969
305             MOV.B   #CSKEY,&CSCTL0_H ;  Unlock CS registers
306
307     .IF FREQUENCY = 0.25
308 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1      ; Set 8MHZ DCO setting (default value)
309             MOV     #DIVA_0 + DIVS_32 + DIVM_32,&CSCTL3
310             MOV     #4,X
311
312     .ELSEIF FREQUENCY = 0.5
313             MOV     #0,&CSCTL1                  ; Set 1MHZ DCO setting
314             MOV     #DIVA_2 + DIVS_2 + DIVM_2,&CSCTL3             ; set all dividers as 2
315             MOV     #4,X
316
317     .ELSEIF FREQUENCY = 1
318             MOV     #0,&CSCTL1                  ; Set 1MHZ DCO setting
319             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
320             MOV     #8,X
321
322     .ELSEIF FREQUENCY = 2
323             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1  ; Set 4MHZ DCO setting
324             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3
325             MOV     #16,X
326
327     .ELSEIF FREQUENCY = 4
328             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1  ; Set 4MHZ DCO setting
329             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
330             MOV     #32,X
331
332     .ELSEIF FREQUENCY = 8
333 ;            MOV     #DCOFSEL2+DCOFSEL1,&CSCTL1  ; Set 8MHZ DCO setting (default value)
334             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
335             MOV     #64,X
336
337     .ELSEIF FREQUENCY = 16
338             MOV     #DCORSEL+DCOFSEL2,&CSCTL1   ; Set 16MHZ DCO setting
339             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
340             MOV     #128,X
341
342     .ELSEIF
343     .error "bad frequency setting, only 0.5,1,2,4,8,16 MHz"
344     .ENDIF
345
346     .IFDEF LF_XTAL
347             MOV     #SELA_LFXCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
348     .ELSE
349             MOV     #SELA_VLOCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
350     .ENDIF
351             MOV.B   #01h, &CSCTL0_H                               ; Lock CS Registers
352
353             BIS &SYSRSTIV,&SAVE_SYSRSTIV; store volatile SYSRSTIV preserving a pending request for DEEP_RST
354             CMP #2,&SAVE_SYSRSTIV   ; POWER ON ?
355             JZ      ClockWaitX      ; yes
356             .word   0759h           ; no  RRUM #2,X --> wait only 125 ms
357 ClockWaitX  MOV     #41666,Y        ; wait 0.5s before starting after POWER ON
358 ClockWaitY  SUB     #1,Y            ;
359             JNZ     ClockWaitY      ; 41666x3 = 125000 cycles delay = 125ms @ 1MHz
360             SUB     #1,X            ; x 4 @ 1 MHZ
361             JNZ     ClockWaitX      ; time to stabilize power source ( 1s )
362
363 ; ----------------------------------------------------------------------
364 ; POWER ON RESET AND INITIALIZATION : REF
365 ; ----------------------------------------------------------------------
366
367             MOV   #8, &REFCTL
368
369 ; ----------------------------------------------------------------------
370 ; POWER ON RESET AND INITIALIZATION : RTC_C REGISTERS
371 ; ----------------------------------------------------------------------
372
373     .IFDEF LF_XTAL
374 ; LFXIN : PJ.4, LFXOUT : PJ.5
375     BIS.B   #010h,&PJSEL0   ; SEL0 for only LFXIN
376     MOV.B   #0A5h,&RTCCTL0_H ; unlock RTC_C
377     BIC.B   #RTCHOLD,&RTCCTL1 ; Clear RTCHOLD = start RTC_C
378     .ENDIF
379
380 ; ----------------------------------------------------------------------
381 ; POWER ON RESET AND INITIALIZATION : SYS REGISTERS
382 ; ----------------------------------------------------------------------
383
384 ; SYS code                                  
385 ; see COLD word
386