OSDN Git Service

12750093debc074c53de1359287355e9ed7e303a
[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 ; PORTA usage
218 SD_SEL      .equ PASEL1 ; to configure UCB0
219 SD_REN      .equ PAREN  ; to configure pullup resistors
220 SD_BUS      .equ 7000h  ; pins P2.4 as UCB0CLK, P2.5 as UCB0SIMO & P2.6 as UCB0SOMI
221
222
223 ; PORT1 usage
224 ; P1.0 - LED2 green   output low
225 ; P1.1 - Switch S2    input with pullup resistor
226
227 ; PORT2 usage
228
229
230 Deep_RST_IN .equ P2IN  ; TERMINAL TX  pin as FORTH Deep_RST 
231 Deep_RST    .equ 1     ; P2.0
232 TERM_TXRX   .equ 003h
233 TERM_SEL    .equ P2SEL1
234 TERM_REN    .equ P2REN
235
236 ; PORTx default wanted state : pins as input with pullup resistor
237
238             BIS     #1,&PADIR   ; all pins 0 as input else P1.0 (LED2)
239             MOV     #0FFFEh,&PAOUT  ; all pins high  else P1.0 (LED2)
240             SUB     #2,&PAREN   ; all pins 1 with pull resistors else P1.0 (LED2)
241
242 ; ----------------------------------------------------------------------
243 ; POWER ON RESET AND INITIALIZATION : PORT3/4
244 ; ----------------------------------------------------------------------
245 ; PB = P4:P3
246
247 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
248
249 ; PORT3 usage
250
251 ; PORT4 usage
252 SD_CD       .equ 4        ; P4.2 as SD_CD
253 SD_CS       .equ 8        ; P4.3 as SD_CS     
254 SD_CDIN     .equ P4IN
255 SD_CSOUT    .equ P4OUT
256 SD_CSDIR    .equ P4DIR
257
258 ; P4.5 - switch S1
259 ; P4.6 - LED1 red
260
261     .IFDEF TERMINAL4WIRES
262
263 ; RTS output is wired to the CTS input of UART2USB bridge 
264 ; configure RTS as output high to disable RX TERM during start FORTH
265
266 HANDSHAKOUT .equ  P4OUT
267 HANDSHAKIN  .equ  P4IN
268 RTS         .equ  2 ; P4.1
269
270             BIS #04200h,&PBDIR  ; all pins as input else P4.1 (RTS), P4.6 (LED1)
271             BIS #-1,&PBREN      ; all inputs with resistor
272
273         .IFDEF TERMINAL5WIRES
274
275 CTS         .equ  1 ; P4.0 
276
277             MOV #0BEFFh,&PBOUT  ; that acts as pull up , P4.6 (LED1) output LOW, RTS output HIGH, CTS input LOW
278
279         .ELSEIF
280
281             MOV #0BFFFh,&PBOUT  ; that acts as pull up , P4.6 (LED1) output LOW, RTS output HIGH
282
283         .ENDIF  ; TERMINAL5WIRES
284
285     .ELSEIF
286             BIS #04000h,&PBDIR  ; all pins as input else P4.6 (LED1)
287             BIS #-1,&PBREN      ; all inputs with resistor
288             MOV #0BFFFh,&PBOUT  ; that acts as pull up, P4.6 (LED1) output LOW
289
290     .ENDIF  ; TERMINAL4WIRES
291
292
293 ; ----------------------------------------------------------------------
294 ; POWER ON RESET AND INITIALIZATION : PORTJ
295 ; ----------------------------------------------------------------------
296
297 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
298
299 ; PORTx default wanted state : pins as input with pullup resistor
300
301             MOV.B #-1,&PJOUT    ; pullup resistors
302             BIS.B #-1,&PJREN    ; enable pullup/pulldown resistors
303
304 ; ----------------------------------------------------------------------
305 ; FRAM config
306 ; ----------------------------------------------------------------------
307
308     .IF FREQUENCY = 16
309             MOV.B   #0A5h, &FRCTL0_H     ; enable FRCTL0 access
310             MOV.B   #10h, &FRCTL0         ; 1 waitstate @ 16 MHz
311             MOV.B   #01h, &FRCTL0_H       ; disable FRCTL0 access
312     .ENDIF
313
314 ; ----------------------------------------------------------------------
315 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
316 ; ----------------------------------------------------------------------
317
318 ; DCOCLK: Internal digitally controlled oscillator (DCO).
319
320
321 ; CS code for MSP430FR5948
322             MOV.B   #CSKEY,&CSCTL0_H ;  Unlock CS registers
323
324     .IF FREQUENCY = 0.25
325 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1      ; Set 8MHZ DCO setting (default value)
326             MOV     #DIVA_0 + DIVS_32 + DIVM_32,&CSCTL3
327             MOV     #4,X
328
329     .ELSEIF FREQUENCY = 0.5
330             MOV     #0,&CSCTL1                  ; Set 1MHZ DCO setting
331             MOV     #DIVA_2 + DIVS_2 + DIVM_2,&CSCTL3             ; set all dividers as 2
332             MOV     #8,X
333
334     .ELSEIF FREQUENCY = 1
335             MOV     #0,&CSCTL1                  ; Set 1MHZ DCO setting
336             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
337             MOV     #16,X
338
339     .ELSEIF FREQUENCY = 2
340             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1  ; Set 4MHZ DCO setting
341             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3
342             MOV     #32,X
343
344     .ELSEIF FREQUENCY = 4
345             MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1  ; Set 4MHZ DCO setting
346             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
347             MOV     #64,X
348
349     .ELSEIF FREQUENCY = 8
350 ;            MOV     #DCOFSEL2+DCOFSEL1,&CSCTL1  ; Set 8MHZ DCO setting (default value)
351             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
352             MOV     #128,X
353
354     .ELSEIF FREQUENCY = 16
355             MOV     #DCORSEL+DCOFSEL2,&CSCTL1   ; Set 16MHZ DCO setting
356             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3             ; set all dividers as 0
357             MOV     #256,X
358
359     .ELSEIF
360     .error "bad frequency setting, only 0.5,1,2,4,8,16 MHz"
361     .ENDIF
362
363     .IFDEF LF_XTAL
364             MOV     #SELA_LFXCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
365     .ELSE
366             MOV     #SELA_VLOCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
367     .ENDIF
368             MOV.B   #01h, &CSCTL0_H                               ; Lock CS Registers
369
370             BIS &SYSRSTIV,&SAVE_SYSRSTIV; store volatile SYSRSTIV preserving a pending request for DEEP_RST
371             CMP #2,&SAVE_SYSRSTIV   ; POWER ON ?
372             JZ      ClockWaitX      ; yes
373             .word   0759h           ; no  RRUM #2,X --> wait only 125 ms
374 ClockWaitX  MOV     #5209,Y         ; wait 0.5s before starting after POWER ON
375 ClockWaitY  SUB     #1,Y            ;1
376             JNZ     ClockWaitY      ;2 5209x3 = 15625 cycles delay = 15.625ms @ 1MHz
377             SUB     #1,X            ; x 32 @ 1 MHZ = 500ms
378             JNZ     ClockWaitX      ; time to stabilize power source ( 500ms )
379
380 ; ----------------------------------------------------------------------
381 ; POWER ON RESET AND INITIALIZATION : REF
382 ; ----------------------------------------------------------------------
383
384             BIS   #8, &REFCTL
385
386 ; ----------------------------------------------------------------------
387 ; POWER ON RESET AND INITIALIZATION : RTC REGISTERS
388 ; ----------------------------------------------------------------------
389
390     .IFDEF LF_XTAL
391 ; LFXIN : PJ.4, LFXOUT : PJ.5
392     BIS.B   #010h,&PJSEL0   ; SEL0 for only LFXIN
393     BIC.B   #RTCHOLD,&RTCCTL1 ; Clear RTCHOLD = start RTC_B
394     .ENDIF
395
396 ; ----------------------------------------------------------------------
397 ; POWER ON RESET AND INITIALIZATION : SYS REGISTERS
398 ; ----------------------------------------------------------------------
399
400 ; SYS code                                  
401 ; see COLD word
402