OSDN Git Service

53cf5d13ecbfd48922e3cafcd4d1c940de8241ba
[fast-forth/master.git] / inc / MSP_EXP430FR6989.asm
1 ; -*- coding: utf-8 -*-
2
3 ; ======================================================================
4 ; INIT MSP-EXP430FR6989 board
5 ; ======================================================================
6
7 ; my USBtoUart :
8 ; http://www.ebay.fr/itm/CP2102-USB-UART-Board-mini-Data-Transfer-Convertor-Module-Development-Board-/251433941479
9
10 ; for sd card socket be carefull : pin CD must be present !
11 ; http://www.ebay.com/itm/2-PCS-SD-Card-Module-Slot-Socket-Reader-For-Arduino-MCU-/181211954262?pt=LH_DefaultDomain_0&hash=item2a3112fc56
12
13
14 ; J101   eZ-FET <-> target
15 ; -----------------------
16 ; P1 <-> P2 - NC
17 ; P3 <-> P4 - TEST  - TEST
18 ; P5 <-> P6 - RST   - RST
19 ; P7 <-> P8 - TX1   - P3.4 UCA1 TXD ---> RX UARTtoUSB module
20 ; P9 <->P10 - RX1   - P3.5 UCA1 RXD <--- TX UARTtoUSB module
21 ; P11<->P12 - CTS   - P3.1
22 ; P13<->P14 - RTS   - P3.0
23 ; P15<->P16 - VCC   - 3V3
24 ; P17<->P18 - 5V
25 ; P19<->P20 - GND   - VSS
26
27 ; Launchpad Header Left J1
28 ; ------------------------
29 ; P1 - 3V3
30 ; P2 - P9.2 ESICH2
31 ; P3 - P4.3 UCA0 RXD
32 ; P4 - P4.2 UCA0 TXD
33 ; P5 - P3.2 UCB1 SCL
34 ; P6 - P9.3 ESICH3
35 ; P7 - P1.4 UCB0 CLK
36 ; P8 - P2.0 TB0.6
37 ; P9 - P4.1 UCB1 SCL
38 ; P10- P4.0 UCB1 SDA
39
40 ; Launchpad Header Left J3
41 ; ------------------------
42 ; P21 - 5V0
43 ; P22 - GND
44 ; P23 - P8.4 A7
45 ; P24 - P8.5 A6
46 ; P25 - P8.6 A5
47 ; P26 - P8.7 A4
48 ; P27 - P9.0 A8
49 ; P28 - P9.1 A9
50 ; P29 - P9.5 A13
51 ; P30 - P9.6 A14
52
53 ; Launchpad Header Right J2
54 ; -------------------------
55 ; P20- GND
56 ; P19- P2.1 TB0.5
57 ; P18- P1.5 TA0.0 UCA0 CLK
58 ; P17- P9.4 ESIC10
59 ; P16- RST
60 ; P15- P1.6 UCB0 SDA
61 ; P14- P1.7 UCB0 SCL
62 ; P13- P2.5 TB0.4
63 ; P12- P2.4 TB0.3
64 ; P11- P4.7 TA1.2 UCB1 SOMI/SCL
65
66 ; Launchpad Header Right J4
67 ; -------------------------
68 ; P40- P2.7 TB0.6
69 ; P39- P2.6 TB0.5
70 ; P38- P3.3 TA1.1
71 ; P37- P3.6 TB0.2
72 ; P36- P3.7 TB0.3
73 ; P35- P2.2 UCA0 CLK
74 ; P34- P1.3 TA1.2
75 ; P33- P3.0 UCB1 CLK
76 ; P32- P3.1 UCB1 SIMO/SDA
77 ; P31- P2.3
78
79
80 ; switch-keys:
81 ; S1 - P1.1
82 ; S2 - P1.2
83 ; S3 - RST
84
85 ; LEDS:
86 ; LED1 - J7 - P1.0
87 ; LED2 - J8 - P9.7
88
89 ; XTAL LF 32768 Hz
90 ; Y4 - PJ.4
91 ; Y4 - PJ.5
92
93 ; LCD
94 ; 1  - P8.3
95 ; 2  - P8.2
96 ; 3  - P8.1
97 ; 4  - P8.0
98 ; 5  - P5.6
99 ; 6  - P5.5
100 ; 7  - P5.4
101 ; 8  - P7.1
102 ; 9  - P4.6
103 ; 10 - P4.5
104 ; 11 - P4.4
105 ; 12 - P5.7
106 ; 13 - P5.2
107 ; 14 - P5.1
108 ; 15 - P5.8
109 ; 16 - P10.2
110 ; 17 - P10.1
111 ; 18 - P7.6
112 ; 19 - P7.5
113 ; 20 - P6.7
114 ; 21 - P6.6
115 ; 22 - P6.5
116 ; 23 - P6.4
117 ; 24 - P6.3
118 ; 25 - NC
119 ; 26 - NC
120 ; 27 - NC
121 ; 28 - NC
122 ; 29 - NC
123 ; 30 - NC
124 ; 31 - NC
125 ; 32 - P10.0
126 ; 33 - P7.7
127 ; 34 - P5.3
128 ; 35 - P7.3
129 ; 36 - P7.2
130 ; 37 - P7.1
131 ; 38 - P7.0
132
133
134 ; Clocks:
135 ; 8 MHz DCO intern
136
137
138
139 ; ===================================================================================
140 ; in case of 3.3V powered by UARTtoUSB bridge, open J13 straps {RST,TST,V+,5V} BEFORE
141 ; then wire VCC and GND of bridge onto J13 connector
142 ; ===================================================================================
143
144 ; ---------------------------------------------------
145 ; MSP  - MSP-EXP430FR6989 LAUNCHPAD <--> OUTPUT WORLD
146 ; ---------------------------------------------------
147 ; P1.0 - LED1 red
148 ; P9.7 - LED2 green
149
150 ; P1.1 - Switch S1              <--- LCD contrast + (finger :-)
151 ; P1.2 - Switch S2              <--- LCD contrast - (finger ;-)
152
153 ; note : ESI1.1 = lowest left pin
154 ; note : ESI1.2 is not connected to 3.3V
155 ;  GND/ESIVSS -          ESI1.3 <-------+---0V0---------->  1 LCD_Vss
156 ;  VCC/ESIVCC -          ESI1.4 >------ | --3V3-----+---->  2 LCD_Vdd
157 ;                                       |           |
158 ;                                     |___    470n ---
159 ;                                       ^ |        ---
160 ;                                      / \ BAT54    |
161 ;                                      ---          |
162 ;                                  100n |    2k2    |
163 ; P3.6 - UCA1 CLK TB0.2 J4.37   >---||--+--^/\/\/v--+---->  3 LCD_Vo (=0V6 without modulation)
164 ; P9.0/ESICH0 -         ESI1.14 <------------------------> 11 LCD_DB4
165 ; P9.1/ESICH1 -         ESI1.13 <------------------------> 12 LCD_DB5
166 ; P9.2/ESICH2 -         ESI1.12 <------------------------> 13 LCD_DB5
167 ; P9.3/ESICH3 -         ESI1.11 <------------------------> 14 LCD_DB7
168 ; P9.4/ESICI0 -         ESI1.10 ------------------------->  4 LCD_RS
169 ; P9.5/ESICI1 -         ESI1.9  ------------------------->  5 LCD_R/W
170 ; P9.6/ESICI2 -         ESI1.8  ------------------------->  6 LCD_EN
171
172 ;                                 +--4k7-< DeepRST <-- GND
173 ;                                 |
174 ; P3.4 - UCA1 TXD       J101.8  <-+-> RX  UARTtoUSB bridge
175 ; P3.5 - UCA1 RXD       J101.10 <---- TX  UARTtoUSB bridge
176 ; P3.0 - RTS            J101.14 ----> CTS UARTtoUSB bridge (optional hardware control flow)
177 ;  VCC -                J101.16 <---- VCC (optional supply from UARTtoUSB bridge - WARNING ! 3.3V !)
178 ;  GND -                J101.20 <---> GND (optional supply from UARTtoUSB bridge)
179
180 ;  VCC -                J1.1    ----> VCC SD_CardAdapter
181 ;  GND -                J2.20   <---> GND SD_CardAdapter
182 ; P2.2 -  UCA0 CLK      J4.35   ----> CLK SD_CardAdapter (SCK)
183 ; P2.6 -                J4.39   ----> CS  SD_CardAdapter (Card Select)
184 ; P2.0 -  UCA0 TXD/SIMO J1.8    ----> SDI SD_CardAdapter (MOSI)
185 ; P2.1 -  UCA0 RXD/SOMI J2.19   <---- SDO SD_CardAdapter (MISO)
186 ; P2.7 -                J4.40   <---- CD  SD_CardAdapter (Card Detect)
187
188 ; P4.0 -                J1.10   <---- OUT IR_Receiver (1 TSOP32236)
189 ;  VCC -                J6.1    ----> VCC IR_Receiver (2 TSOP32236)
190 ;  GND -                J6.2    <---> GND IR_Receiver (3 TSOP32236)
191
192 ; P1.3 -                J4.34   <---> SDA software I2C Master
193 ; P1.5 -                J2.18   ----> SCL software I2C Master
194
195 ; P1.4 -UCB0 CLK TA1.0  J1.7    <---> free
196
197 ; P1.6 -UCB0 SDA/SIMO   J2.15   <---> SDA hardware I2C Master or Slave
198 ; P1.7 -UCB0 SCL/SOMI   J2.14   ----> SCL hardware I2C Master or Slave
199
200 ; P3.0 -UCB1 CLK        J4.33   ----> free (if UARTtoUSB with software control flow)
201 ; P3.1 -UCB1 SDA/SIMO   J4.32   <---> free
202 ; P3.2 -UCB1 SCL/SOMI   J1.5    ----> free
203 ; P3.3 -         TA1.1  J1.5    <---> free
204
205 ; PJ.4 - LFXI 32768Hz quartz
206 ; PJ.5 - LFXO 32768Hz quartz
207 ; PJ.6 - HFXI
208 ; PJ.7 - HFXO
209
210
211 ; ----------------------------------------------------------------------
212 ; POWER ON RESET AND INITIALIZATION : I/O
213 ; ----------------------------------------------------------------------
214
215 ; ----------------------------------------------------------------------
216 ; POWER ON RESET AND INITIALIZATION : PORT1/2
217 ; ----------------------------------------------------------------------
218
219 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
220
221 ; PORTA usage
222     .IFDEF UCA0_SD
223 SD_SEL      .equ PASEL0 ; to configure UCB0
224 SD_REN      .equ PAREN  ; to configure pullup resistors
225 BUS_SD      .equ 0700h  ; pins P2.2 as UCA0CLK, P2.0 as UCA0SIMO & P2.1 as UCA0SOMI
226     .ENDIF ;UCA0_SD
227
228 ; PORT1 usage
229 ; P1.0 - LED1 red   output low
230 LED1_OUT    .equ    P1OUT
231 LED1_DIR    .equ    P1DIR
232 LED1        .equ    1       ;  P1.0 LED1 red
233
234 ; P1.1 - Switch S1
235 SW1_IN      .set P1IN       ; port
236 SW1         .set 2          ; P1.1 = S1
237
238 ; P1.2 - Switch S2
239 SW2_IN      .set P1IN       ; port
240 SW2         .set 4          ; P1.2 = S2
241
242 ; P1.6 -UCB0 SDA/SIMO   J2.15   <---> SDA hardware I2C Master or Slave
243 ; P1.7 -UCB0 SCL/SOMI   J2.14   ----> SCL hardware I2C Master or Slave
244     .IFDEF UCB0_TERM
245 TERM_IN     .equ    P1IN
246 TERM_SEL    .equ    P1SEL1
247 TERM_REN    .equ    P1REN
248 SDA         .equ    40h        ; P1.6 = SDA
249 SCL         .equ    80h        ; P1.7 = SCL
250 BUS_TERM    .equ    0C0h
251     .ENDIF
252
253
254
255 ; PORT2 usage
256
257 SD_CDIN     .equ P2IN
258 SD_CSOUT    .equ P2OUT
259 SD_CSDIR    .equ P2DIR
260 CS_SD       .equ 40h    ; P2.6 Chip Select
261 CD_SD       .equ 80h    ; P2.7 Card Detect
262
263 ; PORTx default wanted state : pins as input with pullup resistor
264
265             BIS     #-1,&PAREN     ; all pins with pull up/down resistor
266             MOV     #-2,&PAOUT    ; all pins with pullup resistors else P1.0
267
268 ; ----------------------------------------------------------------------
269 ; POWER ON RESET AND INITIALIZATION : PORT3/4
270 ; ----------------------------------------------------------------------
271
272 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
273 ; PORTx default wanted state : pins as input with pullup resistor
274
275 ; PORT3 usage
276 ; P3.0 = RTS
277 ; P3.1 = CTS
278 ; P3.4 = TX1
279 ; P3.5 = RX1
280
281 HANDSHAKOUT .equ    P3OUT
282 HANDSHAKIN  .equ    P3IN
283 RTS         .equ    1       ; P3.0
284 CTS         .equ    2       ; P3.1
285
286     .IFDEF UCA1_TERM
287 TERM_IN     .equ    P3IN   ;
288 TERM_REN    .equ    P3REN
289 TERM_SEL    .equ    P3SEL0
290 TXD         .equ    10h    ; P3.4 = TXD
291 RXD         .equ    20h    ; P3.5 = RXD
292 BUS_TERM    .equ    30h    ;
293     .ENDIF ;UCA1_TERM
294
295 ; PORT4 usage
296
297             MOV #-1,&PBREN  ; all pins as input with resistor
298             MOV #-1,&PBOUT  ; all pins as input with resistor
299
300     .IFDEF TERMINAL4WIRES
301 ; RTS output is wired to the CTS input of UART2USB bridge
302 ; configure RTS as output high to disable RX TERM during start FORTH
303             BIS.B #RTS,&P3DIR   ; RTS as output high
304         .IFDEF TERMINAL5WIRES
305 ; CTS input must be wired to the RTS output of UART2USB bridge
306 ; configure CTS as input low (true) to avoid lock when CTS is not wired
307             BIC.B #CTS,&P3OUT   ; CTS input pulled down
308         .ENDIF  ; TERMINAL5WIRES
309     .ENDIF  ; TERMINAL4WIRES
310
311 ; ----------------------------------------------------------------------
312 ; POWER ON RESET AND INITIALIZATION : PORT5/6
313 ; ----------------------------------------------------------------------
314
315 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
316
317 ; PORT5 usage
318
319 ; PORT6 usage
320
321 ; PORTx default wanted state : pins as input with pullup resistor
322
323             MOV     #-1,&PCREN    ; all pins with pull resistors
324             MOV     #-1,&PCOUT    ; all pins 1
325
326
327 ; ----------------------------------------------------------------------
328 ; POWER ON RESET AND INITIALIZATION : PORT7/8
329 ; ----------------------------------------------------------------------
330
331 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
332
333 ; PORT7 usage
334
335 ; PORT8 usage
336
337 ; PORTx default wanted state : pins as input with pullup resistor
338
339             MOV     #-1,&PDREN    ; all pins with pull resistors
340             MOV     #-1,&PDOUT    ; all pins 1
341
342
343
344 ; ----------------------------------------------------------------------
345 ; POWER ON RESET AND INITIALIZATION : PORT9/10
346 ; ----------------------------------------------------------------------
347
348 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
349
350 ; PORT9 usage
351 ; P9.7 Green LED2 as output low
352 LED2_OUT    .equ    P9OUT
353 LED2_DIR    .equ    P9DIR
354 LED2        .equ    80h        ;  P9.7 LED2 green
355
356
357 ; PORT10 usage
358
359 ; PORTx default wanted state : pins as input with pullup resistor
360
361             MOV     #-1,&PEREN    ; all pins with pull resistors else P9.7
362             MOV     #0FF7Fh,&PEOUT    ; all pins high else P9.7
363
364 ; ----------------------------------------------------------------------
365 ; POWER ON RESET AND INITIALIZATION : PORTJ
366 ; ----------------------------------------------------------------------
367
368 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
369
370 ; PORTJ usage
371
372 ; PORTx default wanted state : pins as input with pullup resistor
373
374             MOV.B   #-1,&PJREN    ; enable pullup/pulldown resistors
375             MOV.B   #-1,&PJOUT    ; pullup resistors
376
377 ; ----------------------------------------------------------------------
378 ; FRAM config
379 ; ----------------------------------------------------------------------
380
381     .IF  FREQUENCY > 8
382             MOV.B   #0A5h, &FRCTL0_H     ; enable FRCTL0 access
383             MOV.B   #10h, &FRCTL0         ; 1 waitstate @ 16 MHz
384             MOV.B   #01h, &FRCTL0_H       ; disable FRCTL0 access
385     .ENDIF
386
387 ; ----------------------------------------------------------------------
388 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
389 ; ----------------------------------------------------------------------
390
391 ; DCOCLK: Internal digitally controlled oscillator (DCO).
392
393             MOV.B   #CSKEY,&CSCTL0_H    ;  Unlock CS registers
394     .IF FREQUENCY = 0.25
395 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1         ; Set 8MHZ DCO setting (default value)
396             MOV     #DIVA_0 + DIVS_32 + DIVM_32,&CSCTL3
397
398     .ELSEIF FREQUENCY = 0.5
399             MOV     #0,&CSCTL1                          ; Set 1MHZ DCO setting
400             MOV     #DIVA_2 + DIVS_2 + DIVM_2,&CSCTL3   ; set all dividers as 2
401
402     .ELSEIF FREQUENCY = 1
403             MOV     #0,&CSCTL1                          ; Set 1MHZ DCO setting
404             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
405
406     .ELSEIF FREQUENCY = 2
407             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1          ; Set 4MHZ DCO setting
408             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3
409
410     .ELSEIF FREQUENCY = 4
411             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1          ; Set 4MHZ DCO setting
412             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
413
414     .ELSEIF FREQUENCY = 8
415 ;            MOV     #DCOFSEL2+DCOFSEL1,&CSCTL1         ; Set 8MHZ DCO setting (default value)
416             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
417
418     .ELSEIF FREQUENCY = 12
419             MOV     #DCORSEL+DCOFSEL2+DCOFSEL1,&CSCTL1  ; Set 24MHZ DCO setting
420             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3   ;
421
422     .ELSEIF FREQUENCY = 16
423             MOV     #DCORSEL+DCOFSEL2,&CSCTL1           ; Set 16MHZ DCO setting
424             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
425
426     .ELSEIF
427     .error "bad frequency setting, only 0.5,1,2,4,8,12,16 MHz"
428     .ENDIF
429
430     .IFDEF LF_XTAL
431             MOV     #SELA_LFXCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
432     .ELSE
433             MOV     #SELA_VLOCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
434     .ENDIF
435             MOV.B   #01h, &CSCTL0_H                               ; Lock CS Registers
436
437             MOV     #64,X           ; 64* 3 ms = 192 ms delay (by default of specification)
438 ClockWaitX  MOV     &FREQ_KHZ,Y     ;
439 ClockWaitY  SUB     #1,Y            ;1
440             JNZ     ClockWaitY      ;2 FREQ_KHZ x 3~ ==> 3ms
441             SUB     #1,X            ;
442             JNZ     ClockWaitX      ;
443
444 ; ----------------------------------------------------------------------
445 ; POWER ON RESET AND INITIALIZATION : REF
446 ; ----------------------------------------------------------------------
447
448             MOV   #REFTCOFF, &REFCTL
449
450 ; ----------------------------------------------------------------------
451 ; POWER ON RESET AND INITIALIZATION : RTC_C REGISTERS
452 ; ----------------------------------------------------------------------
453
454     .IFDEF LF_XTAL
455 ; LFXIN : PJ.4, LFXOUT : PJ.5
456     BIS.B   #010h,&PJSEL0   ; SEL0 for only LXIN
457     BIC.B   #RTCHOLD,&RTCCTL1 ; Clear RTCHOLD = start RTC_B
458     .ENDIF
459