OSDN Git Service

improve pat files
[fast-forth/master.git] / MSP_EXP430FR5969.asm
1 ; -*- coding: utf-8 -*-
2 ; MSP-EXP430FR5969.inc
3
4 ; Fast Forth For Texas Instrument MSP430FR5969
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 ; ======================================================================
24 ; INIT MSP-EXP430FR5969 board
25 ; ======================================================================
26
27 ;
28 ; J21 : external target
29 ; ---------------------
30 ; P1 - RX0  - P2.1
31 ; P2 - VCC
32 ; P3 - TEST - TEST
33 ; P4 - RST  - RST
34 ; P5 - GND
35 ; P6 - TX0  - P2.0
36
37
38 ; J3: JTAG
39 ; --------
40 ; P1 - TDO  - PJ.0
41 ; P2 - V_debug
42 ; P3 - TDI  - PJ.1
43 ; P4 - V_ext
44 ; P5 - TMS  - PJ.2
45 ; P6 - NC
46 ; P7 - TCK  - PJ.3
47 ; P8 - TEST - TEST
48 ; P9 - GND
49 ; P10- CTS  - P4.0
50 ; P11- RST  - RESET
51 ; P12- TX0  - P2.0
52 ; P13- RTS  - P4.1
53 ; P14- RX0  - P2.1
54
55
56 ; J13   eZ-FET <-> target
57 ; -----------------------
58 ; P1 <-> P2 - NC
59 ; P3 <-> P4 - TEST  - TEST
60 ; P5 <-> P6 - RST   - RST
61 ; P7 <-> P8 - TX0   - P2.0 ---> RX UARTtoUSB
62 ; P9 <->P10 - RX0   - P2.1 <--- TX UARTtoUSB
63 ; P11<->P12 - CTS   - P4.0
64 ; P13<->P14 - RTS   - P4.1
65 ; P15<->P16 - VCC   - VDD
66 ; P17<->P18 - 5V
67 ; P19<->P20 - GND   - VSS
68
69 ; Launchpad Header Left J4
70 ; ------------------------
71 ; P1 - VCC
72 ; P2 - P4.2
73 ; P3 - P2.6 UCA1 RX/SOMI ---> SD_SDO
74 ; P4 - P2.5 UCA1 TX/SIMO <--- SD_SDI
75 ; P5 - P4.3              ---> SD_SS
76 ; P6 - P2.4 UCA1     CLK ---> SD_CLK
77 ; P7 - P2.2 TB0.2 UCB0CLK
78 ; P8 - P3.4
79 ; P9 - P3.5
80 ; P10- P3.6
81
82 ; Launchpad Header Right J5
83 ; -------------------------
84 ; P11- P1.3
85 ; P12- P1.4
86 ; P13- P1.5
87 ; P14- P1.6  UCB0 SIMO/SDA
88 ; P15- P1.7  UCB0 SOMI/SCL
89 ; P16- RST
90 ; P17- NC
91 ; P18- P3.0
92 ; P19- P1.2
93 ; P20- GND
94
95
96 ; switch-keys:
97 ; S1 - P4.5
98 ; S2 - P1.1
99 ; S3 - RST
100
101 ; LEDS:
102 ; LED1 - J6 - P4.6
103 ; LED2 -      P1.0
104
105 ; XTAL LF 32768 Hz
106 ; Y4 - PJ.4
107 ; Y4 - PJ.5
108
109 ; XTAL HF
110 ; Y1 - PJ.6
111 ; Y1 - PJ.7
112
113 ; Clocks:
114 ; 8 MHz DCO intern
115
116
117
118 ; ===================================================================================
119 ; in case of 3.3V powered by UARTtoUSB bridge, open J13 straps {RST,TST,V+,5V} BEFORE
120 ; ===================================================================================
121
122 ; -----------------------------------------------
123 ; MSP430FR5969        LAUNCHPAD <--> OUTPUT WORLD
124 ; -----------------------------------------------
125 ; P4.6 - J6 - LED1 red
126 ; P1.0 - LED2 green
127
128 ; P4.5 - Switch S1              <--- LCD contrast + (finger :-)
129 ; P1.1 - Switch S2              <--- LCD contrast - (finger ;-)
130                                     
131 ;  GND -                 J1.2   <-------+---0V0---------->  1 LCD_Vss
132 ;  VCC -                 J1.3   >------ | --3V6-----+---->  2 LCD_Vdd
133 ;                                       |           |
134 ;                                     |___    470n ---
135 ;                                       ^ |        ---
136 ;                                      / \ BAT54    |
137 ;                                      ---          |
138 ;                                  100n |    2k2    |
139 ; P2.2 - UCB0 CLK TB0.2  J4.7   >---||--+--^/\/\/v--+---->  3 LCD_Vo (=0V6 without modulation)
140 ; P3.4 -                 J4.8   ------------------------->  4 LCD_RS
141 ; P3.5 -                 J4.9   ------------------------->  5 LCD_R/W
142 ; P3.6 -                 J4.10  ------------------------->  6 LCD_EN0
143 ; PJ.0 -                 J3.1   <------------------------> 11 LCD_DB4
144 ; PJ.1 -                 J3.3   <------------------------> 12 LCD_DB5
145 ; PJ.2 -                 J3.5   <------------------------> 13 LCD_DB5
146 ; PJ.3 -                 J3.7   <------------------------> 14 LCD_DB7
147          
148 ;                                 +--4k7-< DeepRST <-- GND 
149 ;                                 |
150 ; P2.0 - UCA0 TXD        J13.8  <-+-> RX   UARTtoUSB bridge
151 ; P2.1 - UCA0 RXD        J13.10 <---- TX   UARTtoUSB bridge
152 ; P4.1 - RTS             J13.14 ----> CTS  UARTtoUSB bridge (optional hardware control flow)
153 ;  VCC -                 J13.16 <---- VCC  (optional supply from UARTtoUSB bridge - WARNING ! 3.3V !)
154 ;  GND -                 J13.20 <---> GND  (optional supply from UARTtoUSB bridge)
155          
156 ;  VCC -                 J11.1  ----> VCC  SD_CardAdapter
157 ;  GND -                 J12.3  <---> GND  SD_CardAdapter
158 ; P2.4 - UCA1 CLK        J4.6   ----> CLK  SD_CardAdapter (SCK)  
159 ; P4.3 -                 J4.5   ----> CS   SD_CardAdapter (Card Select)
160 ; P2.5 - UCA1 TXD/SIMO   J4.4   ----> SDI  SD_CardAdapter (MOSI)
161 ; P2.6 - UCA1 RXD/SOMI   J4.3   <---- SDO  SD_CardAdapter (MISO)
162 ; P4.2 -                 J4.2   <---- CD   SD_CardAdapter (Card Detect)
163          
164 ; P4.0 -                 J3.10  <---- OUT  IR_Receiver (1 TSOP32236)
165 ;  VCC -                 J3.2   ----> VCC  IR_Receiver (2 TSOP32236)
166 ;  GND -                 J3.9   <---> GND  IR_Receiver (3 TSOP32236)
167          
168 ; P1.2 -                 J5.19  <---> SDA  I2C SOFTWARE MASTER
169 ; P1.3 -                 J5.11  <---> SCL  I2C SOFTWARE MASTER
170 ; P1.4 -           TB0.1 J5.12  <---> free
171 ; P1.5 - UCA0 CLK  TB0.2 J5.13  <---> free
172 ; P1.7 - UCB0 SCL/SOMI   J5.14  ----> SCL  I2C MASTER/SLAVE
173 ; P1.6 - UCB0 SDA/SIMO   J5.15  <---> SDA  I2C MASTER/SLAVE
174 ; P3.0 -                 J5.7   <---- free
175
176 ; PJ.4 - LFXI 32768Hz quartz  
177 ; PJ.5 - LFXO 32768Hz quartz  
178 ; PJ.6 - HFXI 
179 ; PJ.7 - HFXO 
180   
181 ; P2.3 - NC
182 ; P2.7 - NC
183 ; P3.1 - NC
184 ; P3.2 - NC
185 ; P3.3 - NC
186 ; P3.7 - NC
187 ; P4.4 - NC
188 ; P4.7 - NC
189
190
191
192 ; ----------------------------------------------------------------------
193 ; INIT order : LOCK I/O, WDT, GPIOs, FRAM, Clock, UARTs
194 ; ----------------------------------------------------------------------
195
196 ; ----------------------------------------------------------------------
197 ; POWER ON RESET AND INITIALIZATION : LOCK PMM_LOCKLPM5
198 ; ----------------------------------------------------------------------
199
200 ;              BIS     #LOCKLPM5,&PM5CTL0 ; unlocked by WARM
201
202 ; ----------------------------------------------------------------------
203 ; POWER ON RESET AND INITIALIZATION : WATCHDOG TIMER A
204 ; ----------------------------------------------------------------------
205
206         MOV #WDTPW+WDTHOLD+WDTCNTCL,&WDTCTL    ; stop WDT
207
208 ; ----------------------------------------------------------------------
209 ; POWER ON RESET AND INITIALIZATION : I/O
210 ; ----------------------------------------------------------------------
211 ; ----------------------------------------------------------------------
212 ; POWER ON RESET AND INITIALIZATION : PORT1/2
213 ; ----------------------------------------------------------------------
214
215 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
216
217
218 ; PORT1 usage
219 ; P1.0 - LED2 green   output low
220 ; P1.1 - Switch S2    input with pullup resistor
221
222 ; PORTx default wanted state : pins as input with pullup resistor
223
224             BIS     #1,&PADIR   ; all pins 0 as input else P1.0 (LED2)
225             MOV     #0FFFEh,&PAOUT  ; all pins high  else P1.0 (LED2)
226             SUB     #2,&PAREN   ; all pins 1 with pull resistors else P1.0 (LED2)
227
228     .IFDEF UCA0_TERM
229 ; P2.0  UCA0-TXD    --> USB2UART RXD    
230 ; P2.1  UCA0-RXD    <-- USB2UART TXD 
231 TXD         .equ 1      ; P2.0 = TX + FORTH Deep_RST pin
232 RXD         .equ 2      ; P2.1 = RX
233 TERM_BUS    .equ 3
234 TERM_IN     .equ P2IN
235 TERM_SEL    .equ P2SEL1
236 TERM_REN    .equ P2REN
237     .ENDIF
238
239     .IFDEF UCA1_TERM
240 ; P2.5  UCA0-TXD    --> USB2UART RXD    
241 ; P2.6  UCA0-RXD    <-- USB2UART TXD 
242 TXD         .equ 20h   ; P2.5 = TXD + FORTH Deep_RST pin
243 RXD         .equ 40h   ; P2.6 = RXD
244 TERM_BUS    .equ 60h
245 TERM_IN     .equ P2IN
246 TERM_SEL    .equ P2SEL1
247 TERM_REN    .equ P2REN
248     .ENDIF
249
250     .IFDEF UCB0_SD
251 SD_SEL      .equ PASEL1 ; to configure UCB0
252 SD_REN      .equ PAREN  ; to configure pullup resistors
253 SD_BUS      .equ 04C0h  ; pins P2.2 as UCB0CLK, P1.6 as UCB0SIMO & P1.7 as UCB0SOMI
254     .ENDIF
255
256
257 ; ----------------------------------------------------------------------
258 ; POWER ON RESET AND INITIALIZATION : PORT3/4
259 ; ----------------------------------------------------------------------
260 ; PB = P4:P3
261
262 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
263
264 ; PORT3 usage
265
266 ; PORT4 usage
267 SD_CD       .equ 4        ; P4.2 as SD_CD
268 SD_CS       .equ 8        ; P4.3 as SD_CS     
269 SD_CDIN     .equ P4IN
270 SD_CSOUT    .equ P4OUT
271 SD_CSDIR    .equ P4DIR
272
273 ; P4.5 - switch S1
274 ; P4.6 - LED1 red
275
276     .IFDEF TERMINAL4WIRES
277
278 ; RTS output is wired to the CTS input of UART2USB bridge 
279 ; configure RTS as output high to disable RX TERM during start FORTH
280
281 HANDSHAKOUT .equ  P4OUT
282 HANDSHAKIN  .equ  P4IN
283 RTS         .equ  2 ; P4.1
284
285             BIS #04200h,&PBDIR  ; all pins as input else P4.1 (RTS), P4.6 (LED1)
286             BIS #-1,&PBREN      ; all inputs with resistor
287
288         .IFDEF TERMINAL5WIRES
289
290 CTS         .equ  1 ; P4.0 
291
292             MOV #0BEFFh,&PBOUT  ; that acts as pull up , P4.6 (LED1) output LOW, RTS output HIGH, CTS input LOW
293
294         .ELSEIF
295
296             MOV #0BFFFh,&PBOUT  ; that acts as pull up , P4.6 (LED1) output LOW, RTS output HIGH
297
298         .ENDIF  ; TERMINAL5WIRES
299
300     .ELSEIF
301             BIS #04000h,&PBDIR  ; all pins as input else P4.6 (LED1)
302             BIS #-1,&PBREN      ; all inputs with resistor
303             MOV #0BFFFh,&PBOUT  ; that acts as pull up, P4.6 (LED1) output LOW
304
305     .ENDIF  ; TERMINAL4WIRES
306
307
308 ; ----------------------------------------------------------------------
309 ; POWER ON RESET AND INITIALIZATION : PORTJ
310 ; ----------------------------------------------------------------------
311
312 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
313
314 ; PORTx default wanted state : pins as input with pullup resistor
315
316             MOV.B #-1,&PJOUT    ; pullup resistors
317             BIS.B #-1,&PJREN    ; enable pullup/pulldown resistors
318
319 ; ----------------------------------------------------------------------
320 ; FRAM config
321 ; ----------------------------------------------------------------------
322
323     .IF FREQUENCY = 16
324             MOV.B   #0A5h, &FRCTL0_H     ; enable FRCTL0 access
325             MOV.B   #10h, &FRCTL0         ; 1 waitstate @ 16 MHz
326             MOV.B   #01h, &FRCTL0_H       ; disable FRCTL0 access
327     .ENDIF
328
329 ; ----------------------------------------------------------------------
330 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
331 ; ----------------------------------------------------------------------
332
333 ; DCOCLK: Internal digitally controlled oscillator (DCO).
334
335
336 ; CS code for MSP430FR5948
337             MOV.B   #CSKEY,&CSCTL0_H ;  Unlock CS registers
338
339     .IF FREQUENCY = 0.25
340 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1      ; Set 8MHZ DCO setting (default value)
341             MOV     #DIVA_0 + DIVS_32 + DIVM_32,&CSCTL3
342             MOV     #4,X
343
344     .ELSEIF FREQUENCY = 0.5
345             MOV     #0,&CSCTL1                  ; Set 1MHZ DCO setting
346             MOV     #DIVA_2 + DIVS_2 + DIVM_2,&CSCTL3             ; set all dividers as 2
347             MOV     #8,X
348
349     .ELSEIF FREQUENCY = 1
350             MOV     #0,&CSCTL1                  ; Set 1MHZ DCO setting
351             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
352             MOV     #16,X
353
354     .ELSEIF FREQUENCY = 2
355             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1  ; Set 4MHZ DCO setting
356             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3
357             MOV     #32,X
358
359     .ELSEIF FREQUENCY = 4
360             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1  ; Set 4MHZ DCO setting
361             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
362             MOV     #64,X
363
364     .ELSEIF FREQUENCY = 8
365 ;            MOV     #DCOFSEL2+DCOFSEL1,&CSCTL1  ; Set 8MHZ DCO setting (default value)
366             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
367             MOV     #128,X
368
369     .ELSEIF FREQUENCY = 16
370             MOV     #DCORSEL+DCOFSEL2,&CSCTL1   ; Set 16MHZ DCO setting
371             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
372             MOV     #256,X
373
374     .ELSEIF
375     .error "bad frequency setting, only 0.5,1,2,4,8,16 MHz"
376     .ENDIF
377
378     .IFDEF LF_XTAL
379             MOV     #SELA_LFXCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
380     .ELSE
381             MOV     #SELA_VLOCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
382     .ENDIF
383             MOV.B   #01h, &CSCTL0_H                               ; Lock CS Registers
384
385             BIS &SYSRSTIV,&SAVE_SYSRSTIV; store volatile SYSRSTIV preserving a pending request for DEEP_RST
386             CMP #2,&SAVE_SYSRSTIV   ; POWER ON ?
387             JZ      ClockWaitX      ; yes
388             .word   0759h           ; no  RRUM #2,X --> wait only 125 ms
389 ClockWaitX  MOV     #5209,Y         ; wait 0.5s before starting after POWER ON
390 ClockWaitY  SUB     #1,Y            ;1
391             JNZ     ClockWaitY      ;2 5209x3 = 15625 cycles delay = 15.625ms @ 1MHz
392             SUB     #1,X            ; x 32 @ 1 MHZ = 500ms
393             JNZ     ClockWaitX      ; time to stabilize power source ( 500ms )
394
395 ; ----------------------------------------------------------------------
396 ; POWER ON RESET AND INITIALIZATION : REF
397 ; ----------------------------------------------------------------------
398
399             BIS   #8, &REFCTL
400
401 ; ----------------------------------------------------------------------
402 ; POWER ON RESET AND INITIALIZATION : RTC REGISTERS
403 ; ----------------------------------------------------------------------
404
405     .IFDEF LF_XTAL
406 ; LFXIN : PJ.4, LFXOUT : PJ.5
407     BIS.B   #010h,&PJSEL0   ; SEL0 for only LFXIN
408     BIC.B   #RTCHOLD,&RTCCTL1 ; Clear RTCHOLD = start RTC_B
409     .ENDIF
410
411 ; ----------------------------------------------------------------------
412 ; POWER ON RESET AND INITIALIZATION : SYS REGISTERS
413 ; ----------------------------------------------------------------------
414
415 ; SYS code                                  
416 ; see COLD word
417