OSDN Git Service

V309
[fast-forth/master.git] / inc / MSP_EXP430FR5972.asm
1 ; -*- coding: utf-8 -*-
2
3 ; ======================================================================
4 ; INIT MSP-EXP430FR5972 virtual 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 ; Clocks:
94 ; 8 MHz DCO intern
95
96 ; ===================================================================================
97 ; in case of 3.3V powered by UARTtoUSB bridge, open J13 straps {RST,TST,V+,5V} BEFORE
98 ; then wire VCC and GND of bridge onto J13 connector
99 ; ===================================================================================
100
101 ; ---------------------------------------------------
102 ; MSP  - MSP-EXP430FR5972 virtual LAUNCHPAD <--> OUTPUT WORLD
103 ; ---------------------------------------------------
104 ; P1.0 - LED1 red
105 ; P9.7 - LED2 green
106
107 ; P1.1 - Switch S1              <--- LCD contrast + (finger :-)
108 ; P1.2 - Switch S2              <--- LCD contrast - (finger ;-)
109
110 ;  GND                          <-------+---0V0---------->  1 LCD_Vss
111 ;  VCC                          >------ | --3V3-----+---->  2 LCD_Vdd
112 ;                                       |           |
113 ;                                     |___    470n ---
114 ;                                       ^ |        ---
115 ;                                      / \ BAT54    |
116 ;                                      ---          |
117 ;                                  100n |    2k2    |
118 ; P3.6 - UCA1 CLK TB0.2         >---||--+--^/\/\/v--+---->  3 LCD_Vo (=0V6 without modulation)
119 ; P7.0/                         <------------------------> 11 LCD_DB4
120 ; P7.1/                         <------------------------> 12 LCD_DB5
121 ; P7.2/                         <------------------------> 13 LCD_DB5
122 ; P7.3/                         <------------------------> 14 LCD_DB7
123 ; P9.4/A12/C12                  ------------------------->  4 LCD_RS
124 ; P9.5/A13/C13                  ------------------------->  5 LCD_R/W
125 ; P9.6/A14/C14                  ------------------------->  6 LCD_EN
126
127 ;                                 +--4k7-< DeepRST <-- GND
128 ;                                 |
129 ; P3.4 - UCA1 TXD               <-+-> RX  UARTtoUSB bridge
130 ; P3.5 - UCA1 RXD               <---- TX  UARTtoUSB bridge
131 ; P3.0 - RTS                    ----> CTS UARTtoUSB bridge (optional hardware control flow)
132 ;  VCC -                        <---- VCC (optional supply from UARTtoUSB bridge - WARNING ! 3.3V !)
133 ;  GND -                        <---> GND (optional supply from UARTtoUSB bridge)
134
135 ;  VCC -                        ----> VCC SD_CardAdapter
136 ;  GND -                        <---> GND SD_CardAdapter
137 ; P2.2 -  UCA0 CLK              ----> CLK SD_CardAdapter (SCK)
138 ; P2.6 -                        ----> CS  SD_CardAdapter (Card Select)
139 ; P2.0 -  UCA0 TXD/SIMO         ----> SDI SD_CardAdapter (MOSI)
140 ; P2.1 -  UCA0 RXD/SOMI         <---- SDO SD_CardAdapter (MISO)
141 ; P2.7 -                        <---- CD  SD_CardAdapter (Card Detect)
142
143 ; P4.0 -                        <---- OUT IR_Receiver (1 TSOP32236)
144 ;  VCC -                        ----> VCC IR_Receiver (2 TSOP32236)
145 ;  GND -                        <---> GND IR_Receiver (3 TSOP32236)
146
147 ; P1.3 -                        <---> SDA software I2C Master
148 ; P1.5 -                        ----> SCL software I2C Master
149
150 ; P1.4 -UCB0 CLK TA1.0          <---> free
151
152 ; P1.6 -UCB0 SDA/SIMO           <---> SDA hardware I2C Master or Slave
153 ; P1.7 -UCB0 SCL/SOMI           ----> SCL hardware I2C Master or Slave
154
155 ; P3.0 -UCB1 CLK                ----> free (if UARTtoUSB with software control flow)
156 ; P3.1 -UCB1 SDA/SIMO           <---> free
157 ; P3.2 -UCB1 SCL/SOMI           ----> free
158 ; P3.3 -         TA1.1          <---> free
159
160 ; PJ.4 - LFXI 32768Hz quartz
161 ; PJ.5 - LFXO 32768Hz quartz
162 ; PJ.6 - HFXI
163 ; PJ.7 - HFXO
164
165
166 ; ----------------------------------------------------------------------
167 ; POWER ON RESET AND INITIALIZATION : I/O
168 ; ----------------------------------------------------------------------
169
170 ; ----------------------------------------------------------------------
171 ; POWER ON RESET AND INITIALIZATION : PORT1/2
172 ; ----------------------------------------------------------------------
173
174 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
175
176 ; PORTA usage
177     .IFDEF UCA0_SD
178 SD_SEL      .equ PASEL0 ; to configure UCB0
179 SD_REN      .equ PAREN  ; to configure pullup resistors
180 BUS_SD      .equ 0700h  ; pins P2.2 as UCA0CLK, P2.0 as UCA0SIMO & P2.1 as UCA0SOMI
181     .ENDIF ;UCA0_SD
182
183 ; PORT1 usage
184 ; P1.0 - LED1 red   output low
185 LED1_OUT    .equ    P1OUT
186 LED1_DIR    .equ    P1DIR
187 LED1        .equ    1       ;  P1.0 LED1 red
188
189 ; P1.1 - Switch S1
190 SW1_IN      .set P1IN       ; port
191 SW1         .set 2          ; P1.1 = S1
192
193 WIPE_IN     .equ    P1IN
194 IO_WIPE     .equ    2       ; P1.1 = S1 = FORTH Deep_RST pin
195
196 ; P1.2 - Switch S2
197 SW2_IN      .set P1IN       ; port
198 SW2         .set 4          ; P1.2 = S2
199
200 ; P1.6 -UCB0 SDA/SIMO   J2.15   <---> SDA hardware I2C Master or Slave
201 ; P1.7 -UCB0 SCL/SOMI   J2.14   ----> SCL hardware I2C Master or Slave
202     .IFDEF UCB0_TERM
203 TERM_IN     .equ    P1IN
204 TERM_SEL    .equ    P1SEL1
205 TERM_REN    .equ    P1REN
206 SDA         .equ    40h        ; P1.6 = SDA
207 SCL         .equ    80h        ; P1.7 = SCL
208 BUS_TERM    .equ    0C0h
209     .ENDIF
210
211
212
213 ; PORT2 usage
214
215 SD_CDIN     .equ P2IN
216 SD_CSOUT    .equ P2OUT
217 SD_CSDIR    .equ P2DIR
218 CS_SD       .equ 40h    ; P2.6 Chip Select
219 CD_SD       .equ 80h    ; P2.7 Card Detect
220
221 ; PORTx default wanted state : pins as input with pullup resistor
222
223             BIS     #-1,&PAREN     ; all pins with pull up/down resistor
224             MOV     #-2,&PAOUT    ; all pins with pullup resistors else P1.0
225
226 ; ----------------------------------------------------------------------
227 ; POWER ON RESET AND INITIALIZATION : PORT3/4
228 ; ----------------------------------------------------------------------
229
230 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
231 ; PORTx default wanted state : pins as input with pullup resistor
232
233 ; PORT3 usage
234 ; P3.0 = RTS
235 ; P3.1 = CTS
236 ; P3.4 = TX1
237 ; P3.5 = RX1
238
239 HANDSHAKOUT .equ    P3OUT
240 HANDSHAKIN  .equ    P3IN
241 RTS         .equ    1       ; P3.0
242 CTS         .equ    2       ; P3.1
243
244     .IFDEF UCA1_TERM
245 TERM_IN     .equ    P3IN   ;
246 TERM_REN    .equ    P3REN
247 TERM_SEL    .equ    P3SEL0
248 TXD         .equ    10h    ; P3.4 = TXD
249 RXD         .equ    20h    ; P3.4 = RXD
250 BUS_TERM    .equ    30h    ; P3.5 = RX
251     .ENDIF ;UCA1_TERM
252
253 ; PORT4 usage
254
255             MOV #-1,&PBREN  ; all pins as input with resistor
256             MOV #-1,&PBOUT  ; all pins as input with resistor
257
258     .IFDEF TERMINAL4WIRES
259 ; RTS output is wired to the CTS input of UART2USB bridge
260 ; configure RTS as output high to disable RX TERM during start FORTH
261             BIS.B #RTS,&P3DIR   ; RTS as output high
262         .IFDEF TERMINAL5WIRES
263 ; CTS input must be wired to the RTS output of UART2USB bridge
264 ; configure CTS as input low (true) to avoid lock when CTS is not wired
265             BIC.B #CTS,&P3OUT   ; CTS input pulled down
266         .ENDIF  ; TERMINAL5WIRES
267     .ENDIF  ; TERMINAL4WIRES
268
269 ; ----------------------------------------------------------------------
270 ; POWER ON RESET AND INITIALIZATION : PORT5/6
271 ; ----------------------------------------------------------------------
272
273 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
274
275 ; PORT5 usage
276
277 ; PORT6 usage
278
279 ; PORTx default wanted state : pins as input with pullup resistor
280
281             MOV     #-1,&PCREN    ; all pins with pull resistors
282             MOV     #-1,&PCOUT    ; all pins 1
283
284
285 ; ----------------------------------------------------------------------
286 ; POWER ON RESET AND INITIALIZATION : PORT7
287 ; ----------------------------------------------------------------------
288
289 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
290
291 ; PORT7 usage
292
293 ; PORT8 usage
294
295 ; PORTx default wanted state : pins as input with pullup resistor
296
297             MOV.B   #-1,&P7REN    ; all pins with pull resistors
298             MOV.B   #-1,&P7OUT    ; all pins 1
299
300
301
302 ; ----------------------------------------------------------------------
303 ; POWER ON RESET AND INITIALIZATION : PORT9
304 ; ----------------------------------------------------------------------
305
306 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
307
308 ; PORT9 usage
309 ; P9.7 Green LED2 as output low
310 LED2_OUT    .equ    P9OUT
311 LED2_DIR    .equ    P9DIR
312 LED2        .equ    80h        ;  P9.7 LED2 green
313
314
315 ; PORT10 usage
316
317 ; PORTx default wanted state : pins as input with pullup resistor
318
319             MOV.B   #-1,&P9REN  ; all pins with pull resistors else P9.7
320             MOV.B   #7Fh,&P9OUT ; all pins high else P9.7
321
322 ; ----------------------------------------------------------------------
323 ; POWER ON RESET AND INITIALIZATION : PORTJ
324 ; ----------------------------------------------------------------------
325
326 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
327
328 ; PORTJ usage
329
330 ; PORTx default wanted state : pins as input with pullup resistor
331
332             MOV.B   #-1,&PJREN    ; enable pullup/pulldown resistors
333             MOV.B   #-1,&PJOUT    ; pullup resistors
334
335 ; ----------------------------------------------------------------------
336 ; FRAM config
337 ; ----------------------------------------------------------------------
338
339     .IF  FREQUENCY > 8
340             MOV.B   #0A5h, &FRCTL0_H     ; enable FRCTL0 access
341             MOV.B   #10h, &FRCTL0         ; 1 waitstate @ 16 MHz
342             MOV.B   #01h, &FRCTL0_H       ; disable FRCTL0 access
343     .ENDIF
344
345 ; ----------------------------------------------------------------------
346 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
347 ; ----------------------------------------------------------------------
348
349 ; DCOCLK: Internal digitally controlled oscillator (DCO).
350
351             MOV.B   #CSKEY,&CSCTL0_H    ;  Unlock CS registers
352     .IF FREQUENCY = 0.25
353 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1         ; Set 8MHZ DCO setting (default value)
354             MOV     #DIVA_0 + DIVS_32 + DIVM_32,&CSCTL3
355
356     .ELSEIF FREQUENCY = 0.5
357             MOV     #0,&CSCTL1                          ; Set 1MHZ DCO setting
358             MOV     #DIVA_2 + DIVS_2 + DIVM_2,&CSCTL3   ; set all dividers as 2
359
360     .ELSEIF FREQUENCY = 1
361             MOV     #0,&CSCTL1                          ; Set 1MHZ DCO setting
362             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
363
364     .ELSEIF FREQUENCY = 2
365             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1          ; Set 4MHZ DCO setting
366             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3
367
368     .ELSEIF FREQUENCY = 4
369             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1          ; Set 4MHZ DCO setting
370             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
371
372     .ELSEIF FREQUENCY = 8
373 ;            MOV     #DCOFSEL2+DCOFSEL1,&CSCTL1         ; Set 8MHZ DCO setting (default value)
374             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
375
376     .ELSEIF FREQUENCY = 12
377             MOV     #DCORSEL+DCOFSEL2+DCOFSEL1,&CSCTL1  ; Set 24MHZ DCO setting
378             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3   ;
379
380     .ELSEIF FREQUENCY = 16
381             MOV     #DCORSEL+DCOFSEL2,&CSCTL1           ; Set 16MHZ DCO setting
382             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
383
384     .ELSEIF
385     .error "bad frequency setting, only 0.5,1,2,4,8,12,16 MHz"
386     .ENDIF
387
388     .IFDEF LF_XTAL
389             MOV     #SELA_LFXCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
390     .ELSE
391             MOV     #SELA_VLOCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
392     .ENDIF
393             MOV.B   #01h, &CSCTL0_H                               ; Lock CS Registers
394
395             MOV     #64,X           ; 64* 3 ms = 192 ms delay (by default of specification)
396 ClockWaitX  MOV     &FREQ_KHZ,Y     ;
397 ClockWaitY  SUB     #1,Y            ;1
398             JNZ     ClockWaitY      ;2 FREQ_KHZ x 3~ ==> 3ms
399             SUB     #1,X            ;
400             JNZ     ClockWaitX      ;
401
402 ; ----------------------------------------------------------------------
403 ; POWER ON RESET AND INITIALIZATION : REF
404 ; ----------------------------------------------------------------------
405
406             MOV   #REFTCOFF, &REFCTL
407
408 ; ----------------------------------------------------------------------
409 ; POWER ON RESET AND INITIALIZATION : RTC_C REGISTERS
410 ; ----------------------------------------------------------------------
411
412     .IFDEF LF_XTAL
413 ; LFXIN : PJ.4, LFXOUT : PJ.5
414     BIS.B   #010h,&PJSEL0   ; SEL0 for only LXIN
415     BIC.B   #RTCHOLD,&RTCCTL1 ; Clear RTCHOLD = start RTC_B
416     .ENDIF
417