1 ; -*- coding: utf-8 -*-
3 ; Fast Forth For Texas Instrument MSP430FR5739
4 ; Tested on MSP-EXP430FR5739 launchpad
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/>.
21 ; ----------------------------------------------------------------------
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
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)
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 ; ======================================================================
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
49 ; 8x blue LEDs in a row. (portpinX->---resistor---LED---GND)
120 ; ======================================================================
121 ; MSP-EXP430FR5739 LAUNCHPAD <--> OUTPUT WORLD
122 ; ======================================================================
124 ; P4.0 - Switch S1 <--- LCD contrast + (finger :-)
125 ; P4.1 - Switch S2 <--- LCD contrast - (finger :-)
127 ; GND <-------+---0V0----------> 1 LCD_Vss
128 ; VCC >------ | --3V6-----+----> 2 LCD_Vdd
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
144 ; PJ.4 - LFXI 32768Hz quartz
145 ; PJ.5 - LFXO 32768Hz quartz
148 ; +--4k7-< DeepRST <-- GND
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)
155 ; ---------------------------------------------------------------------------
156 ; SD_CardAdapter not compatible with HARDWARE flow control for FORTH TERMINAL
157 ; ---------------------------------------------------------------------------
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)
166 ; P2.7 - RF.9 <---- OUT IR_Receiver (1 TSOP32236)
168 ; P1.7 - UCB0 SCL/SOMI SV2.1 <---> SCL I2C MASTER/SLAVE
169 ; P1.6 - UCB0 SDA/SIMO SV2.2 <---> SDA I2C MASTER/SLAVE
177 ; ----------------------------------------------------------------------
178 ; POWER ON RESET AND INITIALIZATION : LOCK I/O as high impedance state
179 ; ----------------------------------------------------------------------
181 BIS #LOCKLPM5,&PM5CTL0 ; unlocked by WARM
183 ; ----------------------------------------------------------------------
184 ; POWER ON RESET AND INITIALIZATION : WATCHDOG TIMER A
185 ; ----------------------------------------------------------------------
188 MOV #WDTPW+WDTHOLD+WDTCNTCL,&WDTCTL ; stop WDT
190 ; ----------------------------------------------------------------------
191 ; POWER ON RESET AND INITIALIZATION PAIN=PORT2:PORT1
192 ; ----------------------------------------------------------------------
194 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
197 SD_SEL .equ PASEL1 ; to configure UCB0
198 SD_REN .equ PAREN ; to configure pullup resistors
199 SD_BUS .equ 7000h ; pins P2.4 as UCB0CLK, P2.5 as UCB0SIMO & P2.6 as UCB0SOMI
203 ; P1.4 is used as analog input from NTC voltage divider
206 Deep_RST_IN .equ P2IN ; TERMINAL TX pin as FORTH Deep_RST
207 Deep_RST .equ 1 ; P2.0
212 SD_CD .equ 4 ; P2.2 as SD_CD
213 SD_CS .equ 8 ; P2.3 as SD_CS
218 ; RTS output is wired to the CTS input of UART2USB bridge
219 ; configure RTS as output high to disable RX TERM during start FORTH
221 ; P2.7 is used to power the accelerometer and NTC voltage divider ==> output low = power OFF
222 BIS #07FEFh,&PAREN ; all input pins with pull up resistor else P2.7 and P1.4 with pull down
224 .IFDEF TERMINAL4WIRES
226 HANDSHAKOUT .equ P2OUT
230 BIS #00400h,&PADIR ; RTS P2.2 output high
232 .IFDEF TERMINAL5WIRES
236 BIS #00800h,&PAOUT ; CTS input low
238 .ENDIF ; TERMINAL5WIRES
240 .ENDIF ; TERMINAL4WIRES
242 ; ----------------------------------------------------------------------
243 ; POWER ON RESET AND INITIALIZATION : PORT3/4
244 ; ----------------------------------------------------------------------
247 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
250 ; P3.0 to P3.2 are accelerometer analog outputs
252 ; P3.4 to P3.7 are blues LEDs : set output low = OFF
261 ; PORTx default wanted state : pins as input with pullup resistor
263 MOV #0FF08h,&PAOUT ; all pins inputs hifh else blues LEDs and ADC inputs
264 BIS #0FF08h,&PAREN ; all pins with pull resistors else blues LEDs and ADC inputs
265 BIS #000F0h,&PADIR ; all pins as input else blues LEDs
267 ; ----------------------------------------------------------------------
268 ; POWER ON RESET AND INITIALIZATION : PORTJ
269 ; ----------------------------------------------------------------------
271 ; reset state : Px{DIR,REN,SEL0,SEL1,SELC,IE,IFG,IV} = 0 ; Px{IN,OUT,IES} = ?
275 ; PJ.0 to PJ.3 are blues LEDs : set as output low = OFF
277 ; PORTx default wanted state : pins as input with pullup resistor else leds output low
279 MOV.B #0F0h,&PJOUT ; all pins high else blues LEDs
280 BIS.B #0F0h,&PJREN ; all pins 1 with pull resistors else blues LEDs
281 BIS.B #00Fh,&PJDIR ; all pins as input else blues LEDs
284 ; ----------------------------------------------------------------------
285 ; POWER ON RESET AND INITIALIZATION : CLOCK SYSTEM
286 ; ----------------------------------------------------------------------
288 ; DCOCLK: Internal digitally controlled oscillator (DCO).
290 ; CS code for MSP430fr5739
291 MOV.B #CSKEY,&CSCTL0_H ; Unlock CS registers
294 ; MOV #DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 8MHZ DCO setting (default value)
295 MOV #DIVA_0 + DIVS_32 + DIVM_32,&CSCTL3
298 .ELSEIF FREQUENCY = 0.5
299 ; MOV #DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 8MHZ DCO setting (default value)
300 MOV #DIVA_0 + DIVS_16 + DIVM_16,&CSCTL3
303 .ELSEIF FREQUENCY = 1
304 ; MOV #DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 8MHZ DCO setting (default value)
305 MOV #DIVA_0 + DIVS_8 + DIVM_8,&CSCTL3
308 .ELSEIF FREQUENCY = 2
309 ; MOV #DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 8MHZ DCO setting (default value)
310 MOV #DIVA_0 + DIVS_4 + DIVM_4,&CSCTL3
313 .ELSEIF FREQUENCY = 4
314 ; MOV #DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 8MHZ DCO setting (default value)
315 MOV #DIVA_0 + DIVS_2 + DIVM_2,&CSCTL3
318 .ELSEIF FREQUENCY = 8
319 ; MOV #DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 8MHZ DCO setting (default value)
320 MOV #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3 ; set all dividers as 0
324 .ELSEIF FREQUENCY = 16
325 MOV #DCORSEL,&CSCTL1 ; Set 16MHZ DCO setting
326 MOV #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3 ; set all dividers as 0
330 .ELSEIF FREQUENCY = 24
331 MOV #DCORSEL+DCOFSEL1+DCOFSEL0,&CSCTL1 ; Set 24 MHZ DCO setting
332 MOV #DIVA_0 + DIVS_0 + DIVM_0,&CSCTL3 ; set all dividers as 0
337 .error "bad frequency setting, only 0.5,1,2,4,8,16,24 MHz"
341 MOV #SELA_LFXCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
343 MOV #SELA_VLOCLK+SELS_DCOCLK+SELM_DCOCLK,&CSCTL2
345 MOV.B #01h, &CSCTL0_H ; Lock CS Registers
347 BIS &SYSRSTIV,&SAVE_SYSRSTIV; store volatile SYSRSTIV preserving a pending request for DEEP_RST
348 CMP #2,&SAVE_SYSRSTIV ; POWER ON ?
350 .word 0759h ; no RRUM #2,X --> wait only 125 ms
351 ClockWaitX MOV #41666,Y ; wait 0.5s before starting after POWER ON
352 ClockWaitY SUB #1,Y ;
353 JNZ ClockWaitY ; 41666x3 = 125000 cycles delay = 125ms @ 1MHz
354 SUB #1,X ; x 4 @ 1 MHZ
355 JNZ ClockWaitX ; time to stabilize power source ( 1s )
357 ; ----------------------------------------------------------------------
358 ; POWER ON RESET AND INITIALIZATION : REF
359 ; ----------------------------------------------------------------------
361 BIS.W #REFTCOFF, &REFCTL ; Turn off temp.
362 BIC.W #REFON, &REFCTL
365 ; ----------------------------------------------------------------------
366 ; POWER ON RESET AND INITIALIZATION : RTC REGISTERS
367 ; ----------------------------------------------------------------------
369 ; LFXIN : PJ.4, LFXOUT : PJ.5
370 BIS.B #010h,&PJSEL0 ; SEL0 for only LFXIN
371 BIC.B #RTCHOLD,&RTCCTL1 ; Clear RTCHOLD = start RTC_B