1 #FastForth for MSP430FRxxxx TI's devices, light, fast, efficient, reliable.
3 Tested on TI MSP-EXP430FR(5739,5969,5994,6989,4133,2355,2433) launchpads, at 1, 2, 4, 8, 12, 16 MHz plus 20MHz & 24MHz with MSP430FR(23xx,57xx) devices.
5 It's an "interpret and compile" operating system for MSP430 devices with FRAM, very interesting because of its 5kB size.
9 * the kernel FORTH with interpreting double numbers and Q15.16 numbers,
11 * an assembler with TI's syntax, "label free", with conditional compilation,
13 * a 16-input search engine that speeds up the interpreter by 4,
15 * an UART TERMINAL up to 6MBds, with software (XON/XOFF) + hardware (RTS) control flow,
17 * or an I2C TERMINAL up to 1MHz (overruns 2.5 times the TI specifications), see \MSP430-FORTH\UARTI2CS.f.
19 After downloading \MSP430-FORTH\ANS_COMP.f, FastForth becomes a true ANS FORTH for afficionados.
20 Personally I use it mainly as super OS for real time programs.
22 If your goal is to learn or to teach programming with assembler, don't miss it, try it!
24 For only 3 kbytes in addition, you have the primitives to access the SD\_CARD FAT16 and FAT32: read, write, del, download source files and to copy them from PC to the SD_Card. It works with all SD\_CARD memories from 64MB to 64GB. The cycle of read/write a byte is below 1 us @ 16 MHz.
26 With all the kernel addons, including extended\_ASM and SD\_Card driver, FastForth size is 10 kB.
28 However, if all works well with Windows 10, it works less well with Linux due to the lack of a good alternative to TERATERM...
30 Note: for every update, download all subdirectories to correctly update the project, without missing configurations files.
32 ##how to connect TERMINAL
34 The files \binaries\launchpad_xMHz.txt are the executables ready to use with a serial terminal
35 (TERATERM.exe), 115200Bds, with XON/XOFF or RTS_hardware flow controls and a PL2303TA/CP2102 cable.
36 ------------------------------------------------------------------------------------------
37 WARNING! doesn't use them to supply your launchpad: red wire is 5V ==> MSP430FRxxxx destroyed!
38 ------------------------------------------------------------------------------------------
39 (modify this first, by opening the box to weld red wire on 3.3V pad).
41 programming with MSP430Flasher.exe and FET interface
43 TI Launchpad <--> CP2102/PL2302TA cable <------> USB <-------------> TERATERM.exe
45 GND <--> GND > used by FastForth TERMINAL
47 RTS ---> CTS (optionnal) RTS pin Px.y is described in your \inc\launchpad.asm)
49 TI Launchpad <--> FET interface <-------------> USB <-------------> MSP430Flasher.exe
51 TST/SBWTCK <--> SBWTCK
53 RST/SBWTDIO <--> SBWTDIO
55 programming with BSL_Scripter.exe
57 TI Launchpad <--> CP2102/PL2303TA cable <------> USB <-------->+<--> TERATERM.exe
59 GND <--> GND > used by FastForth TERMINAL +<--> BSL_Scripter.exe
63 GND <--> GND > used by BSL_Scripter
64 RST/SBWTDIO <--> DTR )
66 Before programming device, close teraterm TERMINAL and connect the wire RST/SBWTDIO <--> DTR
67 Once device is programmed, open teraterm TERMINAL then disconnect the wire RST/SBWTDIO <--> DTR.
71 Once FastForth is loaded in the target FRAM memory, you add assembly code or FORTH code, or both,
72 by downloading your source files which embedded FastForth and its assembler interpret and compile.
74 Beforehand, the preprocessor GEMA, by means of a \config\gema\target.pat file, will have translated
75 your generic MSP430FR source file.f in a targeted MSP430FRxxxx source file.4th, allowing you to use
76 symbolic addressing for all peripheral registers, without having to do declarations via FORTH words.
77 A set of .bat files in \MSP430-FORTH folder is furnished to do all this automatically.
79 To see all specifications of FastForth, download \MSP430-FORTH\FF_SPECS.f.
81 To change the terminal baudrate on the fly, 9600 Bauds up to 6 MBds,
82 download the file \MSP430-FORTH\CHNGBAUD.f.
83 Beyond 1 MBds, shorten the PL2303HXD cable, down to 20 cm for 6MBds.
85 XON/XOFF flow control allows 3.75kV galvanic isolation of terminal input with SOIC8 Si8622EC|ISO7021.
86 With powered SOIC16W ISOW7821, you have 5kV rms isolation for both XON/XOFF TERMINAL and a 3V3 75mA supply.
88 If you choose I2C_FastForth for your target, you will need of one more to make the USBtoI2C bridge.
90 After downloading of complementary words in \MSP430-FORTH\ANS_COMP.f, FastForth executes CORETEST.4th
91 in less than a second, and without errors which ensures its compatibility with the FORTH CORE ANS94 standard.
93 Notice that FAST FORTH interprets lines up to 84 chars, only SPACE as delimiter, only CR+LF as
94 End Of Line, and BACKSPACE.
95 And that the high limit of FORTH program memory is $FF80.
97 Finally, using the SCITE editor as IDE, all is ready to do everything from its "tools" menu.
104 54 bytes added to (Kernel + Conditional_Compilation + Assembler).
106 Source file copy from I2C_TERMINAL to the SD_Card of any I2C_target works now.
108 The bootstrap call is modified: ' BOOT IS WARM to start it,
109 ' BOOT 2 + @ IS WARM to stop it.
111 In addition of target's ID test made by Teraterm macro, a preamble has been added to all
112 \MSP430-FORTH\source.f files to prohibit their downloading with another version of FastForth.
114 Words @ ! ALLOT come back from "ANS_COMP" add-on to core.
116 Recognized prefixes are $ # % and ' respectively for hex decimal binary and ASCII 'char' numbers.
117 Examples: 'U' - $55 = 0, '3' - #33 = 0, '@' - %0100_0000 = 0.
118 When use in source.f files, all ASCII special chars are available. See \inc\FastForthREGtoTI.pat.
120 Assembler allows "argument+offset" into FORTH area (0 to $FFFF).
121 Examples: MOV #RXON,&SLEEP+2 to store RXON addr at SLEEP+2 addr.
122 MOV.B BUFFER+-1(X),TOS to load the byte at BUFFER-1(X) addr in the register TOS.
124 COLD does same than hardware RST.
125 WIPE does same than hardware SW1+RST (DEEP_RESET).
130 In the FastForth init process, COLD WARM SLEEP are modified and INI_FORTH is added.
131 They start each with an immediate call to a paired assembly subroutine:
133 RST_SYS failures ->+ +<- ABORT_TERM <- ABORT" <-(error)<-+-<-COMPILE/EXECUTE<-INTERPRET<-+
136 SW1+RST->+<-RST | +--> INI_FORTH -> ABORT" ->+->QUIT>-+->ACCEPT->+ +->ACCEPT->+
139 words: WIPE -->+->COLD-->+-> RESET -> INI_FORTH --> WARM -->+ +->SLEEP->+
140 ---- --------- ---- -----
142 subroutine: COLD_APP INI_SOFT_APP INI_HARD_APP BACKGND_APP
143 default CALL# COLD_TERM RET_ADR INIT_TERM RXON
144 Default action: wait TERMINAL idle do nothing init TERM UCAx enable TERMINAL TX
145 + unlock I/O's (send RXON + /RTS)
148 On the other hand, MARKER is modified in such a way that MARKER_DOES executes a CALL to
149 the content of BODY+4, by default RET_ADR:
151 MARKER [CFA] = DODOES
153 [BODY] = previous DP (Dictionnary Pointer)
154 [BODY+2] = previous VOCLINK (if word-set addon)
157 By replacing [BODY+4] with the address of a new defined subroutine (named for example: STOP_XXX),
158 MARKER_DOES will execute it to restore all critical pointers saved at BODY+6, BODY+8...
160 Thus, with MARKER and the definition of subroutines COLD_XXX, INI_SOFT_XXX, INI_HARD_XXX, BACKGND_XXX
161 the programmer has full control of his "XXX" real time application using interrupts,
162 with everything he needs to start it, stop it, and also to properly remove it with
163 a 'soft' MARKER word, avoiding the use of a WIPE or a SW1+RST of the last chance.
165 See examples in /MSP430-FORTH/UARTI2CS.f, /MSP430-FORTH/RTC.f.
167 notes: RST and SW1+RST (deep RST) are hardware redirected to COLD via NMI and the USER_NMI vector.
168 INI_SOFT_SD is used as INI_SOFT_APP alias by the SD_CARD driver to reinit handles.
169 WIPE|SW1+RST initialises this four APP calls plus TERMINAL_INT Vector.
174 8 bytes added to (Kernel + Conditional_Compilation + Assembler).
176 Fixed the crash caused by forgetting the prefix '&' in the last term of an assembly instruction.
177 (the TI's symbolic mode is not implemented).
179 Added in the macro \config\SendFile.ttl the word ?ID to prevent any crash during download
180 due to a device confusion:
181 When downloading a source_file.f asked from the scite editor or by the use
182 of SendSourceFileToTarget.bat, Teraterm macro first sends ?ID definition then
183 the string: %deviceID% ?ID.
184 By executing ?ID, FastForth substracts %deviceID% value from the target's one then
185 executes ABORT" DeviceID mismatch!" : the downloading is aborted if DeviceID mismatch.
186 %deviceID% is provided by the file \config\select.bat.
188 When downloading a source_file.4TH, it's up to you to be careful because
189 Teraterm sends the string 0 ?ID, so that ?ID bypasses the substraction.
190 (when a source_file.4TH is issued from a source_file.f, you can verify
191 the target name in its header).
193 Added the word set DOUBLE in the \MSP430-FORTH\DOUBLE.f file.
199 from Scite menu, we can program MSP430FRxxxx also with BSL_Scripter.
201 To do, save file \prog\BSL_Scripter.exe from:
202 https://github.com/drcrane/bslscripter-vs2017/releases/download/v3.4.2/BSL-Scripter-v3.4.2.zip,
203 but erasing a MSP430FR2355 doesn't work.
205 and buy a USB2UART module CP2102 6 pin. On the web, search: "CP2102 3.3V DTR RTS"
206 For wiring, see \config\BSL_Prog.bat.
208 So, we download both binaries and source files with only one CP2102|PL2303TA module,
209 the XON/XOFF TERMINAL and BSL_Scripter. Bye bye T.I. FET!
211 ABORT messages display first the I2C address, if applicable.
212 QNUMBER some issues solved.
213 UART version of ACCEPT and KEY are shortened.
214 EVALUATE is moved to CORE_ANS.
220 for kernel compiling use the last version of srecord (1.64) to enable overlapping in vectors area.
222 The forthMSP430FR.lst output file is more readable because purged of all unused conditionnal parts.
224 Fixed: word F. issue in FIXPOINT.asm
226 Moved: words ALLOT and DOES> to CORE_ANS.asm/f files.
228 CORDIC.f also works without hardware MPY (MSP430FR4133).
230 By compiling :NONAME CODENNM DEFER IS, the new option DEFERRED superseeds the old NONAME option.
232 pin RESET is software replaced by pin NMI and so, RESET executes COLD, allowing code insert before BOR.
233 however SYSRSTIV numbering remains unchanged: = 4 for RESET, = 6 for COLD.
235 Deep RESET reinitializes vectors interrupts and SIGNATURES area, as WIPE.
237 Fast Forth Deep RESET is done by switches S1 + RST.
240 A newcomer: FastForth for I2C TERMINAL. With the driver UART2I2CS running on another FastForth target,
241 we have the USB to I2C_Slave bridge we need: one TERMINAL for up to 112 I2C_FastForth targets.
243 +---------------------------+
244 notebook USB to I2C_Slave bridge +-I2C-| others I2C_slave target |
245 +-----------+ +-------------------------------------------------+ / +--------------------------+ |
246 | | ¦ PL2303HXD target running UARTI2CS @24MHz¦ +-I2C-| MSP430FR4133 @ 1 MHz | |
247 | | ¦------------+ +----------------------------¦ / +--------------------------+ |--+
248 | | ¦ | 3wires| MSP430FR2355 @ 24MHz ¦/ | MSP430FR5738 @ 24 MHz | |
249 | TERATERM -o->USB-o->USB2UART->o->UART-o-> FAST FORTH -> UARTI2CS -o-I2C-o-> FAST FORTH with option |--+
250 | terminal | ¦ | 6MBds | (I2C MASTER) ¦ | TERMINAL_I2C (I2C SLAVE)|
251 | | ¦------------+ +----------------------------¦ +--------------------------+
252 | | ¦ |< 20cm>| ¦ up to 112 I2C_Slave targets
253 +-----------+ +-------------------------------------------------+
255 With the indicated MCLK and UART speeds, Coretest.4th is downloaded to (and executed by) I2C_Slave in 800ms.
256 The driver UARTI2CS works without error from 1MHz up to 24MHz MCLK and from 115200Bds up to 6MBds UART.
257 With I2C_Master running at 24 MHz, the I2C bus frequency is about 1MHz, and it works fine even if I2C_slave is running at 1 MHz.
258 Don't forget to add two 3k3 pullup resistors on SCL and SDA...
260 the copy of a file to I2C target SD_Card doesn't work.
262 the Multi Master Mode works but is not tested in multi master environment.
264 "Cherry on the pudding", when they wait for a TERMINAL input (idle state),
265 both I2C_Master and I2C_Slave(s) are sleeping in LPMx mode and the bus I2C is freed.
266 Sleep modes down to LPM4 are available for I2C_Slave devices.
268 The driver UART2I2CS doesn't use the UCBx I2C_Master hardware, really too bad, but
269 profitably its software version, much more faster, which consumes just two I/O (better in the range Px0-Px3),
270 the UCBx remaining available for another I2C_Slave or SPI driver.
272 On the side of I2C_Slave, pins SDA SCL are those defined as BUS_TERM in the file \inc\your_target.asm.
273 I2CSLA0, in the file forthMSP430FR.asm, defines the I2C_Slave address of the I2C FastForth module.
274 for I2C_Master, see \inc\your_UARTI2CS_bridge.pat the correspondence of SM_SCL and SM_SDA.
279 first you make a I2C cable (GND,SDA,SCL,3V3) between your 2 LaunchPad, with 3,3k pullup resistors on SDA and SCL lines.
280 see each of two /inc/target.pat files to know SDA ans SCL pins.
282 to compile FastForth for I2C TERMINAL from forthMSP430FR.asm file:
283 1- uncomment the line "TERMINAL_I2C".
284 2- search "I2CSLAVEADR" line and set your <slave address you want>, i.e. 10h.
285 3- compile file then prog your I2C_Slave LaunchPad.
287 with the another LaunchPad running FastForth:
288 At line 610 of UART2I2CS.f file set the <slave address you want>, i.e. $10.
289 then download it, it's done: TERMINAL is linked to I2C_Slave.
291 Type `Alt+B` on teraterm (send UART break) to unlink I2C_Slave.
296 Kernel + FIXPOINT input + DOUBLE input + :NONAME + Conditional Compilation + Assembler under 5 kB.
298 the FORTH kernel is drastically reduced to 55 words.
299 All others are moved in the \ADDON\ANS_COMPLEMENT.asm file,
300 the conditionnal compilation with the assembler allowing to reuse them on request.
303 ACCEPT (XON/XOFF TERMINAL with MSP430FR2xxx).
306 FF_SPECS.f displays FastForth environment.
310 -584 bytes, Kernel + Conditional Compilation + Assembler under 5.5 kb.
312 the FORTH kernel is drastically reduced to 82 words, just what the operating system needs.
313 All others are moved in the \ADDON\ANS_COMPLEMENT.asm file, the conditionnal compilation
314 allowing you to use them on request.
316 Taking into account the new TI launchpad LP_MSP430FR2476.
318 Fixed: :NONAME (now aligned), LOAD" (no more crash on error).
319 Modified: ACCEPT, WORD, HEADER, CODE, ENDCODE, ASM, GOTO, ?GOTO, RPT.
320 Removed JMP <word> and ?JMP <word> from assembler (replaced by GOTO BWx and ?GOTO BWx).
322 ACCEPT is modified to include the RXON call in the word SLEEP.
323 By rewriting the defered word SLEEP, we can easily disable the TERMINAL_INPUT interrupt.
324 See BACKGROUND, START and STOP in \MSP430-FORTH\RC5toLCD.f.
329 The prompt "ok" becomes a compilation option.
331 Taking into account the digit separator '_' in ?NUMBER, to better see when typing binary numbers.
332 example: %1010100011000111 can be typed as well: %1010_1000_1100_0111
336 Modified GetFreeHandle CloseHandle
338 Tested with BLE 5.0 terminal (a couple of BGX13P EVK) at 16MHz, 921600 bds + terminal 5 wires:
339 download throughput = 5 kbytes/s (and with errors when ECHO is ON), disappointing...
340 (Bluetooth 2.1 terminal with one RN42 works well).
342 RePeaTed instructions RRUX,RRCX,RLAX,ADDX,SUBX work fine! See TESTASMX.4TH
348 added experimental extended_assembler (MSP430FR5969,MSP430FR5994,MSP430FR6989)
353 Simplified directory structure of project.
354 Added switch DOUBLE_INPUT as kernel compilation ADDON, removed switch LOWERCASE.
355 Added \MSP430-FORTH\CORDIC.f for aficionados.
356 Added FF_SPECS.4th to show all specificities of FastForth compilation.
357 Corrected LITERAL (double LITERAL part).
358 Modified ACCEPT COLD WARM ?ABORT, S", QNUMBER.
363 Unlocking I/O's is transfered from RESET to WARM.
364 Thus, by redirecting WARM, you can add I/O's configuration of your application before unlock them.
366 two options to do this:
369 your START routine is inserted in WARM and continues with the default WARM.
370 Search "START" in the \MSP430_FORTH\IR_RC5.f file as application example.
373 START routine replaces WARM and continues with ABORT (without WARM message).
374 In this case, you can also change the Reset events handling but you will need to unlock I/O's
375 and configure TERMINAL I/O's in your START routine.
376 Search "activate I/O" in \MSP430_FORTH\RC5toLCD.f file to see how to do.
378 Bugs corrected in target.asm, target.pat and device.inc files.
382 The terminal baudrate can be changed on the fly. Download MSP430-FORTH\CHNGBAUD.f to do.
386 Bugs corrected: ALSO and :NONAME (option).
388 The structure of primary DEFERred words as KEY,EMIT,CR,WARM... is modified,
390 the address of their default execute part, without name, can be found with:
393 example, after this entry: ' DROP IS KEY
394 KEY (or ' KEY EXECUTE) runs DROP i.e. runs the redirection made by IS,
395 ' KEY >BODY EXECUTE runs KEY, the default action at the BODY address.
397 and: ' KEY >BODY IS KEY
398 restore the default action of this primary DEFERred word.
401 WARNING! you cannot do that with words created by DEFER !
402 DEFER creates only secondary DEFERred words, without BODY !
405 to build a primary DEFERred FORTH word,
407 you must create a DEFERred word followed by a
408 :NONAME definition, ended by ; IS <name>
412 :NONAME \ does nothing (for the example)
417 The advantage of creating primary DEFERred words is to set their
418 default state, enabling to reinitialize them easily.
420 forthMSP430FR_ASM.asm:
422 All assembly code is revamped.
424 POPM and PUSHM instructions now follow the TI syntax :-(
426 Added CODENNM as assembly counterpart of :NONAME (option)
428 to build the primary DEFERred assembly word "machin" :
434 NOP2 \ assembly instruction
435 NOP3 \ assembly instruction
436 MOV @IP+,PC \ mandatory before ENDCODE
439 you can obviously mix LOW/HIGH levels in CODENNM and :NONAME areas...
443 Added MSP-EXP430FR2355 launchpad
444 Added word :NONAME (option).
445 FastForth terminal via Bluetooth v2.1 + EDR (Microchip RN42) works fine in full duplex mode,
446 up to 460800bds, 4 WIRES (GND,RX,TX,RTS); but with, as wireless effect, a bad troughput of 6kb/s
447 instead of 30kb/s with a bridge UART2USB.
448 Added 4Mbds,5Mbds terminal @16MHZ, for use with UART2USB PL2303HXD.
449 Words AND, OR, XOR are moved as complement in ANS_COMP.f file.
450 Simplified preprocessor files in \config\gema\ folder: only two for one target:
451 one for the device, other for the target (launchpad or user application/module).
452 and similarly with the assembly files: Device.inc and Target.asm, for compiling FastForth.
453 Corrected startup time in target.asm files.
454 Modified Clock config in MSP_EXP430FR2433.asm and MSP_EXP430FR4133.ASM, allowing clock modulation.
458 added the line number in case of error occurring when download a source file (*f,*.4th)
459 in HALFDUPLEX mode (scite command CTRL+2) or in default NOECHO mode (scite cmd CTRL+0).
460 However, in case of download a file.f (with preprocessing), this line number refers
461 to the contents of the file named LAST.4th.
465 modified OPEN file primitive in forthMSP430FR_SD_LOAD.asm; modified forthMSP430FR_SD_INIT.asm
466 reordered files preprocessor in only one folder.
468 You can now compile FastForth from Linux, see FastForth.pdf
469 ...But desperately searching for the linux equivalent of TERATERM !
471 FastForth V2.0, major version.
473 Word TIB is deprecated and replaced by CIB (Current Input Buffer)
474 Word CR generates CR+LF instead of CR. TYPE is rewritten in assembly.
476 Added fixed point s15q16 numbers. Thus FAST FORTH recognises :
477 unsigned/signed numbers u/n (u <= 65535) / (-32768 <= n <= 32767),
478 unsigned/signed double numbers ud/d by adding a decimal point
479 (ud <= .4294967295) / (-.2147483648 <= d <= .2147483647),
480 and s15q16 signed numbers by adding a comma (-32768,00000 <= s15q16 <= 32767,00000).
482 Fixed issue about the word LOAD": when called from a word, returns well into this calling word.
483 Note that with MSP430FR57xx family, SDIB uses PAD, due to lack of RAM.
485 With the BOOTLOADER option, QUIT becomes a DEFERed word to easily enable/disable bootloader:
486 ' BOOT IS WARM enables bootloader.
487 WIPE disables bootloader.
491 Added a set of words to enable conditional interpretation/compilation : MARKER [DEFINED] [UNDEFINED]
492 [IF] [ELSE] [THEN]. A MARKER word (defined as {word} to well see it) allows you to wipe some program
493 even if loaded in memory below RST_STATE boundary.
495 All interpretation/compilation errors now execute POWER_STATE, so any incorrect definition
496 and all its source file will be automatically erased.
498 Added a bootloader option which loads BOOT.4TH from SD_Card memory.
502 SD_Card driver works also with software multiplier (with MSP430FR4133)
503 added SLEEP word enabling user access to background task,
504 see ACCEPT in forthMSP430FR.asm and see use in RC5toLCD.f
506 You can type double numbers by inserting a decimal point.
507 Example : `$-12` is processed as 16 bits negative number.
508 `$-.12` or `$-1.2` or `$-12.` are processed as 32 bits negative numbers.
510 FAST FORTH V160, major version.
512 Accept SD_Card from 64 MB (FAT16) up to 64 GB (FAT32).
513 Note that Windows 10 no longer offers the FAT32 format for the highest sizes of SD_CARD memory.
514 So you must use an alternative to do, for example: https://www.partitionwizard.com.
517 in SD_TOOLS the word SECTOR dumps a sector (use a 32 bits number).
518 the word CLUSTER dumps first sector of a cluster.
519 Usage (notice the point): number. CLUSTER or number. SECTOR
523 Added direct file transfer from PC to the target SD_CARD.
524 Measured throughput with "HCI" SD CARD: 90 kbytes/s at 3Mbauds and 16MHz target clock.
525 You can do it from scite editor (menu Tools) or by using specific bat file.
526 Double click on it to see how to do.
528 JTAG and BSL signatures (FF80h-FF88h) are protected against overwrite, typically during
529 source file download.
531 added signed number prefixes $ (hex), % (bin) and # (decimal) to supersede current BASE.
533 Added words ASM and ENDASM to create assembler words that are not interpretable by FORTH
534 i.e. that are called by {CALL|INTERRUPT} and ended by {RET|RETI}. These so created words
535 can be used only in ASSEMBLER context.
537 In the embedded assembler, added 3 backward BW1 BW2 BW3 and 3 forward FW1 FW2 FW3 jump labels
538 to use with GOTO, ?GOTO.
539 These labels are for single use (one jump for one label) but immediately reusable once resolved.
541 you can compile up to 32 threads vocabularies.
544 Fast Forth defines 4 levels of program memory with this words :
545 WIPE (and system failures) that resets program memory, vectors interrupts and any DEFERred words,
546 RST_HERE/RST_STATE that sets/resets the boundary of program protected against <reset> and COLD,
547 PWR_HERE/PWR_STATE that sets/resets the boundary of program protected against power ON/OFF,
548 and nothing, i.e. volatile program.
550 You can download source files with hardware and/or software control flow (i.e. without line
551 or char delays) up to:
558 6000000 bds @ 24MHz with MSP430FR57xx devices
559 See main file DTCforthMSP430FR5xxx.asm for the list of reliable baudrates.
561 FAST FORTH can be adjusted by selection of SWITCHES in the source file to reduce its size according
562 to your convenience. To do, comment/uncomment their line.
564 for your application, select the mode LPM{0,1,2,3,4} that enables wake on FAST FORTH input,
565 depending of family: FR2xxx: LPM0, FR57xx : LPM0 to LPM2, FR59xx : LPM0 to LPM4.
567 DEEP_RST (RESET + WIPE) can be hardware performed via the programmation interface
568 (Vcc,RX,TX,RST,TEST,GND).
570 Many thanks to Brad Rodriguez
571 -----------------------------
573 for his CamelForth which served me as a kind of canvas.
574 And also to Matthias Koch for its ideas about Q15.16 implementation.
576 Unlike CamelForth FASTFORTH is a "Direct Threaded Code", with an embedded assembler following the standard syntax,
577 not the one used in the world Forth.
579 Its core is fully compliant with the standard ANS.
581 It is optimized for the speed, especially in the interpreter mode, so that you can load an application program written in FORTH/Assembler faster than its binary via MSP430 Flasher.exe.
582 Everything can be done from your text editor, the preprocessor and a serial terminal.
587 I have first programmed atmel tiny devices.
588 Particularly I2C master driver to have both I2C slave and I2C master on a ATtiny461.
589 which means a lot of back and forth between the editor, assembler, the programmer and the test in situ.
591 Previously I had programmed a FORTH on a Motorola 6809 and had been seduced by the possibility of sending a source file directly to the target using a serial terminal. Target which compiled and executed the program. At the time FORTH program lay in a battery backed RAM.
593 The advent of chip MSP430 TEXAS INSTRUMENT with embedded FRAM gave me the idea to do it again : FAST FORTH was born.
595 Today I dropped the ATMEL chips and proprietary interfaces, I program my applications in a mix 80%/20% of assembler/FORTH I then sent on MSP430FR5738 chips with embedded FAST FORTH.
597 And that's the magic: After I finished editing (or modify) the source file, I press the "send" button in my text editor and I can test result on target in the second following. This is the whole point of an IDE reduced to its simplest form: a text editor, a cable, a target.
602 See [FastForth.pdf](https://gitlab.com/Jean-Michel/FastForthForMSP430fr5xxx/-/blob/master/FastForth.pdf)
604 Organize your gitlab copy of FastForth
607 See [FastForth.pdf](https://gitlab.com/Jean-Michel/FastForthForMSP430fr5xxx/-/blob/master/FastForth.pdf)
612 See [FastForth.pdf](https://gitlab.com/Jean-Michel/FastForthForMSP430fr5xxx/-/blob/master/FastForth.pdf)
614 Build the program file
615 ----------------------
617 \forthMSP430FR.asm is the main file to compile FastForth:
619 Open forthMSP430FR.asm with scite editor
621 uncomment the target as you want, i.e. MSP_EXP430FR5969
623 choose frequency, baudrate, flow control.
625 uncomment options switches as your convenience.
629 assemble (CTRL+0). A window asks you for 4 parameters:
631 set target as first param, i.e. MSP_EXP430FR5969
633 then execute. the output will be \binaries\MSP_EXP430FR5969.txt
635 Load Txt file (TI format) to target
636 -----------------------------------
638 in \binaries folder, drag your target.txt file and drop it on prog.bat
640 or use scite internal command TOOLS: FET prog (CTRL+1).
642 nota : programming the device use SBW2 interface, so UARTn is free for serial terminal connexion.
644 If you want to program your own MSP430FRxxxx board, wire its pins TST, RST, 3V3 and GND
645 to same pins of the launchpad, on eZ-FET side of the programming connector.
647 Connect the FAST FORTH target to a serial terminal
648 -------------------------------------------------
650 you will need an USBtoUART cable with a PL2303TA or PL2303HXD device that allows both XON/XOFF
651 and hardware control flow :
653 [PL2303HXD 3.3V](http://www.google.com/search?q=PL2303HXD+3.3V+cable)
654 [PL2303 driver](http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=225&pcid=41)
656 WARNING! always verify VCC PIN = 3.3V before use to supply your target with.
658 or with a CP2102 device and 3.3V/5V that allows XON/XOFF control flow up to 921600 Bds:
660 [CP2102 3.3V](https://www.google.com/search?q=cp2102+3.3V+6PIN)
661 [CP2102 driver](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers)
663 WARNING! always verify VCC PIN = 3.3V before use to supply your target with.
665 or with a FT232RL device and 3.3V/5V but without XON/XOFF control flow:
667 [FT232RL 3.3V](http://www.google.com/search?q=FT232RL+3.3V)
668 [FT232RL driver](https://www.ftdichip.com/Drivers/VCP.htm)
670 WARNING! always verify VCC PIN = 3.3V before use to supply your target with.
672 or compatible 921600bds wireless module: RN42 (bluesmirf), RN4878...
674 Send a source file.f or file.4th to the FAST FORH target
677 Three bat files are done in \MSP430-FORTH that enable you to do all you want.
678 drag and drop your source file on to.
679 you can also open any source file with scite editor, and do all you want via its Tools menu.
681 If you have any downloading error, first verify in "LAST.4th" that all lines are
682 correctly ended with CR+LF.
684 SD_Card Load, Read, Write and Delete
685 =============================================
690 If you have MSP-EXP430FR5994, nothing to do.
692 For the choice of a SD card socket be carefull, pin CD (Card Detect) must be present!
693 google search: "micro SD card 9 pin"
694 Look for the good wiring in /Launchpad.asm file
696 Compile with SD_Card addon
699 in forthMSP430FR.asm, uncomment lines SD_CARD_LOADER, SD_CARD_READ_WRITE, SD_TOOLS
700 then compile for your target
705 With the LOAD" pathame" command you load your source files from a SD_CARD memory in both execute
706 and compile modes. Idem for READ", WRITE" and DEL" commands.
708 See "SD_TESTS.f", a FORTH program done for example
710 If you remove the SD memory card reader and then reset, all SD\_IO pins are available except SD_CD obviously.
712 HowTo LOAD a sourcefile
715 LOAD" path\filename.4th".
717 The file is interpreted by FORTH in same manner than from the serial terminal.
719 When EOF is reached, the file is automatically closed.
721 A source file can _LOAD"_ an other source file, and so on in the limit of available handles (up to 8).
726 READ" path\filename.ext".
728 The first sector of this file is loaded in BUFFER.
729 To read next sectors, use the command READ that loads the next sector in the buffer,
730 and leaves on the stack a flag that is true when the EOF is reached.
731 The file is automatically closed. See tstwords.4th for basic usage.
733 The variable BufferLen keep the count of bytes to be read (0 to 512).
735 If you want to anticipate the end, use the CLOSE command.
740 WRITE" path\filename.ext".
742 If the file does not exist, create it, else open it and set the write pointer at the end of the file,
743 ready to append chars.
745 See example of use in \MSP430-FORTH\SD_TEST.f.
747 To overwrite an existing file: DEL" file" then WRITE" file".
749 Use CLOSE to close the file.
754 DEL" path\filename.ext". If the file is not found, do nothing, no error.
756 HowTo change DIRectory
759 LOAD" \misc". \misc becomes the current folder.
760 LOAD" ..\" parent folder becomes the current folder.
761 LOAD" \" Root becomes the current folder.
763 Drive letters are always ignored.
765 Downloading source file to SD_Card
766 ------------------------------------------
768 to download a source file (.f or.4th) onto SD_CARD target, use CopySourceFileToTarget\_SD\_Card.bat.
769 Double click on one of this bat files to see how to do.
773 If you have any downloading error, first verify in "LAST.4th" that all lines are
774 correctly ended with CR+LF.
776 Other interesting specificities :
779 Management of vocabularies (not ANSI) with the option VOCABULARY_SET:
780 VOCABULARY, DEFINITIONS, ONLY, ALSO, PREVIOUS, CONTEXT, CURRENT, FORTH, ASSEMBLER.
781 In fact, it's the the assembler that requires the vocabularies management.
783 Recognizing prefixed numbers %101011 (bin), $00FE (hex) and #220 (decimal).
784 you can insert underscores in numbers: %1100\_1101\_0000\_0001 instead of %1100110100000001.
788 The words DEFER and IS are implemented. CR, EMIT, KEY, ACCEPT, QUIT and WARM are deferred words.
790 Error messages are colored (reverse video on ANSI terminal).
792 Assembly jumps are as FORTH one's : IF, ELSE, THEN, BEGIN, AGAIN, UNTIL, WHILE.
793 Not canonical jumps are also available with GOTO|?GOTO to
794 backward labels BW1 BW2 BW3 or forward labels FW1 FW2 FW3.
795 Backward labels BWx are live until new definition, forward labels FWx are for single use.
796 Switch within definitions between FORTH and Assembly contexts with words HI2LO and LO2HI.
797 See examples in the TstWords.f file. This is perhaps the most interesting feature for development...
799 The system is not responding ?
802 First, remove the USBtoUART bridge then reconnect it. Perhaps it was in suspend state...
804 If the system is always freezed, press <reset> button on the MSP-EXP430FR5xxx ; FORTH restarts
805 as it was after the last RST_HERE command.
807 If the system does not restart again, press `SW1+RESET`.
808 FORTH restarts in the state it is in its object txt file.
810 Here is the FastForth initialization process, in itself one of its major assets :
812 case 1 : when you type `PWR_STATE` ==> the program beyond PWR_HERE is lost.
814 case 1.1 : when you type `WARM`, FORTH interpreter is restarted, the program
815 beyond of last PWR_HERE (or last RST_HERE) is lost.
816 The WARM display is preceded by "#0".
818 case 1.2 : Power ON ==> performs a reset and the program beyond PWR_HERE is lost.
819 the WARM display is preceded by the SYSRSTIV value "#2".
821 case 1.3 : SVSHIFG SVSH event ==> same effects,
822 the WARM display is preceded by the SYSRSTIV decimal value "#14".
826 case 2 : when you type `RST_STATE` ==> the program beyond RST_HERE is lost.
828 case 2.1 : <RESET> ==> performs reset and the program beyond RST_HERE is lost,
829 the WARM display is preceded by the SYSRSTIV value "#4".
831 case 2.2 : when you type `COLD` (software reset) ==> same effects,
832 the WARM display is preceded by the SYSRSTIV value "#6".
834 case 2.3 : PUC on failure ===> same effects,
835 The WARM display is preceded by the SYSRSTIV decimal value.
839 case 3 : when you type `WIPE` ==> all programs donwloaded from the terminal or the SD_Card
840 are lost, the default state of COLD_APP, INI_SOFT_APP, INI_HARD_APP and BACKGND_APP
841 are restored, all "defered" words are initialised with their default value,
842 same thing for interrupts vectors, and SIGNATURES area is cleared (FFh).
843 The WARM display is preceded by #-1.
845 case 3.1 : <SW1+RESET> ==> performs deep reset, same effects.
846 The WARM display is preceded by #-1.
848 case 3.2 : after compiling new FastForth ==> same effects, obviously!
849 The WARM display is preceded by #-3.
852 If you have previously set 'NOECHO', there is no WARM display.
855 If an error occurs from the interpreter, FORTH is restarted,
856 The error is always displayed and the program beyond PWR_HERE is lost.
858 In this way, any error is followed by the complete erasure of a bad definined word causing this error,
859 or by that of the downloaded source file including it.
861 It is therefore recommended to end a source file with at least 'PWR_HERE' to protect it
862 from any subsequent error.
868 These words are not ANS94 compliant, they are those of F83 standard.
870 For example, after loading SD_TOOLS add-on, you can type: ALSO ASSEMBLER WORDS PREVIOUS WORDS
872 With ALSO ASSEMBLER, the vocabulary ASSEMBLER is added to the search CONTEXT thus the ASSEMBLER words
875 WORDS display the words of ASSEMBLER then those of FORTH,
877 PREVIOUS remove the vocabulary ASSEMBLER form the CONTEXT, and the ASSEMBLER words become hidden,
879 so the last WORDS display only FORTH words.
881 In the forthMSP430FR_ASM.asm, see the FORTH word CODE that add ASSEMBLER to the search CONTEXT and the ASSEMBLER word ENDCODE
882 that remove ASSEMBLER from search CONTEXT. Thus, the assembler words can be used only between CODE and ENDCODE.
884 The CONTEXT can grow up to 6 vocabularies by using the word ALSO.
886 If you want add words to the assembler you must type: ALSO ASSEMBLER DEFINITIONS,
887 The vocabulary ASSEMBLER is added to the search CONTEXT as previously but also becomes the CURRENT vocabulary in which the new words will be stored.
889 Finally, FORTH ONLY DEFINITIONS limits the search CONTEXT to FORTH and the CURRENT vocabulary is FORTH.
894 With the preprocessor GEMA the embedded assembler allows access to all system variables.
895 See files \\inc\\Target.pat.
896 You can also access to VARIABLE. See \\MSP430-FORTH\\TESTASM.4th.
898 HOW TO MIX assembly and FORTH ?
901 FAST FORTH knows three kinds of words :
903 high level FORTH words beginning with : <name> and ended with ;
905 low level assembly words starting with CODE <name> and ended with ENDCODE
907 low level assembly words starting with ASM <name> and ended by ENDASM
908 these words are hidden because they are not FORTH executable.
909 they can be used only by calling from CODE words.
913 : NOOP \ FORTH word "NOOP", do nothing
918 CODE ADD \ Assembly word "ADD", alias of word +
923 ASM WDT_INT \ Watchdog interrupt
924 BIT #8,&TERM_STATW \ break (ALT+b) sent by TERMINAL ?
926 MOV #WARM,PC \ continue with WARM
928 RETI \ else return to background task SLEEP
932 To end a low level assembly word, the instruction MOV @IP+,PC jumps to the next FORTH word.
933 This faster (4 cycles) and shorter (one word) instruction replaces the famous pair of assembly
934 instructions : CALL #LABEL ... RET (4+4 cycles, 2+1 words). The register IP is the Interpretative Pointer.
936 High level FORTH word starts with a boot code DOCOL that save the IP pointer, load it with the first address
937 of a list of execution addresses, then performs a postincrement branch to this first address.
938 The list ends with the address of another piece of code EXIT (6 cycles) that restores IP before the instruction MOV @IP+,PC.
940 here, the compilation of low level word ADD :
942 header \ compiled by the word CODE
943 execution addr ADD @PSP+,TOS
944 MOV @IP+,PC \ instruction called NEXT
946 and the one of the high level word NOOP :
948 header \ compiled by the word :
949 execution addr CALL rDOCOL \ boot code compiled by the word :
950 addr of DUP \ execution addr of DUP
951 addr of DROP \ execution addr of DROP
952 addr of EXIT \ execution addr of EXIT compiled by the word ;
954 _A high level FORTH word is a list of execution addresses preceded by a boot code and ending with EXIT address._
959 any low level FORTH words must be ended with the instruction MOV @IP+,PC (NEXT).
961 CODE TEST \ CODE starts a low level word
962 asm1 \ assembly instruction 1
963 asm2 \ assembly instruction 2
965 ENDCODE \ end of low level word
967 If you want to use the IP register, save it before and restore it before NEXT
969 CODE TEST1 \ CODE starts a low level word
970 asm1 \ assembly instruction
972 PUSH IP \ save IP before use
973 MOV #1,IP \ assembly instruction that uses IP
974 ... \ assembly instructions
975 MOV @RSP+,IP \ restore IP
977 ENDCODE \ end of low level word
979 A little more complex, the case of mixing FORTH and assembly with use of the words HI2LO, LO2HI and COLON
981 : MIX_FORTH_ASM \ definition of a FORTH word starts with :
984 HI2LO \ FORTH to assembler switch
985 asm1 \ you can freely use IP
989 MOV @RSP+,IP \ restore IP stacked by :
991 ENDCODE \ end of low level word
993 If we see the code "MIX\_FORTH\_ASM" after compilation :
995 header \ compiled by :
996 exec@ CALL rDOCOL \ boot code (which saves IP onto stack) compiled by :
999 next addr \ addr of asm1, compiled by HI2LO
1004 MOV @RSP+,IP \ restore IP saved by boot code
1007 going a step further :
1009 CODE MIX_ASM_FORTH \ CODE starts a low level word
1012 COLON \ starts high level
1015 ; \ end of high level word
1017 If we see this code "MIX\_ASM\_FORTH" after compilation :
1019 header \ compiled by CODE
1022 CALL rDOCOL \ compiled by COLON
1025 addr of EXIT \ the word ; compiles address of EXIT that restores IP then executes MOV @IP+,PC
1029 : MIX_FORTH_ASM_FORTH \ definition of a FORTH word starts with :
1033 HI2LO \ FORTH to assembler switch
1034 MOV #0,IP \ IP is free for use
1037 LO2HI \ assembler to FORTH switch
1040 ; \ end of high level word
1044 header \ compiled by :
1045 exec@ CALL rDOCOL \ boot code compiled by the word :
1049 next addr \ compiled by HI2LO
1050 MOV #0,IP \ IP is free for use
1051 asm1 \ assembly instruction
1053 CALL #EXIT \ compiled by LO2HI (10 cycles switch)
1058 EXIT is used twice !
1060 the first time, by LO2HI :
1062 EXIT MOV @RSP+,IP \ 2 pop into IP the PC pushed on return stack by CALL #EXIT
1063 MOV @IP+,PC \ 4 execute the routine at addr3
1065 then at the end of FORTH word (addr5):
1067 EXIT MOV @RSP+,IP \ 2 pop old IP from return stack
1068 MOV @IP+,PC \ 4 execute the routine pointed by the old IP
1070 Still another step :
1072 CODE MIX_ASM_FORTH_ASM \ CODE starts a low level word
1075 COLON \ switches from assembly to FORTH (COLON saves IP)
1078 HI2LO \ FORTH to assembler switch
1081 MOV @RSP+,IP \ restore IP
1083 ENDCODE \ end of low level word
1085 In fact, an exclusive of FAST FORTH, the start of a word FORTH can be placed anywhere :
1087 CODE MIX_ASM_FORTH_ASM_FORTH
1091 COLON \ starts high level
1095 HI2LO \ FORTH to assembler switch
1099 LO2HI \ assembler to FORTH switch
1103 ; \ end of high level word
1105 with the compiled result :
1107 header \ compiled by CODE
1110 CALL rDOCOL \ compiled by COLON
1113 next address \ compiled by HI2LO
1116 CALL #EXIT \ compiled by LO2HI
1119 EXIT addr \ that restores IP from return stack and then executes MOV @IP+,PC
1121 As we see, IP is saved once time, it's logical.
1123 ASSEMBLER WITHOUT LABELS ? YES !
1126 To compare AS macro assembler and FastForth embedded assembler,
1127 compare files \ADDON\FIXPOINT.asm and \MSP430-FORTH\FIXPOINT.f
1129 The conditionnal instructions doesn't use labels.
1130 Instead, they borrow FORTH's conditional environment:
1133 CMP #1,R8 \ set Z,N,V, flags
1134 0= IF \ irritating, the "IF 0=" upside down, isn't it?
1135 ADD R8,R9 \ true part of comparaison
1139 MOV @IP+,PC \ don't forget...
1140 ENDCODE \ don't forget...
1142 and the complete version :
1144 CODE TEST_IF_ELSE_THEN
1145 CMP #1,R8 \ set Z,N,V, flags
1147 ADD R8,R9 \ true part of comparaison
1149 SUB R8,R9 \ false part of comparaison
1151 ... \ the next for the two branches
1155 test for loop back version BEGIN ... UNTIL
1157 CODE TEST_BEGIN_UNTIL
1160 SUB #1,R10 \ set Z,N,V flags
1161 0= UNTIL \ loop back to BEGIN if flag Z is not set
1166 test for out of loop version BEGIN ... WHILE ... REPEAT
1168 CODE TEST_BEGIN_WHILE_REPEAT
1171 SUB #1,R10 \ set Z,N,V flags
1172 0<> WHILE \ go to out of loop if X=0 (Z flag =1)
1174 REPEAT \ unconditionnal loop back to BEGIN
1175 ... \ out of loop here
1181 CODE TEST_BEGIN_AGAIN
1184 AGAIN \ unconditionnal loop back to BEGIN
1187 to quit this infinite loop, press reset.
1189 We can nest several conditional branches :
1191 CODE TEST_NESTED_IF_ELSE
1208 CODE TEST_NESTED_BEGIN_AGAIN_IF
1213 MOV @IP+,PC \ out of test_NESTED_BEGIN_AGAIN_IF
1219 you can also MIX conditional branches with a mix of FORTH/assembly: see TEST5 in the demo file \MSP430-FORTH\TESTASM.4TH
1222 FAST FORTH have one pass assembler, not able to make forward jump.
1224 I have added possibility of several "non canonical" jumps, up to 3 backward and up to 3 forward jumps to label :
1226 \ C UM/MOD udlo|udhi u1 -- ur uq
1228 MOV @PSP+,W \ 2 W = DIVIDENDhi
1229 MOV @PSP,S \ 2 S = DIVIDENDlo
1230 \ T.I. ROUTINE Section 5.1.5 of MSP430 Family Application Reports
1231 MOV #0,Y \ 1 CLEAR RESULT
1232 MOV #16,X \ 2 INITIALIZE LOOP COUNTER
1235 SUB TOS,W \ 1 if carry DIVIDENDhi-divisor
1238 ADDC Y,Y \ 1 RLC quotient
1239 U>= ?GOTO FW1 \ 2 if carry Error: result > 16 bits
1240 SUB #1,X \ 1 Decrement loop counter
1241 <0 ?GOTO FW2 \ 2 if 0< terminate w/o error
1242 ADD S,S \ 1 RLA DIVIDENDlo
1243 ADDC W,W \ 1 RLC DIVIDENDhi
1244 U< ?GOTO BW1 \ 2 if not carry 14~ loop
1245 SUB TOS,W \ 1 if carry DIVIDENDhi-divisor
1248 FW2 BIC #1,SR \ 1 CLRC No error, C = 0
1249 FW1 \ Error indication in C
1250 \ END of T.I. ROUTINE Section 5.1.5 of MSP430 Family Application Reports
1251 MOV W,0(PSP) \ 3 remainder on stack
1252 MOV Y,TOS \ 1 quotient in TOS
1256 Forward labels FWx are for single use, backward labels BWx can solve several jumps,
1257 until new definition.
1259 SYMBOLIC ASSEMBLER ? YES !
1262 I have discovered a little semantic preprocessor "GEMA", just like that FAST FORTH have its symbolic assembler !
1264 \inc\DEVICE.pat contains memory map and vectors for a specified DEVICE
1265 \inc\LAUNCHPAD.pat is the I/O config file for specific LAUNCHPAD (or application)
1267 gema translates also FORTH registers in ASM registers (R0 to R15)
1269 With the three bat files in \MSP430_FORTH folder all is done automatically.
1271 COMPILE FAST FORTH FOR YOUR MODULE
1274 1- in forthMSP430FR.asm "TARGET configuration" create a line for your target, example:
1276 ;MY_MSP430FR5738_1 ; compile for my own MSP430FR5738 miniboard V1
1278 2- create your \inc\MSP430FR5738_1.asm and \inc\MSP430FR5738.inc from another target.asm and device.inc as pattern,
1279 Notice that you must define here only the necessary for FAST-FORTH compilation.
1281 3- in \inc\ThingsInFirst.inc add one "device.inc" item:
1283 .IFDEF MY_MSP430FR5738_1
1284 UCA0_UART ; defines uart used by FORTH input terminal
1285 LF_XTAL ; defines if your module have a 32768 Hz xtal, to enable it.
1286 UCB0_SD ; defines UC used for SD Card driver if used
1287 .include "MSP430FR5738.inc" ; include device declarations
1290 4- in \inc\TargetInit.asm add one "target.asm" item:
1292 .IFDEF MY_MSP430FR5738_1
1293 .include MY_MSP430FR5738_1.asm
1296 Then, for the preprocessor which you will use when downloading source files:
1298 1- create your \inc\device.pat file if not exist, from your \inc\device.inc and another \inc\device.pat as pattern.
1300 2- create your \inc\target.pat file from your \inc\target.asm and another \inc\target.pat as pattern.
1302 Best practice, I suggest you that all digital pins you define (input or output) in your projects have their idle state high, with external pull up resistor
1303 that is the reset state of FastForth...
1308 How to start your project ?
1310 I show you, assuming you are working from the scite editor with its enhanced tools menu.
1312 First you create two files : project.f and test.f
1316 ; ----------------------------------------------------
1317 ; MSP_EXP430FR5969 16MHZ 4Mbds PROJECT.f
1318 ; ----------------------------------------------------
1320 [DEFINED] {PROJECT} [IF] {PROJECT} [THEN] \ remove {PROJECT} if exist (memory managment)
1324 here you append your already tested routines :
1326 CODE FIRST \ assembler CODE words are FORTH executable
1331 ASM TWO \ assembler ASM words are not FORTH executable and can only be used in assembler mode
1332 ... \ used to define interrupt routines, or subroutines called by CALL...
1333 RET \ and ended by RET or RETI.
1338 CALL #TWO \ CALL only ASM words
1343 ASM WDT_INT \ interrupt routine
1346 BIC #WDTIFG,&SFRIFG1 \ reset WDT_INT flag
1347 BIC #$F8,0(RSP) \ set CPU ON and GIE OFF in saved SR
1353 then finish with this 2 "magic" words plus one optional : START, STOP and optional BACKGROUND
1355 ASM BACKGROUND \ (optional)
1357 ... \ insert here your background task
1368 CODE START \ to init your app
1369 ... \ init assembly part
1370 MOV #WDT_INT,&VEC_WDT \ init WDT vector interrupt
1372 BIC #RC5,&P1REN \ init I/O
1375 MOV #SLEEP,X \ redirect default background task
1376 MOV #BACKGROUND,2(X) \ to yours (optional)
1379 ... \ init FORTH part
1381 LIT RECURSE IS WARM \ replace WARM by START
1382 ['] WARM >BODY \ and end START with default WARM
1383 EXECUTE \ that unlock I/O, start FORTH process
1384 ; \ then fall down to sleep state, waiting any interrupt...
1387 CODE STOP \ to properly stop your app
1388 MOV #SLEEP,X \ restore the default background (optional)
1389 ADD #4,X \ (word SLEEP can only be seen in assembler mode, not in FORTH)
1393 IS WARM \ remove START from FORTH init process
1394 ECHO \ to always retrieve FORTH input terminal
1395 COLD \ reset CPU, interrupt vectors and restart FORTH.
1405 Each time you download this project file, the word {PROJECT} removes all subsequent definitions,
1406 and the word RST_HERE protects the PROJECT against RESET.
1408 The word START allows you to include your app init into FORTH's one.
1409 The word STOP unlink your app from FORTH init process.
1411 Look at the file RC5toLCD.f to retrieve this structure.
1415 \ ----------------------------------
1416 \ MSP-EXP430FR5969_8MHZ_TEST.f
1417 \ ----------------------------------
1419 RST_STATE \ memory managment
1421 here you write your routine to test
1430 PWR_HERE \ test.f content is protected against POWER OFF, but volatile with <reset>
1432 Each time you download this TEST file, the word RST\_STATE clears memory content beyond PROJECT.
1437 With the SCITE menu tools : send a file.f, you download first your project.f file, then your test.f file that include the routine to test.
1439 If the test don't work, modify it in the test.f file, then reload it.
1441 When the routine "test" works as you want, you cut it in test.f file and copy it in project.f, then when you reload it, test is done !
1448 Here you have a good view of MSP430 assembly:
1449 [MSP430 ISA](http://www.ece.utep.edu/courses/web3376/Notes_files/ee3376-isa.pdf)
1451 FastForth embedded assembler doesn't recognize the (useless) TI's symbolic addressing mode: ADD.B EDE,TONI.
1453 REGISTERS correspondence (you can use freely ASM or TI or FASTFORTH registers's names).
1455 ASSEMBLER TI FASTFORTH comment
1457 R0 PC PC Program Counter
1458 R1 SP RSP Return Stack Pointer
1459 R2 SR/CG1 Status Register/Constant Generator 1
1460 R3 CG2 Constant Generator 2
1461 R4 R4 R (rDOCOL) contents address of xDOCOL (DTC=1|2)
1462 R5 R5 Q (rDODOES) contents address of xdodoes
1463 R6 R6 P (rDOCON) contents address of xdocon
1464 R7 R7 M (rDOVAR) contents address of RFROM
1465 R8 R8 Y scratch register
1466 R9 R9 X scratch register
1467 R10 R10 W scratch register
1468 R11 R11 T scratch register
1469 R12 R12 S scratch register
1470 R13 R13 IP Interpretation Pointer
1471 R14 R14 TOS Top Of parameters Stack
1472 R15 R15 PSP Parameters Stack Pointer
1476 The FASTFORTH registers rDOCOL, rDOVAR, rDOCON and rDODOES must be preserved.
1477 If you use them you can either PUSHM #4,M before and POPM #4,M after,
1478 or use then restore FastForth default values:
1479 xdocol, xdovar, xdocon, xdodoes. See device.pat.
1481 But if you use this registers you must not at the same time call any FORTH words
1484 don't use R3 and use R2 only with BIC, BIT, BIS instructions in register mode.
1486 The bits 0-11 of SR register are saved by interrupts and restored by the instruction RETI.
1487 you can use freely UF9 UF10 and UF11 as SR bits 9-11.
1488 FastForth uses UF9 for double numbers interpreting.
1491 **PARAMETERS STACK**
1493 The register TOS (Top Of Stack) is the first cell of the Parameters stack.
1494 The register PSP (Parameters Stack Pointer) points the second cell.
1496 to push one cell on the PSP stack :
1498 SUB #2,PSP \ insert a empty 2th cell
1499 MOV TOS,0(PSP) \ fill this 2th cell with first cell
1500 MOV <what you want>,TOS \ MOV or MOV.B <what you want>,TOS ; i.e. update first cell
1502 to pop one cell from the PSP stack :
1504 MOV @PSP+,TOS \ first cell TOS is lost and replaced by the 2th.
1506 don't never pop a byte with instruction MOV.B @PSP+, because it generates a stack misalignement...
1510 register RSP is the Return Stack Pointer (SP).
1512 to push one cell on the RSP stack :
1514 PUSH <what you want> \
1516 to pop one cell from the RSP stack :
1518 MOV @RSP+,<where you want> \
1520 don't never pop a byte with instruction MOV.B @RSP+, ...
1523 to push multiple registers on the RSP stack :
1525 PUSHM #n,Rx \ with 0 <= x-(n-1) < 16
1527 to pop multiple registers from the RSP stack :
1529 POPM #n,Rx \ with 0 <= x-(n-1) < 16
1531 PUSHM order : PSP,TOS, IP, S , T , W , X , Y ,rDOVAR,rDOCON,rDODOES,rDOCOL, R3, SR,RSP, PC
1532 PUSHM order : R15,R14,R13,R12,R11,R10, R9, R8, R7 , R6 , R5 , R4 , R3, R2, R1, R0
1534 example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
1536 POPM order : PC,RSP, SR, R3,rDOCOL,rDODOES,rDOCON,rDOVAR, Y , X , W , T , S , IP,TOS,PSP
1537 POPM order : R0, R1, R2, R3, R4 , R5 , R6 , R7 , R8, R9,R10,R11,R12,R13,R14,R15
1539 example : POPM #6,IP pulls Y,X,W,T,S,IP registers from return stack
1541 error occurs if n is out of bounds
1543 **conditionnal jumps use**
1545 0= with IF UNTIL WHILE ?GOTO
1546 0<> with IF UNTIL WHILE ?GOTO
1547 U>= with IF UNTIL WHILE ?GOTO
1548 U< with IF UNTIL WHILE ?GOTO
1549 S< with IF UNTIL WHILE ?GOTO
1550 S>= with IF UNTIL WHILE ?GOTO
1551 0>= with IF UNTIL WHILE