OSDN Git Service

Update readme
[fast-forth/master.git] / MSP_EXP430FR5739.asm
1 ; -*- coding: utf-8 -*-
2
3 ; Fast Forth For Texas Instrument MSP430FR5739
4 ; Tested on MSP-EXP430FR5739 launchpad
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 ; MSP_EXP430FR739.inc 
23 ; ----------------------------------------------------------------------
24 ; ----------------------------------------------------------------------
25 ; MSP430FR57xx BOOTSTRAP
26 ; ----------------------------------------------------------------------
27 ; BSL for MSP430FR573x devices
28 ; BSL Version 00.04.31.71
29 ; RAM erased 0x1C00-0x1FFF
30 ; Buffer size for Core Commands : 260 bytes
31 ; Notable Information
32 ; 1. TX and RX pins are noted in the device data sheet
33 ; 2. A mass erase command or incorrect password triggers a BSL reset. 
34 ;    This resets the BSL state to the default settings (9600 baud, password locked)
35 ; Known Bugs
36 ; 1. The baud rate of 115k cannot be ensured across all clock, voltage, and temperature variations
37 ; ----------------------------------------------------------------------
38 ; ======================================================================
39 ; INIT MSP-EXP430FR5739 board
40 ; ======================================================================
41
42 ; J3 (5xjumper), silkscreen printing:
43 ; "TEST" - FR5739 pin19 = TEST
44 ; "RST"  - FR5739 pin20 = RST
45 ; "RXD"  - FR5739 pin22 = P2.1 == UCA0RXD --> UCA0RXDBUF
46 ; "TXD"  - FR5739 pin21 = P2.0 == UCA0TXD <-- UCA0TXDBUf
47 ; "VCC"  - + upper side
48
49 ; 8x blue LEDs in a row.   (portpinX->---resistor---LED---GND)
50 ; PJ.0 - LED1
51 ; PJ.1 - LED2
52 ; PJ.2 - LED3
53 ; PJ.3 - LED4
54 ; P3.4 - LED5
55 ; P3.5 - LED6
56 ; P3.6 - LED7
57 ; P3.7 - LED8
58
59 ; I/O pins on SV1:
60 ; P1.0 - SV1.1
61 ; P1.1 - SV1.2
62 ; P1.2 - SV1.3
63 ; P3.0 - SV1.4
64 ; P3.1 - SV1.5
65 ; P3.2 - SV1.6
66 ; P3.3 - SV1.7
67 ; P1.3 - SV1.8
68 ; P1.4 - SV1.9
69 ; P1.5 - SV1.10
70 ; P4.0 - SV1.11
71 ; GND  - SV1.12
72
73 ; I/O pins on SV2:
74 ; P1.7 - SV2.1
75 ; P1.6 - SV2.2
76 ; P3.7 - SV2.3
77 ; P3.6 - SV2.4
78 ; P3.5 - SV2.5
79 ; P3.4 - SV2.6
80 ; P2.2 - SV2.7
81 ; P2.1 - SV2.8
82 ; P2.6 - SV2.9
83 ; P2.5 - SV2.10
84 ; P2.0 - SV2.11
85 ; VCC  - SV2.12
86
87 ; I/O pins on RF:
88 ; GND  - RF.1
89 ; VCC  - RF.2
90 ; P2.0 - RF.3
91 ; P1.0 - RF.4
92 ; P2.6 - RF.5
93 ; P1.1 - RF.6
94 ; P2.5 - RF.7
95 ; P1.2 - RF.8
96 ; P2.7 - RF.9
97 ; P2.3 - RF.10
98 ; P4.0 - RF.11
99 ; GND  - RF.12
100 ; P4.1 - RF.13
101 ; P2.4 - RF.14
102 ; P1.7 - RF.15
103 ; P2.2 - RF.16
104 ; P1.3 - RF.17
105 ; P1.6 - RF.18
106
107 ; Accelerometer:
108 ; P2.7 - VS
109 ; P3.0 - XOUT
110 ; P3.1 - YOUT
111 ; P3.2 - ZOUT
112
113 ; LDR and NTC:
114 ; P2.7 - VS
115 ; P3.3 - LDR
116 ; P1.4 - NTC
117
118 ; RST - reset
119
120 ; ======================================================================
121 ; MSP-EXP430FR5739 LAUNCHPAD    <--> OUTPUT WORLD
122 ; ======================================================================
123 ;
124 ; P4.0 - Switch S1              <--- LCD contrast + (finger :-)
125 ; P4.1 - Switch S2              <--- LCD contrast - (finger :-)
126 ;                                   
127 ;  GND                          <-------+---0V0---------->  1 LCD_Vss
128 ;  VCC                          >------ | --3V6-----+---->  2 LCD_Vdd
129 ;                                       |           |
130 ;                                     |___    470n ---
131 ;                                       ^ |        ---
132 ;                                      / \ BAT54    |
133 ;                                      ---          |
134 ;                                  100n |    2k2    |
135 ; P1.5 - UCB0 CLK  TB0.2 SV1.10 >---||--+--^/\/\/v--+---->  3 LCD_Vo (=0V6 without modulation)
136 ; P3.4 -                 SV2.6  ------------------------->  4 LCD_RS
137 ; P3.5 -                 SV2.5  ------------------------->  5 LCD_R/W
138 ; P3.6 -                 SV2.4  ------------------------->  6 LCD_EN
139 ; P1.0 -                 SV1.1  <------------------------> 11 LCD_DB4
140 ; P1.1 -                 SV1.2  <------------------------> 12 LCD_DB5
141 ; P1.2 -                 SV1.3  <------------------------> 13 LCD_DB5
142 ; P1.3 -                 SV1.8  <------------------------> 14 LCD_DB7
143 ;
144 ; PJ.4 - LFXI 32768Hz quartz  
145 ; PJ.5 - LFXO 32768Hz quartz  
146 ; PJ.6 - HFXI 
147 ; PJ.7 - HFXO 
148 ;                                 +--4k7-< DeepRST <-- GND 
149 ;                                 |
150 ; P2.0 -  UCA0 TXD       SV2.11 --+-> RX  UARTtoUSB bridge
151 ; P2.1 -  UCA0 RXD       SV2.8  <---- TX  UARTtoUSB bridge
152 ;  VCC -                        <---- VCC (optional supply from UARTtoUSB bridge - WARNING ! 3.3V !)
153 ;  GND -                        <---> GND (optional supply from UARTtoUSB bridge)
154 ;        
155 ; ---------------------------------------------------------------------------
156 ; SD_CardAdapter not compatible with HARDWARE flow control for FORTH TERMINAL
157 ; ---------------------------------------------------------------------------
158 ; VCC  -                 RF.2 
159 ; VSS  -                 RF.1 
160 ; P2.2 -                 RF.16  <---- CD  SD_CardAdapter (Card Detect) / RTS
161 ; P2.3 -                 RF.10  ----> CS  SD_CardAdapter (Card Select) / CTS
162 ; P2.4 - UCA1 CLK        RF.14  ----> CLK SD_CardAdapter (SCK)  
163 ; P2.5 - UCA1 TXD/SIMO   RF.7   ----> SDI SD_CardAdapter (MOSI)
164 ; P2.6 - UCA1 RXD/SOMI   RF.5   <---- SDO SD_CardAdapter (MISO)
165 ;
166 ; P2.7 -                 RF.9   <---- OUT IR_Receiver (1 TSOP32236)
167 ;
168 ; P1.7 - UCB0 SCL/SOMI   SV2.1  <---> SCL I2C MASTER/SLAVE
169 ; P1.6 - UCB0 SDA/SIMO   SV2.2  <---> SDA I2C MASTER/SLAVE
170
171
172 ; Clocks:
173 ; 8 MHz DCO intern
174
175
176
177 ; ----------------------------------------------------------------------
178 ; POWER ON RESET AND INITIALIZATION : LOCK I/O as high impedance state
179 ; ----------------------------------------------------------------------
180
181     BIS #LOCKLPM5,&PM5CTL0 ; unlocked by WARM
182
183 ; ----------------------------------------------------------------------
184 ; POWER ON RESET AND INITIALIZATION : WATCHDOG TIMER A
185 ; ----------------------------------------------------------------------
186
187 ; WDT code
188     MOV #WDTPW+WDTHOLD+WDTCNTCL,&WDTCTL    ; stop WDT
189
190 ; ----------------------------------------------------------------------
191 ; POWER ON RESET AND INITIALIZATION PAIN=PORT2:PORT1
192 ; ----------------------------------------------------------------------
193
194 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
195
196 ; PORT 1  usage
197 ; P1.4 is used as analog input from NTC voltage divider
198
199
200
201     .IFDEF UCA0_TERM
202 TERM_IN     .equ P2IN
203 TXD         .equ 1          ; P2.0 = TXD + FORTH Deep_RST pin
204 RXD         .equ 2          ; P2.1 = RXD
205 TERM_BUS    .equ 3
206 TERM_SEL    .equ P2SEL1
207 TERM_REN    .equ P2REN
208     .ENDIF
209
210     .IFDEF UCB0_SD
211 SD_SEL      .equ PASEL1     ; to configure UCB0
212 SD_REN      .equ PAREN      ; to configure pullup resistors
213 SD_BUS      .equ 7000h      ; pins P2.4 as UCB0CLK, P2.5 as UCB0SIMO & P2.6 as UCB0SOMI
214 SD_CD       .equ 4          ; P2.2 as SD_CD
215 SD_CS       .equ 8          ; P2.3 as SD_CS     
216 SD_CDIN     .equ P2IN
217 SD_CSOUT    .equ P2OUT
218 SD_CSDIR    .equ P2DIR
219     .ENDIF
220
221
222 ; RTS output is wired to the CTS input of UART2USB bridge 
223 ; configure RTS as output high to disable RX TERM during start FORTH
224
225 ; P2.7 is used to power the accelerometer and NTC voltage divider ==> output low = power OFF
226
227     MOV #07FEFh,&PAREN  ; all input pins with pull up resistor else P2.7 and P1.4 with pull down
228     MOV #-1,&PAOUT
229
230     .IFDEF TERMINAL4WIRES
231 ; RTS output is wired to the CTS input of UART2USB bridge 
232 ; configure RTS as output high to disable RX TERM during start FORTH
233 HANDSHAKOUT .equ    P2OUT
234 HANDSHAKIN  .equ    P2IN
235 RTS         .equ    4           ; P2.2
236             BIS.B #RTS,&P2DIR   ; RTS as output high
237         .IFDEF TERMINAL5WIRES
238 ; CTS input must be wired to the RTS output of UART2USB bridge 
239 ; configure CTS as input low (true) to avoid lock when CTS is not wired
240 CTS         .equ    8           ; P2.3
241             BIC.B #CTS,&P2OUT   ; CTS input pulled down
242         .ENDIF  ; TERMINAL5WIRES
243     .ENDIF  ; TERMINAL4WIRES
244
245
246 ; ----------------------------------------------------------------------
247 ; POWER ON RESET AND INITIALIZATION : PORT3/4
248 ; ----------------------------------------------------------------------
249 ; PB = P4:P3
250
251 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
252
253 ; P3 FastForth usage
254 ; P3.0 to P3.2 are accelerometer analog outputs
255
256 ; P3.4 to P3.7 are blues LEDs : set output low = OFF
257
258 ; P4 FastForth usage
259 ; P4.0 Switch S1
260 ; P4.1 switch S2
261
262 SWITCHIN    .equ P4IN
263 S1          .equ 1
264
265 ; PORTx default wanted state : pins as input with pullup resistor
266
267     MOV #0FF08h,&PAOUT      ; all pins inputs hifh else blues LEDs and ADC inputs
268     BIS #0FF08h,&PAREN      ; all pins with pull resistors else blues LEDs and ADC inputs
269     BIS #000F0h,&PADIR      ; all pins as input else blues LEDs
270
271 ; ----------------------------------------------------------------------
272 ; POWER ON RESET AND INITIALIZATION : PORTJ
273 ; ----------------------------------------------------------------------
274
275 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
276
277
278 ; PJ FastForth usage
279 ; PJ.0 to PJ.3 are  blues LEDs : set as output low = OFF
280
281 ; PORTx default wanted state : pins as input with pullup resistor else leds output low
282
283     MOV.B #0F0h,&PJOUT      ; all pins high else blues LEDs
284     BIS.B #0F0h,&PJREN      ; all pins 1 with pull resistors else blues LEDs
285     BIS.B #00Fh,&PJDIR      ; all pins as input else blues LEDs
286
287
288 ; ----------------------------------------------------------------------
289 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
290 ; ----------------------------------------------------------------------
291
292 ; DCOCLK: Internal digitally controlled oscillator (DCO).
293
294             MOV.B   #CSKEY,&CSCTL0_H ;  Unlock CS registers
295
296     .IF FREQUENCY = 0.25
297 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1      ; Set 8MHZ DCO setting (default value)
298             MOV     #DIVA_0 + DIVS_32 + DIVM_32,&CSCTL3
299             MOV     #4,X
300
301     .ELSEIF FREQUENCY = 0.5
302 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1      ; Set 8MHZ DCO setting (default value)
303             MOV     #DIVA_0 + DIVS_16 + DIVM_16,&CSCTL3
304             MOV     #8,X
305
306     .ELSEIF FREQUENCY = 1
307 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1      ; Set 8MHZ DCO setting (default value)
308             MOV     #DIVA_0 + DIVS_8 + DIVM_8,&CSCTL3
309             MOV     #16,X
310
311     .ELSEIF FREQUENCY = 2
312 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1      ; Set 8MHZ DCO setting (default value)
313             MOV     #DIVA_0 + DIVS_4 + DIVM_4,&CSCTL3
314             MOV     #32,X
315
316     .ELSEIF FREQUENCY = 4
317 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1          ; Set 8MHZ DCO setting (default value)
318             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3
319             MOV     #64,X
320
321     .ELSEIF FREQUENCY = 8
322 ;            MOV     #DCOFSEL1+DCOFSEL0,&CSCTL1          ; Set 8MHZ DCO setting (default value)
323             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
324             MOV     #128,X
325
326     .ELSEIF FREQUENCY = 10
327             MOV     #DCORSEL+DCOFSEL1,&CSCTL1           ; Set 20 MHZ DCO setting
328             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3   ; then SMCLK/2 MCLK/2
329             MOV     #160,X
330
331     .ELSEIF FREQUENCY = 12
332             MOV     #DCORSEL+DCOFSEL1+DCOFSEL0,&CSCTL1  ; Set 24 MHZ DCO setting
333             MOV     #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3   ; then SMCLK/2 MCLK/2
334             MOV     #192,X
335
336     .ELSEIF FREQUENCY = 16
337             MOV     #DCORSEL,&CSCTL1                    ; Set 16MHZ DCO setting
338             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
339             MOV     #256,X
340
341     .ELSEIF FREQUENCY = 20
342             MOV     #DCORSEL+DCOFSEL1,&CSCTL1           ; Set 20 MHZ DCO setting
343             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
344             MOV     #320,X
345
346     .ELSEIF FREQUENCY = 24
347             MOV     #DCORSEL+DCOFSEL1+DCOFSEL0,&CSCTL1  ; Set 24 MHZ DCO setting
348             MOV     #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3   ; set all dividers as 0
349             MOV     #384,X
350
351     .ELSEIF
352     .error "bad frequency setting, only 0.25,0.5,1,2,4,8,12,16,20,24 MHz"
353     .ENDIF
354
355     .IFDEF LF_XTAL
356             MOV     #SELA_LFXCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
357     .ELSE
358             MOV     #SELA_VLOCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
359     .ENDIF
360             MOV.B   #01h, &CSCTL0_H                     ; Lock CS Registers
361
362             BIS &SYSRSTIV,&SAVE_SYSRSTIV    ; store volatile SYSRSTIV preserving a pending request for DEEP_RST
363 ;            MOV &SAVE_SYSRSTIV,TOS  ;
364 ;            CMP #2,TOS              ; POWER ON ?
365 ;            JZ      ClockWaitX      ; yes
366 ;            RRUM    #2,X            ; wait only 125 ms
367 ClockWaitX  MOV     #5209,Y         ; wait 0.5s before starting after POWER ON
368 ClockWaitY  SUB     #1,Y            ;1
369             JNZ     ClockWaitY      ;2 5209x3 = 15625 cycles delay = 15.625ms @ 1MHz
370             SUB     #1,X            ; x 32 @ 1 MHZ = 500ms
371             JNZ     ClockWaitX      ; time to stabilize power source ( 500ms )
372
373 ; ----------------------------------------------------------------------
374 ; POWER ON RESET AND INITIALIZATION : REF
375 ; ----------------------------------------------------------------------
376
377             BIS.W   #REFTCOFF, &REFCTL  ; Turn off temp.
378             BIC.W   #REFON, &REFCTL
379
380
381 ; ----------------------------------------------------------------------
382 ; POWER ON RESET AND INITIALIZATION : RTC REGISTERS
383 ; ----------------------------------------------------------------------
384     .IFDEF LF_XTAL
385 ; LFXIN : PJ.4, LFXOUT : PJ.5
386     BIS.B   #010h,&PJSEL0   ; SEL0 for only LFXIN
387     BIC.B   #RTCHOLD,&RTCCTL1 ; Clear RTCHOLD = start RTC_B
388     .ENDIF
389