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
21 \ first, we do some tests allowing the download
26 BIT #$3C00,TOS \ BIT13|BIT12|BIT11|BIT10 test (UART TERMINAL test)
27 0<> IF MOV #0,TOS THEN \ if TOS <> 0 (UART TERMINAL), set TOS = 0
30 SUB #400,TOS \ FastForth V4.0
32 $0D EMIT \ return to column 1 without CR
33 ABORT" FastForth V4.0 please!"
34 ABORT" <-- Ouch! unexpected I2C_FastForth target!"
35 RST_RET \ remove ABORT_UARTI2CS definition before resuming
40 ; ------------------------------------------------------------------
41 ; first we download the set of definitions we need (from CORE_ANS.f)
42 ; ------------------------------------------------------------------
44 [UNDEFINED] DUP [IF] \ define DUP and DUP?
45 \ https://forth-standard.org/standard/core/DUP
46 \ DUP x -- x x duplicate top of stack
48 BW1 SUB #2,PSP \ 2 push old TOS..
49 MOV TOS,0(PSP) \ 3 ..onto stack
53 \ https://forth-standard.org/standard/core/qDUP
54 \ ?DUP x -- 0 | x x DUP if nonzero
56 CMP #0,TOS \ 2 test for TOS nonzero
63 \ https://forth-standard.org/standard/core/DROP
64 \ DROP x -- drop top of stack
72 \ https://forth-standard.org/standard/core/OVER
73 \ OVER x1 x2 -- x1 x2 x1
75 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
76 MOV @PSP,TOS \ 2 -- x1 (x2) x1
77 SUB #2,PSP \ 1 -- x1 x2 x1
83 \ https://forth-standard.org/standard/core/CR
84 \ CR -- send CR+LF to the output device
86 \ DEFER CR \ DEFERed definition, by default executes that of :NONAME
88 MOV #NEXT_ADR,PC \ compile same as DEFER
97 \ https://forth-standard.org/standard/core/OnePlus
98 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
106 \ U/ u1 u2 -- q unsigned 16/16->q16
109 MOV #0,0(PSP) \ -- u1lo u1hi u2
110 CALL #MUSMOD \ -- r qlo qhi
111 MOV @PSP,TOS \ -- r qlo qlo
118 \ https://forth-standard.org/standard/core/toR
119 \ >R x -- R: -- x push to return stack
128 \ https://forth-standard.org/standard/core/Rfrom
129 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
139 \ https://forth-standard.org/standard/core/Equal
140 \ = x1 x2 -- flag test x1=x2
144 AND #0,TOS \ 1 flag Z = 1
152 [UNDEFINED] < [IF] \ define < and >
153 \ https://forth-standard.org/standard/core/less
154 \ < n1 n2 -- flag test n1<n2, signed
156 SUB @PSP+,TOS \ 1 TOS=n2-n1
157 S< ?GOTO FW1 \ 2 signed
159 BW1 MOV #-1,TOS \ 1 flag Z = 0
164 \ https://forth-standard.org/standard/core/more
165 \ > n1 n2 -- flag test n1>n2, signed
167 SUB @PSP+,TOS \ 2 TOS=n2-n1
168 S< ?GOTO BW1 \ 2 --> +5
169 FW1 AND #0,TOS \ 1 flag Z = 1
174 [UNDEFINED] IF [IF] \ define IF THEN
175 \ https://forth-standard.org/standard/core/IF
176 \ IF -- IFadr initialize conditional forward branch
180 MOV &DP,TOS \ -- HERE
181 ADD #4,&DP \ compile one word, reserve one word
182 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
183 ADD #2,TOS \ -- HERE+2=IFadr
187 \ https://forth-standard.org/standard/core/THEN
188 \ THEN IFadr -- resolve forward branch
190 MOV &DP,0(TOS) \ -- IFadr
196 [UNDEFINED] ELSE [IF]
197 \ https://forth-standard.org/standard/core/ELSE
198 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
200 ADD #4,&DP \ make room to compile two words
203 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
205 MOV W,TOS \ -- ELSEadr
210 [UNDEFINED] DO [IF] \ define DO LOOP +LOOP
211 \ https://forth-standard.org/standard/core/DO
212 \ DO -- DOadr L: -- 0
213 HDNCODE XDO \ DO run time
214 MOV #$8000,X \ 2 compute 8000h-limit = "fudge factor"
216 MOV TOS,Y \ 1 loop ctr = index+fudge
217 ADD X,Y \ 1 Y = INDEX
218 PUSHM #2,X \ 4 PUSHM X,Y, i.e. PUSHM LIMIT, INDEX
226 ADD #2,&DP \ make room to compile xdo
227 MOV &DP,TOS \ -- HERE+2
228 MOV #XDO,-2(TOS) \ compile xdo
229 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
231 MOV #0,0(W) \ -- HERE+2 L-- 0
235 \ https://forth-standard.org/standard/core/LOOP
236 \ LOOP DOadr -- L-- an an-1 .. a1 0
237 HDNCODE XLOOP \ LOOP run time
238 ADD #1,0(RSP) \ 4 increment INDEX
239 BW1 BIT #$100,SR \ 2 is overflow bit set?
240 0= IF \ branch if no overflow
244 ADD #4,RSP \ 1 empties RSP
245 ADD #2,IP \ 1 overflow = loop done, skip branch ofs
246 MOV @IP+,PC \ 4 14~ taken or not taken xloop/loop
251 BW2 ADD #4,&DP \ make room to compile two words
253 MOV X,-4(W) \ xloop --> HERE
254 MOV TOS,-2(W) \ DOadr --> HERE+2
255 BEGIN \ resolve all "leave" adr
256 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
257 SUB #2,&LEAVEPTR \ --
258 MOV @TOS,TOS \ -- first LeaveStack value
259 CMP #0,TOS \ -- = value left by DO ?
261 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
267 \ https://forth-standard.org/standard/core/PlusLOOP
268 \ +LOOP adrs -- L-- an an-1 .. a1 0
269 HDNCODE XPLOO \ +LOOP run time
270 ADD TOS,0(RSP) \ 4 increment INDEX by TOS value
271 MOV @PSP+,TOS \ 2 get new TOS, doesn't change flags
277 GOTO BW2 \ goto BW1 LOOP
281 [UNDEFINED] CASE [IF] \ define CASE OF ENDOF ENDCASE
282 \ https://forth-standard.org/standard/core/CASE
283 : CASE 0 ; IMMEDIATE \ -- #of-1
285 \ https://forth-standard.org/standard/core/OF
286 : OF \ #of-1 -- orgOF #of
288 >R \ move off the stack in case the control-flow stack is the data stack.
289 POSTPONE OVER POSTPONE = \ copy and test case value
290 POSTPONE IF \ add orig to control flow stack
291 POSTPONE DROP \ discards case value if =
292 R> \ we can bring count back now
295 \ https://forth-standard.org/standard/core/ENDOF
296 : ENDOF \ orgOF #of -- orgENDOF #of
297 >R \ move off the stack in case the control-flow stack is the data stack.
299 R> \ we can bring count back now
302 \ https://forth-standard.org/standard/core/ENDCASE
303 : ENDCASE \ orgENDOF1..orgENDOFn #of --
311 ; --------------------------
312 ; end of definitions we need
313 ; --------------------------
316 CODE S_ \ Squote alias with blank instead quote separator
320 MOV #S"+10,PC \ addr S" + 10 --> PC
327 0= IF MOV @IP+,PC \ interpret time use is disallowed
331 POSTPONE LITERAL \ compile-time code : lit $1B
332 POSTPONE EMIT \ compile-time code : EMIT
333 POSTPONE S_ \ compile-time code : S_ <escape_sequence>
334 POSTPONE TYPE \ compile-time code : TYPE
340 ABORT" only for 1,4,8,16,24 MHz MCLK!"
344 $20 DUP EMIT ESC [7m \ set reverse video
345 ." with MCLK = " FREQ_KHZ @ 1000 U/ .
346 ABORT" MHz? don't dream!"
349 : CHNGBAUD \ only for 1, 4, 8, 16, 24 MHz
350 RST_RET \ removes this created word (garbage collector)
352 ESC [8;42;80t \ set 42L * 80C terminal display
353 41 0 DO CR LOOP \ to avoid erasing any line of source, create 42-1 empty lines
356 FREQ_KHZ @ DUP >R \ r-- target MCLCK frequency in MHz
357 ." target MCLK = " 1000 U/ . ." MHz" CR
358 ." choose your baudrate:" CR
359 ." 0 --> 6 MBds" CR \ >= 24 MHz
360 ." 1 --> 5 MBds" CR \ >= 20 MHz
361 ." 2 --> 4 MBds" CR \ >= 16 MHz
362 ." 3 --> 3 MBds" CR \ >= 12 MHz
363 ." 4 --> 1843200 Bds" CR \ >= 8 MHz
364 ." 5 --> 921600 Bds" CR \ >= 4 MHz
365 ." 6 --> 460800 Bds" CR \ >= 2 MHz
366 ." 7 --> 230400 Bds" CR \ >= 1 MHz
367 ." 8 --> 115200 Bds" CR \ >= 500 kHz
368 ." 9 --> 38400 Bds" CR
369 ." A --> 19200 Bds" CR
370 ." B --> 9600 Bds" CR
371 ." other --> abort" CR
375 #48 OF ." 6 MBds" \ add this to the current line
377 #24000 OF $4 $0 \ -- TERM_BRW TERM_MCTLW
380 IF OVR_BAUDS \ < 24 MHz --> abort
381 THEN BAD_MHz \ other MHz --> abort
386 #24000 OF $4 $EE00 ENDOF
387 #20000 OF $4 $0 ENDOF
389 IF OVR_BAUDS \ < 20 MHz --> abort
390 THEN BAD_MHz \ other MHz --> abort
395 #24000 OF $6 $0 ENDOF
396 #20000 OF $5 $0 ENDOF
397 #16000 OF $4 $0 ENDOF
399 IF OVR_BAUDS \ < 16 MHz --> abort
400 THEN BAD_MHz \ other MHz --> abort
405 #24000 OF $8 $0 ENDOF
406 #20000 OF $6 $D600 ENDOF
407 #16000 OF $5 $4900 ENDOF
408 #12000 OF $4 $0 ENDOF
410 IF OVR_BAUDS \ < 12 MHz --> abort
411 THEN BAD_MHz \ other MHz --> abort
414 #52 OF ." 1843200 Bds"
416 #24000 OF $0D $0200 ENDOF
417 #20000 OF $0A $DF00 ENDOF
418 #16000 OF $8 $D600 ENDOF
419 #12000 OF $6 $AA00 ENDOF
420 #8000 OF $5 $9200 ENDOF
422 IF OVR_BAUDS \ < 8 MHz --> abort
423 THEN BAD_MHz \ other MHz --> abort
426 #53 OF ." 921600 Bds"
428 #24000 OF $1 $00A1 ENDOF
429 #20000 OF $1 $B751 ENDOF
430 #16000 OF $11 $4A00 ENDOF
431 #12000 OF $0D $0200 ENDOF
432 #8000 OF $8 $D600 ENDOF
433 #4000 OF $4 $4900 ENDOF
435 IF OVR_BAUDS \ < 4 MHz --> abort
436 THEN BAD_MHz \ other MHz --> abort
439 #54 OF ." 460800 Bds"
441 #24000 OF $3 $0241 ENDOF
442 #20000 OF $2 $92B1 ENDOF
443 #16000 OF $2 $BB21 ENDOF
444 #12000 OF $1 $00A1 ENDOF
445 #8000 OF $11 $4A00 ENDOF
446 #4000 OF $8 $D600 ENDOF
447 #2000 OF $4 $4900 ENDOF
449 IF OVR_BAUDS \ < 2 MHz --> abort
450 THEN BAD_MHz \ other MHz --> abort
453 #55 OF ." 230400 Bds"
455 #24000 OF $6 $2081 ENDOF
456 #20000 OF $5 $EE61 ENDOF
457 #16000 OF $4 $5551 ENDOF
458 #12000 OF $3 $0241 ENDOF
459 #8000 OF $2 $BB21 ENDOF
460 #4000 OF $11 $4A00 ENDOF
461 #2000 OF $8 $D600 ENDOF
462 #1000 OF $4 $4900 ENDOF
464 IF OVR_BAUDS \ < 1 MHz --> abort
465 THEN BAD_MHz \ other MHz --> abort
468 #56 OF ." 115200 Bds"
470 #24000 OF $0D $4901 ENDOF
471 #20000 OF $0A $AD01 ENDOF
472 #16000 OF $8 $F7A1 ENDOF
473 #12000 OF $6 $2081 ENDOF
474 #8000 OF $4 $5551 ENDOF
475 #4000 OF $2 $BB21 ENDOF
476 #2000 OF $11 $4A00 ENDOF
477 #1000 OF $8 $D600 ENDOF
478 #500 OF $4 $4900 ENDOF
480 IF OVR_BAUDS \ < 500 Khz --> abort
481 THEN BAD_MHz \ other MHz --> abort
486 #24000 OF $27 $0011 ENDOF
487 #16000 OF $1A $D601 ENDOF
488 #8000 OF $0D $4901 ENDOF
489 #4000 OF $6 $2081 ENDOF
490 #1000 OF $1 $00A1 ENDOF
491 BAD_MHz \ other MHz --> abort
496 #24000 OF $4E $0021 ENDOF
497 #16000 OF $34 $4911 ENDOF
498 #8000 OF $1A $D601 ENDOF
499 #4000 OF $0D $4901 ENDOF
500 #1000 OF $3 $0241 ENDOF
501 BAD_MHz \ other MHz --> abort
506 #24000 OF $9C $0041 ENDOF
507 #16000 OF $68 $D621 ENDOF
508 #8000 OF $34 $4911 ENDOF
509 #4000 OF $1A $D601 ENDOF
510 #1000 OF $6 $2081 ENDOF
511 BAD_MHz \ other MHz --> abort
514 ." abort" ABORT" " \ ABORT" " displays nothing
516 TERMMCTLW_RST ! \ set UCAxMCTLW value in FRAM
517 TERMBRW_RST ! \ set UCAxBRW value in FRAM
518 CR ESC [7m \ escape sequence to set reverse video
519 ." Change baudrate in Teraterm, save its setup, then reset target."