Mecrisp Stellaris FORTH or FLASHFORTH-Anyone used them? - Page 1
Forum section: electronics / general

author: djsb
author_rank: Super Contributor
timestamp: March 26, 2023, 06:25:07 pm
content: Just started reading about FORTH herehttps://mecrisp-stellaris-folkdoc.sourceforge.io/index.htmlAnd I've downloaded both of the Leo Brodie books (Starting FORTH and thinking FORTH-Too big to attach here). Before I go any further down the rabbit hole, is this worth the effort for use with VERY small (I.E very low RAM and Flash memory etc) microcontrollers? I mainly work with PICS, but I've had a go with Micropython (with the Thonny IDE) on the PI PICO. Or has anyone worked with FLASHFORTH on a PIC18F microcontroller?https://flashforth.com/Any insights or can anyone share any of their experiences? How easy is it to get an LED blinking on a PIC18F45K50 using FLASHFORTH as an example? Thanks.P.S Found the SCAMP3 on Tindie (https://www.tindie.com/products/johncatsoulis/scamp/).I think I'll have a go with this first.

author: iMo
author_rank: Super Contributor
timestamp: March 27, 2023, 10:16:40 am
content: I was playing a lot with FlashForth (pic18, pic24, dspic33), Mecrisp Forth (stm32, FPGA) and amForth(atmega32/328/128). All are excellent implementations. Also the authors were responsive and collaborative too. Using Forth has sense, indeed, especially with "smaller devices" and FPGAs provided you get quite familiar with the Forth and the way it is written and how it works. That requires to change your programming habits and mindset. Performance-wise those ports are between assembler and C, therefore pretty fast.Mind the Forth community is rather small, somehow special, the availability of the ready source code or libraries is very limited as well. The existing source code (written by someone else) is difficult to read unless you are quite good at it..PS: An example: you may try to debug this48bit floating point library for MecrispI put together years back..

author: rhb
author_rank: Super Contributor
timestamp: March 27, 2023, 10:53:03 am
content: Mecrisp is superb and is available configured for many, if not most of the eval boards on the market.I learned forth on a Vic20 & C64 in the early 80's. Those implementations were so bad that my only ptogram was a decompiler :-(Try Mecrisp on an original MSP430 Launchpad. You can't buy them for the intro price of $4.30, but they are still a great deal if battery life is important. A friend designed a remote reading system for retrofit to existing meters using an MSP430 with *15 YEAR* battery life!Have Fun!Reg

author: sgall17a
author_rank: Newbie
timestamp: November 08, 2023, 08:46:12 pm
content: I put flashforth on 2 arduino nano clones to control a stepper motor with an A4988 type board in a test jig. (Speed direction, rotation count etc)It was interactive and very easy to extend. Unfortunately I didnt keep a record of my programs.The problem was that both nano's become non-functional. I assume that I must have burnt out the flash (by too many overwrites) somehow. They were cheap clones so maybe the number of writes was pretty limited. Anyway that was enough for me to move on.Nevertheless as a concept, forth was really nice as a dedicated control language. I just used text on the serial port but it would have been easy to put some buttons that could excecute a word on a button press.

author: brucehoult
author_rank: Super Contributor
timestamp: November 08, 2023, 10:55:26 pm
content: Quote from: djsb on March 26, 2023, 06:25:07 pmForth (or some other bytecode such as UCSD Pascal or Java JVM or ...) makes a lot of sense purely in getting maximum functionality into limited code space on primitive CPUs with awful instruction sets and poor code density, as long as you have enough program space to hold the interpreter (or built in words in the case of Forth).Especially if you are doing a lot with 16 or 32 bit values on an 8 bit CPU.This certainly includes PIC, as well as 6502 and others of that era, early 1970s minicomputers, 1950s mainframes. Woz's "SWEET16" bytecode interpreter for a 16 bit virtual machine on 6502 was about 300 bytes.Forth and Micropython also of course have the bonus of providing an interactive console, which can be handy.

