OSDN Git Service

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