1 \ -*- coding: utf-8 -*-
3 \ TARGET SELECTION ( = the name of \INC\target.pat file without the extension)
4 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
5 \ MSP_EXP430FR4133 MSP_EXP430FR2433 CHIPSTICK_FR2433 MSP_EXP430FR2355
8 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
12 \ drag and drop this file onto SendSourceFileToTarget.bat
13 \ then select your TARGET when asked.
15 \ COLD \ uncomment for this TEST which must not disrupt the downloading process
22 0<> IF MOV #0,TOS THEN \ if TOS <> 0 (UART TERMINAL), set TOS = 0
25 SUB #308,TOS \ FastForth V3.8
27 $0D EMIT \ return to column 1 without CR
28 ABORT" FastForth V3.8 please!"
29 ABORT" <-- Ouch! unexpected I2C_FastForth target!"
30 PWR_STATE \ remove ABORT_UARTI2CS definition before resuming
39 [UNDEFINED] DUP [IF] \ define DUP and DUP?
40 \ https://forth-standard.org/standard/core/DUP
41 \ DUP x -- x x duplicate top of stack
43 BW1 SUB #2,PSP \ 2 push old TOS..
44 MOV TOS,0(PSP) \ 3 ..onto stack
48 \ https://forth-standard.org/standard/core/qDUP
49 \ ?DUP x -- 0 | x x DUP if nonzero
51 CMP #0,TOS \ 2 test for TOS nonzero
58 \ https://forth-standard.org/standard/core/DROP
59 \ DROP x -- drop top of stack
67 \ https://forth-standard.org/standard/core/OVER
68 \ OVER x1 x2 -- x1 x2 x1
70 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
71 MOV @PSP,TOS \ 2 -- x1 (x2) x1
72 SUB #2,PSP \ 1 -- x1 x2 x1
78 \ https://forth-standard.org/standard/core/OnePlus
79 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
87 \ U/ u1 u2 -- q unsigned 16/16->q16
90 MOV #0,0(PSP) \ -- u1lo u1hi u2
91 CALL #MUSMOD \ -- r qlo qhi
92 MOV @PSP,TOS \ -- r qlo qlo
99 \ https://forth-standard.org/standard/core/toR
100 \ >R x -- R: -- x push to return stack
109 \ https://forth-standard.org/standard/core/Rfrom
110 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
120 \ https://forth-standard.org/standard/core/Equal
121 \ = x1 x2 -- flag test x1=x2
125 AND #0,TOS \ 1 flag Z = 1
133 [UNDEFINED] < [IF] \ define < and >
134 \ https://forth-standard.org/standard/core/less
135 \ < n1 n2 -- flag test n1<n2, signed
137 SUB @PSP+,TOS \ 1 TOS=n2-n1
138 S< ?GOTO FW1 \ 2 signed
140 BW1 MOV #-1,TOS \ 1 flag Z = 0
145 \ https://forth-standard.org/standard/core/more
146 \ > n1 n2 -- flag test n1>n2, signed
148 SUB @PSP+,TOS \ 2 TOS=n2-n1
149 S< ?GOTO BW1 \ 2 --> +5
150 FW1 AND #0,TOS \ 1 flag Z = 1
156 \ https://forth-standard.org/standard/core/IF
157 \ IF -- IFadr initialize conditional forward branch
161 MOV &DP,TOS \ -- HERE
162 ADD #4,&DP \ compile one word, reserve one word
163 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
164 ADD #2,TOS \ -- HERE+2=IFadr
168 \ https://forth-standard.org/standard/core/THEN
169 \ THEN IFadr -- resolve forward branch
171 MOV &DP,0(TOS) \ -- IFadr
177 [UNDEFINED] ELSE [IF]
178 \ https://forth-standard.org/standard/core/ELSE
179 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
181 ADD #4,&DP \ make room to compile two words
184 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
186 MOV W,TOS \ -- ELSEadr
191 [UNDEFINED] DO [IF] \ define DO LOOP +LOOP
192 \ https://forth-standard.org/standard/core/DO
193 \ DO -- DOadr L: -- 0
197 ADD #2,&DP \ make room to compile xdo
198 MOV &DP,TOS \ -- HERE+2
199 MOV #XDO,-2(TOS) \ compile xdo
200 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
202 MOV #0,0(W) \ -- HERE+2 L-- 0
206 \ https://forth-standard.org/standard/core/LOOP
207 \ LOOP DOadr -- L-- an an-1 .. a1 0
210 BW1 ADD #4,&DP \ make room to compile two words
212 MOV X,-4(W) \ xloop --> HERE
213 MOV TOS,-2(W) \ DOadr --> HERE+2
214 BEGIN \ resolve all "leave" adr
215 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
216 SUB #2,&LEAVEPTR \ --
217 MOV @TOS,TOS \ -- first LeaveStack value
218 CMP #0,TOS \ -- = value left by DO ?
220 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
226 \ https://forth-standard.org/standard/core/PlusLOOP
227 \ +LOOP adrs -- L-- an an-1 .. a1 0
234 [UNDEFINED] CASE [IF]
235 \ https://forth-standard.org/standard/core/CASE
236 : CASE 0 ; IMMEDIATE \ -- #of-1
238 \ https://forth-standard.org/standard/core/OF
239 : OF \ #of-1 -- orgOF #of
241 >R \ move off the stack in case the control-flow stack is the data stack.
242 POSTPONE OVER POSTPONE = \ copy and test case value
243 POSTPONE IF \ add orig to control flow stack
244 POSTPONE DROP \ discards case value if =
245 R> \ we can bring count back now
248 \ https://forth-standard.org/standard/core/ENDOF
249 : ENDOF \ orgOF #of -- orgENDOF #of
250 >R \ move off the stack in case the control-flow stack is the data stack.
252 R> \ we can bring count back now
255 \ https://forth-standard.org/standard/core/ENDCASE
256 : ENDCASE \ orgENDOF1..orgENDOFn #of --
265 CODE S_ \ Squote alias with blank separator instead quote
266 MOV #0,&CAPS \ turn CAPS OFF
268 XSQUOTE , \ compile run-time code
269 $20 WORD \ -- c-addr (= HERE)
271 MOV.B @TOS,TOS \ -- len compile string
272 ADD #1,TOS \ -- len+1
274 ADDC TOS,&DP \ store aligned DP
276 MOV @RSP+,IP \ pop paired with push COLON
277 MOV #$20,&CAPS \ turn CAPS ON (default state)
285 0= IF MOV @IP+,PC \ interpret time use is disallowed
289 POSTPONE LITERAL \ compile-time code : lit $1B
290 POSTPONE EMIT \ compile-time code : EMIT
291 POSTPONE S_ \ compile-time code : S_ <escape_sequence>
292 POSTPONE TYPE \ compile-time code : TYPE
298 ABORT" only for 1,4,8,16,24 MHz MCLK!"
302 $20 DUP EMIT ESC [7m \ set reverse video
303 ." with MCLK = " FREQ_KHZ @ 1000 U/ .
304 ABORT" MHz? don't dream!"
307 : CHNGBAUD \ only for 1, 4, 8, 16, 24 MHz
308 PWR_STATE \ removes this created word (garbage collector)
310 ESC [8;42;128t \ set 42L * 128C terminal display
311 41 0 DO CR LOOP \ to avoid erasing any line of source, create 42-1 empty lines
314 FREQ_KHZ @ DUP >R \ r-- target MCLCK frequency in MHz
315 ." target MCLK = " 1000 U/ . ." MHz" CR
316 ." choose your baudrate:" CR
317 ." 0 --> 6 MBds" CR \ >= 24 MHz
318 ." 1 --> 5 MBds" CR \ >= 20 MHz
319 ." 2 --> 4 MBds" CR \ >= 16 MHz
320 ." 3 --> 3 MBds" CR \ >= 12 MHz
321 ." 4 --> 1843200 Bds" CR \ >= 8 MHz
322 ." 5 --> 921600 Bds" CR \ >= 4 MHz
323 ." 6 --> 460800 Bds" CR \ >= 2 MHz
324 ." 7 --> 230400 Bds" CR \ >= 1 MHz
325 ." 8 --> 115200 Bds" CR \ >= 500 kHz
326 ." 9 --> 38400 Bds" CR
327 ." A --> 19200 Bds" CR
328 ." B --> 9600 Bds" CR
329 ." other --> abort" CR
334 #48 OF ." 6 MBds" \ add this to the current line
336 #24000 OF $4 $0 \ -- TERM_BRW TERM_MCTLW
339 IF OVR_BAUDS \ < 24 MHz --> abort
340 THEN BAD_MHz \ other MHz --> abort
345 #24000 OF $4 $EE00 ENDOF
346 #20000 OF $4 $0 ENDOF
348 IF OVR_BAUDS \ < 20 MHz --> abort
349 THEN BAD_MHz \ other MHz --> abort
354 #24000 OF $6 $0 ENDOF
355 #20000 OF $5 $0 ENDOF
356 #16000 OF $4 $0 ENDOF
358 IF OVR_BAUDS \ < 16 MHz --> abort
359 THEN BAD_MHz \ other MHz --> abort
364 #24000 OF $8 $0 ENDOF
365 #20000 OF $6 $D600 ENDOF
366 #16000 OF $5 $4900 ENDOF
367 #12000 OF $4 $0 ENDOF
369 IF OVR_BAUDS \ < 12 MHz --> abort
370 THEN BAD_MHz \ other MHz --> abort
373 #52 OF ." 1843200 Bds"
375 #24000 OF $0D $0200 ENDOF
376 #20000 OF $0A $DF00 ENDOF
377 #16000 OF $8 $D600 ENDOF
378 #12000 OF $6 $AA00 ENDOF
379 #8000 OF $5 $9200 ENDOF
381 IF OVR_BAUDS \ < 8 MHz --> abort
382 THEN BAD_MHz \ other MHz --> abort
385 #53 OF ." 921600 Bds"
387 #24000 OF $1 $00A1 ENDOF
388 #20000 OF $1 $B751 ENDOF
389 #16000 OF $11 $4A00 ENDOF
390 #12000 OF $0D $0200 ENDOF
391 #8000 OF $8 $D600 ENDOF
392 #4000 OF $4 $4900 ENDOF
394 IF OVR_BAUDS \ < 4 MHz --> abort
395 THEN BAD_MHz \ other MHz --> abort
398 #54 OF ." 460800 Bds"
400 #24000 OF $3 $0241 ENDOF
401 #20000 OF $2 $92B1 ENDOF
402 #16000 OF $2 $BB21 ENDOF
403 #12000 OF $1 $00A1 ENDOF
404 #8000 OF $11 $4A00 ENDOF
405 #4000 OF $8 $D600 ENDOF
406 #2000 OF $4 $4900 ENDOF
408 IF OVR_BAUDS \ < 2 MHz --> abort
409 THEN BAD_MHz \ other MHz --> abort
412 #55 OF ." 230400 Bds"
414 #24000 OF $6 $2081 ENDOF
415 #20000 OF $5 $EE61 ENDOF
416 #16000 OF $4 $5551 ENDOF
417 #12000 OF $3 $0241 ENDOF
418 #8000 OF $2 $BB21 ENDOF
419 #4000 OF $11 $4A00 ENDOF
420 #2000 OF $8 $D600 ENDOF
421 #1000 OF $4 $4900 ENDOF
423 IF OVR_BAUDS \ < 1 MHz --> abort
424 THEN BAD_MHz \ other MHz --> abort
427 #56 OF ." 115200 Bds"
429 #24000 OF $0D $4901 ENDOF
430 #20000 OF $0A $AD01 ENDOF
431 #16000 OF $8 $F7A1 ENDOF
432 #12000 OF $6 $2081 ENDOF
433 #8000 OF $4 $5551 ENDOF
434 #4000 OF $2 $BB21 ENDOF
435 #2000 OF $11 $4A00 ENDOF
436 #1000 OF $8 $D600 ENDOF
437 #500 OF $4 $4900 ENDOF
439 IF OVR_BAUDS \ < 500 Khz --> abort
440 THEN BAD_MHz \ other MHz --> abort
445 #24000 OF $27 $0011 ENDOF
446 #16000 OF $1A $D601 ENDOF
447 #8000 OF $0D $4901 ENDOF
448 #4000 OF $6 $2081 ENDOF
449 #1000 OF $1 $00A1 ENDOF
450 BAD_MHz \ other MHz --> abort
455 #24000 OF $4E $0021 ENDOF
456 #16000 OF $34 $4911 ENDOF
457 #8000 OF $1A $D601 ENDOF
458 #4000 OF $0D $4901 ENDOF
459 #1000 OF $3 $0241 ENDOF
460 BAD_MHz \ other MHz --> abort
465 #24000 OF $9C $0041 ENDOF
466 #16000 OF $68 $D621 ENDOF
467 #8000 OF $34 $4911 ENDOF
468 #4000 OF $1A $D601 ENDOF
469 #1000 OF $6 $2081 ENDOF
470 BAD_MHz \ other MHz --> abort
473 ." abort" ABORT" " \ ABORT" displays nothing
475 TERMMCTLW_RST ! \ set UCAxMCTLW value in FRAM
476 TERMBRW_RST ! \ set UCAxBRW value in FRAM
477 CR ESC [7m \ escape sequence to set reverse video
478 ." Change baudrate in Teraterm, save its setup, then reset target."