author: pqass
author_rank: Super Contributor
timestamp: November 09, 2023, 01:48:11 am
content: For a taste of FlashForth 5,below are the words that I developed to define: standard GPIO, SPI, and stepper functions.Code:$ more atmega328_gpio-base.ff5-gpio-basemarker -gpio-base\ gpio ports#37 constant PORTB\ Port B Data Register#36 constant DDRB\ Port B Data Direction Register#35 constant PINB\ Port B Input Pins#40 constant PORTC\ Port C Data Register#39 constant DDRC\ Port C Data Direction Register#38 constant PINC\ Port C Input Pins#43 constant PORTD\ Port D Data Register#42 constant DDRD\ Port D Data Direction Register#41 constant PIND\ Port D Input Pins$ more atmega328_spi-base.ff5-spi-basemarker -spi-base\ spi ports$4c constant SPCR \ SPI Control Register$4d constant SPSR \ SPI Status Register$4e constant SPDR \ SPI Data Register\ spi bit masks%000100 constant mSS1 ( PB2 )%001000 constant mMOSI ( PB3 )%010000 constant mMISO ( PB4 )%100000 constant mSCK ( PB5 )\ spi flags$80 constant mSPIF \ SPI Interrupt Flag$40 constant mWCOL \ Write Collision Flag\: slave.select ( mSSx -- ) \ select slave x in mSSx constantdup DDRB mset \ SS as outputPORTB mclr \ deselect;: slave.deselect ( mSSx -- ) \ unselect slavedup DDRB mset \ SS as outputPORTB mset \ deselect;%01000000 constant SPCR_SPE \ SPI Enable: spi.enable ( ---)SPCR_SPE SPCR mset;: spi.disable ( ---)SPCR_SPE SPCR mclr;%00100000 constant SPCR_DORD \ Data Order: LSB.first ( --- ) \ select LOW Signifiant Bit firstSPCR_DORD SPCR mset;: MSB.first ( --- ) \ select MOST Signifiant Bit firstSPCR_DORD SPCR mclr;%00010000 constant SPCR_MSTR \ Master/Slave Select: Master.modeSPCR_MSTR SPCR mset;: Slave.modeSPCR_MSTR SPCR mclr;\ SPI mode%00000100 constant SPCR_CPHA \ Clock Phase%00001000 constant SPCR_CPOL \ Clock Polarity: Mode0SPCR_CPHA SPCR mclr \ Idle CLK = 0SPCR_CPOL SPCR mclr \ Sample on leading edge;: Mode1SPCR_CPHA SPCR mclr \ Idle CLK = 0SPCR_CPOL SPCR mset \ Sample on trailing edge;: Mode2SPCR_CPHA SPCR mset \ Idle CLK = 1SPCR_CPOL SPCR mclr \ Sample on trailing edge;: Mode3SPCR_CPHA SPCR mset \ Idle CLK = 1SPCR_CPOL SPCR mset \ Sample on leading edge;\ SPI clock speed%00000010 constant SPCR_SPR1 \ SPI Clock Rate Selects%00000001 constant SPCR_SPR0 \ SPI Clock Rate Selects%00000001 constant SPSR_SPI2x \ Double SPI Speed: spi2X.off ( --- )SPSR_SPI2x SPSR mclr;: spi2X.on ( --- )SPSR_SPI2x SPSR mset;: fosc/4SPCR_SPR1 SPCR mclrSPCR_SPR0 SPCR mclrspi2X.off;: fosc/16SPCR_SPR1 SPCR mclrSPCR_SPR0 SPCR msetspi2X.off;: fosc/64SPCR_SPR1 SPCR msetSPCR_SPR0 SPCR mclrspi2X.off;: fosc/128SPCR_SPR1 SPCR msetSPCR_SPR0 SPCR msetspi2X.off;: spi.init ( -- )mSCK DDRB mset \ SCK as outputmSCK PORTB mclr \ clock idles lowmMOSI DDRB mset \ MOSI as outputmMISO DDRB mclr \ MISO as inputmMISO PORTB mset \ activate pull-up on MISOmSS1 DDRB mset \ SS as outputmSS1 PORTB mset \ deselectspi.enableMaster.modeMode0fosc/64SPSR c@ drop SPDR c@ drop \ will clear SPIF;: spi.close ( -- )$00 SPCR c!;: spi.wait ( -- )beginmSPIF SPSR mtstuntil;: spi.cexch ( c1 -- c2 )SPDR c! spi.wait SPDR c@;: spi.csend ( c1 -- )spi.cexch drop;$ more atmega328_step-base.ff5-step-basemarker -step-base: step.init ( -- ) \ 4 wire, bipolar 293d on PORTC pins 0..3, phases are 0+1, 2+3$0f DDRC mset ;: step.off ( -- )$0 PORTC c! ;: step.fwd.ms ( ms -- )$9 PORTC c! dup ms $5 PORTC c! dup ms $6 PORTC c! dup ms $a PORTC c! ms ;: step.rev.ms ( ms -- )$a PORTC c! dup ms $6 PORTC c! dup ms $5 PORTC c! dup ms $9 PORTC c! ms ;: step.fwd.to ( nsteps speed steps -- ) \ steps/rev rev/s qtyrot rot / swap for dup step.fwd.ms next drop ;: step.rev.to ( nsteps speed steps -- ) \ steps/rev rev/s qtyrot rot / swap for dup step.rev.ms next drop ;Assuming a common anode LED display+74HC595 attached to the standard SCK,MISO,MOSI,SS pins on a ATmega328, then issuing the following will light the display accordingly.Code:spi.init mSS1 slave.deselect $00 spi.csend mSS1 slave.select \ all on\fed.gcba is segment order%11111111 spi.csend mSS1 slave.deselect mSS1 slave.select \ all off%11111000 spi.csend mSS1 slave.deselect mSS1 slave.select \ "7"%11111001 spi.csend mSS1 slave.deselect mSS1 slave.select \ "1"%11010000 spi.csend mSS1 slave.deselect mSS1 slave.select \ "3"%01110001 spi.csend mSS1 slave.deselect mSS1 slave.select \ "4"Or,bipolar stepper+L293D driver attached to PORTC pins PC0..3, then issuing the following will cause it to turn 1000 steps at a particular speed.Code:step.init200 50 1000 step.fwd.to step.offI haven't revisited this in 4 years. I just remember that it irked me that every defined word would update the flash. I would have preferred it to write to RAM and only when you're done debugging commit it to flash. Oh well.

author: westfw
author_rank: Super Contributor
timestamp: November 10, 2023, 04:00:53 am
content: QuoteForth is pretty neat, but I'm not convinced that any of the microcontrollers you mention really qualify as "VERY small."PIC18 and Pico all do a pretty good job of supporting more conventional languages (like C and BASIC.)It's very easy to write nearly unreadable code in Forth-like languages :-(pqass's example was very nice, though!Since it's interpreted and usually includes an interactive parser, Forth can be very handy for "poking around" during debugging.