1 ; -*- coding: utf-8 -*-
4 ; Fast Forth For Texas Instrument MSP430FR5969
6 ; Copyright (C) <2014> <J.M. THOORENS>
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.
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.
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/>.
23 ; ======================================================================
24 ; INIT MSP-EXP430FR5969 board
25 ; ======================================================================
28 ; J21 : external target
29 ; ---------------------
56 ; J13 eZ-FET <-> target
57 ; -----------------------
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
67 ; P19<->P20 - GND - VSS
69 ; Launchpad Header Left J4
70 ; ------------------------
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
82 ; Launchpad Header Right J5
83 ; -------------------------
87 ; P14- P1.6 UCB0 SIMO/SDA
88 ; P15- P1.7 UCB0 SOMI/SCL
118 ; ===================================================================================
119 ; in case of 3.3V powered by UARTtoUSB bridge, open J13 straps {RST,TST,V+,5V} BEFORE
120 ; ===================================================================================
122 ; -----------------------------------------------
123 ; MSP430FR5969 LAUNCHPAD <--> OUTPUT WORLD
124 ; -----------------------------------------------
125 ; P4.6 - J6 - LED1 red
128 ; P4.5 - Switch S1 <--- LCD contrast + (finger :-)
129 ; P1.1 - Switch S2 <--- LCD contrast - (finger ;-)
131 ; GND - J1.2 <-------+---0V0----------> 1 LCD_Vss
132 ; VCC - J1.3 >------ | --3V6-----+----> 2 LCD_Vdd
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
148 ; +--4k7-< DeepRST <-- GND
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)
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)
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)
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
176 ; PJ.4 - LFXI 32768Hz quartz
177 ; PJ.5 - LFXO 32768Hz quartz
192 ; ----------------------------------------------------------------------
193 ; INIT order : LOCK I/O, WDT, GPIOs, FRAM, Clock, UARTs
194 ; ----------------------------------------------------------------------
196 ; ----------------------------------------------------------------------
197 ; POWER ON RESET AND INITIALIZATION : LOCK PMM_LOCKLPM5
198 ; ----------------------------------------------------------------------
200 ; BIS #LOCKLPM5,&PM5CTL0 ; unlocked by WARM
202 ; ----------------------------------------------------------------------
203 ; POWER ON RESET AND INITIALIZATION : WATCHDOG TIMER A
204 ; ----------------------------------------------------------------------
206 MOV #WDTPW+WDTHOLD+WDTCNTCL,&WDTCTL ; stop WDT
208 ; ----------------------------------------------------------------------
209 ; POWER ON RESET AND INITIALIZATION : I/O
210 ; ----------------------------------------------------------------------
211 ; ----------------------------------------------------------------------
212 ; POWER ON RESET AND INITIALIZATION : PORT1/2
213 ; ----------------------------------------------------------------------
215 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
219 ; P1.0 - LED2 green output low
220 ; P1.1 - Switch S2 input with pullup resistor
222 ; PORTx default wanted state : pins as input with pullup resistor
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)
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
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
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
257 ; ----------------------------------------------------------------------
258 ; POWER ON RESET AND INITIALIZATION : PORT3/4
259 ; ----------------------------------------------------------------------
262 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
267 SD_CD .equ 4 ; P4.2 as SD_CD
268 SD_CS .equ 8 ; P4.3 as SD_CS
276 .IFDEF TERMINAL4WIRES
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
281 HANDSHAKOUT .equ P4OUT
285 BIS #04200h,&PBDIR ; all pins as input else P4.1 (RTS), P4.6 (LED1)
286 BIS #-1,&PBREN ; all inputs with resistor
288 .IFDEF TERMINAL5WIRES
292 MOV #0BEFFh,&PBOUT ; that acts as pull up , P4.6 (LED1) output LOW, RTS output HIGH, CTS input LOW
296 MOV #0BFFFh,&PBOUT ; that acts as pull up , P4.6 (LED1) output LOW, RTS output HIGH
298 .ENDIF ; TERMINAL5WIRES
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
305 .ENDIF ; TERMINAL4WIRES
308 ; ----------------------------------------------------------------------
309 ; POWER ON RESET AND INITIALIZATION : PORTJ
310 ; ----------------------------------------------------------------------
312 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
314 ; PORTx default wanted state : pins as input with pullup resistor
316 MOV.B #-1,&PJOUT ; pullup resistors
317 BIS.B #-1,&PJREN ; enable pullup/pulldown resistors
319 ; ----------------------------------------------------------------------
321 ; ----------------------------------------------------------------------
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
329 ; ----------------------------------------------------------------------
330 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
331 ; ----------------------------------------------------------------------
333 ; DCOCLK: Internal digitally controlled oscillator (DCO).
336 ; CS code for MSP430FR5948
337 MOV.B #CSKEY,&CSCTL0_H ; Unlock CS registers
340 ; MOV #DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 8MHZ DCO setting (default value)
341 MOV #DIVA_0 + DIVS_32 + DIVM_32,&CSCTL3
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
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
354 .ELSEIF FREQUENCY = 2
355 MOV #DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 4MHZ DCO setting
356 MOV #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3
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
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
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
375 .error "bad frequency setting, only 0.5,1,2,4,8,16 MHz"
379 MOV #SELA_LFXCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
381 MOV #SELA_VLOCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
383 MOV.B #01h, &CSCTL0_H ; Lock CS Registers
385 BIS &SYSRSTIV,&SAVE_SYSRSTIV; store volatile SYSRSTIV preserving a pending request for DEEP_RST
386 CMP #2,&SAVE_SYSRSTIV ; POWER ON ?
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 )
395 ; ----------------------------------------------------------------------
396 ; POWER ON RESET AND INITIALIZATION : REF
397 ; ----------------------------------------------------------------------
401 ; ----------------------------------------------------------------------
402 ; POWER ON RESET AND INITIALIZATION : RTC REGISTERS
403 ; ----------------------------------------------------------------------
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
411 ; ----------------------------------------------------------------------
412 ; POWER ON RESET AND INITIALIZATION : SYS REGISTERS
413 ; ----------------------------------------------------------------------