Seen a few FORTH examples on UA-cam and this is the first one that contained enough details to make me think about trying Mecrisp. I haven't done any FORTH since about 1985. that's pretty impressive that the compiler contains and optimisation stage AND it's running that compiler on the STM32.
This has been a great video! I love the way you explained it and build upon the messages, great little demo-tutorurial, I got me enough to to be able to build a blinky on an STM32blackpill with in 5 mins! It has opened up a new horizon for prototyping fun little project.
Very nice video, and great introduction to the power of using mecrisp forth for embedded programming and exploration. It really is a great way to interactively explore embedded hardware environments, especially when it's not exactly clear how the peripherals (and things they're connected to) are working. This interactive capability is a huge time saver over the usual edit/compile/link/burn cycle as you pointed out. I picked up mecrisp forth to do an embedded project to replace the old 7-segment LCD display on my Fluke 8050A multimeter with a color graphical SPI-connected LCD display. That involved "wire tapping" the original display scanning to capture what the measurements, and forth really excelled at the low-level bit-banging.. but also in trying to understand what the existing behavior of the system was. In the process of doing all that, I learned enough Forth the be dangerous, and also to really appreciate the work of art that the mecrisp implementation is. There is a lot of very clever things going on inside, and it was a pleasure to discover those things as my understanding of the language and environment grew. There's also a disassembler for mecrisp that you can use to see the generated code - it adds the top-level "SEE" word that you can point at a forth word and see the generated code. It really is quite impressive the job that it does! Some resources on github: github.com/jeelabs/mecrisp-stellaris for a mirror of the repository, various libraries and applications from JeeLabs github.com/jeelabs/embello/tree/master/explore/1608-forth . You can see what I did here: madnessinthedarkness.transsys.com/projects:fluke8050a:start Thanks again for the video, great work and a nice introduction..
Very enjoyable and inspiring video! I would love to see you do more Mecrisp laboratory sessions like this. Given that it has evidently been four years since this was released, I guess it isn't very likely now. But one could wish!
I feel so bad that I've never really figured out how to have a UA-cam presence :-/. I've taken a few years now on a big excursion into RF engineering, which is all coming together quite nicely. My plan is actually to merge a lot of that back into my Forth enthusiasm, and I might actually get some more stuff going here. Based on history, though, I can't make any promises!
Did you anything more on this? That would be fun to see some more code. Maybe even an small editor in FORTH? I also saw you was using Emacs, so you could run the terminal from Emacs, and have everything in one editor.
Didn't need to set APB2ENR. Worked without that line. Latest Mecrisp for bluepill can be found on Terry Porter's Unofficial website, version includes some needed words which makes it easier. Was able to make similar code work on an ST Discovery board (stm32f0discovery). Bluepill Diagnostics V1.6.
Well. My bought trio of Blue Pills arrived today with an ST-LINK V2, loaded Forth onto them, pulled up a FT232R for comms, loaded a terminal app on my pc and got it all working, today. Now to find out more about this arcane art...
Really nice work! Great joy to watch. There are many Forth systems out there, and some are even documented. But nobody seems to document their workflow, which I think is at least as important! I've got some nRF51822 chips on their way, and I'm really excited to try some of this stuff out myself. I noticed you're using Emacs, and that you're copy-pasting or loading files using picocom. Emacs has a nice REPL interface with gforth's forth-mode so that you can get your Forth REPL in Emacs directly: C-u M-x run-forth ./terminal Now how `M-o` in your `test.fth` buffer and the entire buffer gets sent over the serial line. Or M-RET to send the definition at point. I feel that takes the interactivity to a whole new level!
Very nice. I'm installing it now. It is really strange for an old-timer to see Forth in lower case. The "bang" I assume is Linux influence. We said "store" and "c-store" as in character store. The last silly standardizing effort tried to make the language platform independent and screwed up any definite meaning or memory or register sizes of "word" or "char". And of course, "#" is not the awkward "pound sign", it is "sharp". The meta-compiling words are where it gets fun. The Bill Ragsdale 6502 in-line assembler code is a study in brilliant code. I used that same method to build libraries for co-processors and such. I have not used Forth in ages, but the way Mecrisp is set up and the optimizing is compelling and I am definitely giving it a try for some peripheral and sensor development! Thanks.
Yeah, I'm a classic UNIX nerd, so "!" is bang, "#" is hash, etc. In my new Forth environment (EvilVM), I use "!!" for OS command execution, and pronounce it "bang bang". On capitalization, there's old-school LISP code out there that's all caps too, but Lisp migrated into a lower-case convention eventually. I still read a lot of the Forth Dimensions archives, and have read a lot of capitalized Forth, but I don't like holding SHIFT down...
Just starting to look at Mecrisp and have ordered some Blue Pills to play with - so enjoyed your explanation and I'm looking forward to trying it myself. Thank you - a very informative video and I hope you make some more on this particular topic.. (I'll check that resistor too!)
Very interesting video. Have you tried the Scamp by Udamonic? It's an embedded computer that comes with Forth preinstalled, and it has words for analog, digital I/O, serial, SPI, I2C, PWM, DSM etc already in the dictionary. It's very fast to get stuff up and running. Try it. I think you'll like it a lot. It costs more than the BluePill but it's a very cool little machine.
Thanks, very useful. I starting on Forth for embedded and you video is a good start point. Did you do a complete project in forth for embedded? Greetings.
I, too, would like to see a follow-up. There are many useful / additional words to do with I/O and I2C which would make very useful viewing. This looks like a powerful FORTH on a powerful chip . Interrupt handling and Timer functions are another topic. I am a amateur and would find explanations very helpful .
Awesome upload. I found this after searching for Mecrisp on YT and watching a short playlist by someone named Alan Cruikshank, and titles Forth. A lot of this was way over my head but this is certainly a general direction I want to pursue learning more about. The initialization of registers and all that jazz is certainly challenging after learning on Arduino. I practically go crosseyed while trying to figure out MPlabX. MCC helps but it feels like too much of a bandaid on a bullet wound to me. What's the deal with different forth versions? I just heard of Mecrisp from someone in the comments section of Andreas Spies's latest upload about Micropython. I am aware of 0033mer's (YT channel) uploads about Forth. He has several examples of Forth running on AVRs and a few that go into STM32s. I know he has a few uploads about MSP430s but I don't recall if he went into Forth on those. This has me curious. ..anyways...thanks for the upload. I'll have to sit down and try this step by step to explore it further. From my (ignorant) perspective, this looks like the ideal API for hacking. Thanks again. -Jake
Just found this today, what a wonderful short tutorial. Have you posted your utility code on Github? I would love to use it. Also the color coding in your editor, and the workflow you demonstrate would be worth another video. Thanks for posting!
It would be very nice if you could show how all the process from connecting the st-link, what to do with it, then the usb ttl, how to connect it, how to deal with it. Something for beginners.
The problem with the USB is that they used to fit the wrong value pullup on USB D+ Usually soldering a 1.8k resistor between PA12 and 3.3V fixes this. See wiki.stm32duino.com/index.php?title=Blue_Pill
Nice! Regarding Forth, are you aware of a forth command which displays word definitions? I know there is a command called “words” which displays all the dictionary words, but is there a command to display the code behind each word?
Most surely not. As jephtai showed in the video, forth is a compiled language. However the confusion is understandable, since the words are still callable by their name after compilation, and he said one time that some words were written in forth. Actually they are not in the chip memory, that's all assembly, but what he meant is that the forth runtime is very minimal in its conception, and is able to compile code very early in its development. Hence you can write most of the runtime directly within the runtime, in forth. But ultimately it's all assembly instructions.
there are 8 n-foldable words. The n-foldable words tell the optimizer that the word is a pure function with 0..7 parameters on stack. Instead of compiling a call to a function / word with constant parameters the call is substituted by the results - places them as literals on stack e.g. word '+' is 2-foldable that means '+' expects 2 constants and it is a pure function(doesn't use any external variables/states). when you define a word : test-foldable + 2-foldable ; : test 1 2 test-foldable ; the optimizer can optimize the word 'test' by substituting call to test-foldable by a constant, evaluated at compile time : : test 3 ; so most mathematical functions can be declared foldable.
Liked the video. Some comments, the address of RCC->APB2ENR is $40021018 thats why you couldn't read it with a meaningful values, also to supply clock for GPIOA you need to toggle bit 2 that is $4 RCC_APB2ENR bis!. by default mecrisp-stellaris inits the ports to be enabled thaats why you could manipulate the state of the GPIOA.
Hey, thanks for the info. I continue to play with mecrisp, and is wonderful. I've always found the C libraries for working with the ARM uCs to be really frustrating, but some of this stuff actually starts to make more sense when you just work directly from the data sheets. Some data sheets are better than others, though! Again, thanks for the clarification.
Yakov Davidovich I agree manipulating the registers directly is more convenient, The C library is not convenient, the HAL is even more inconvenient. ST documentation is not the best, but much better than other manufacturers I worked with. You should try a complex device designed by german engineers translated to english by them without debugging software or hardware.
This is awesome! Are you aware that Bitcoin Script is based very very closely on Forth... Bitcoin SV is about to reinstate OP_RETURN to its original (day 1) functionality of returning the top value off of the stack... Shit's about to get real! :)
Seen a few FORTH examples on UA-cam and this is the first one that contained enough details to make me think about trying Mecrisp.
I haven't done any FORTH since about 1985.
that's pretty impressive that the compiler contains and optimisation stage AND it's running that compiler on the STM32.
This has been a great video! I love the way you explained it and build upon the messages, great little demo-tutorurial, I got me enough to to be able to build a blinky on an STM32blackpill with in 5 mins! It has opened up a new horizon for prototyping fun little project.
Very nice video, and great introduction to the power of using mecrisp forth for embedded programming and exploration. It really is a great way to interactively explore embedded hardware environments, especially when it's not exactly clear how the peripherals (and things they're connected to) are working. This interactive capability is a huge time saver over the usual edit/compile/link/burn cycle as you pointed out. I picked up mecrisp forth to do an embedded project to replace the old 7-segment LCD display on my Fluke 8050A multimeter with a color graphical SPI-connected LCD display. That involved "wire tapping" the original display scanning to capture what the measurements, and forth really excelled at the low-level bit-banging.. but also in trying to understand what the existing behavior of the system was.
In the process of doing all that, I learned enough Forth the be dangerous, and also to really appreciate the work of art that the mecrisp implementation is. There is a lot of very clever things going on inside, and it was a pleasure to discover those things as my understanding of the language and environment grew. There's also a disassembler for mecrisp that you can use to see the generated code - it adds the top-level "SEE" word that you can point at a forth word and see the generated code. It really is quite impressive the job that it does!
Some resources on github: github.com/jeelabs/mecrisp-stellaris for a mirror of the repository, various libraries and applications from JeeLabs github.com/jeelabs/embello/tree/master/explore/1608-forth . You can see what I did here: madnessinthedarkness.transsys.com/projects:fluke8050a:start
Thanks again for the video, great work and a nice introduction..
Very enjoyable and inspiring video! I would love to see you do more Mecrisp laboratory sessions like this. Given that it has evidently been four years since this was released, I guess it isn't very likely now. But one could wish!
I feel so bad that I've never really figured out how to have a UA-cam presence :-/. I've taken a few years now on a big excursion into RF engineering, which is all coming together quite nicely. My plan is actually to merge a lot of that back into my Forth enthusiasm, and I might actually get some more stuff going here. Based on history, though, I can't make any promises!
I'm happy to see intrest FORTH being revived.
Did you anything more on this? That would be fun to see some more code. Maybe even an small editor in FORTH?
I also saw you was using Emacs, so you could run the terminal from Emacs, and have everything in one editor.
Didn't need to set APB2ENR. Worked without that line. Latest Mecrisp for bluepill can be found on Terry Porter's Unofficial website, version includes some needed words which makes it easier. Was able to make similar code work on an ST Discovery board (stm32f0discovery). Bluepill Diagnostics V1.6.
Well. My bought trio of Blue Pills arrived today with an ST-LINK V2, loaded Forth onto them, pulled up a FT232R for comms, loaded a terminal app on my pc and got it all working, today. Now to find out more about this arcane art...
You just showed me a whole new side to mcu, and you did demo that looks like a tutorial.
Really nice work! Great joy to watch. There are many Forth systems out there, and some are even documented. But nobody seems to document their workflow, which I think is at least as important! I've got some nRF51822 chips on their way, and I'm really excited to try some of this stuff out myself.
I noticed you're using Emacs, and that you're copy-pasting or loading files using picocom. Emacs has a nice REPL interface with gforth's forth-mode so that you can get your Forth REPL in Emacs directly:
C-u M-x run-forth ./terminal
Now how `M-o` in your `test.fth` buffer and the entire buffer gets sent over the serial line. Or M-RET to send the definition at point. I feel that takes the interactivity to a whole new level!
Very nice. I'm installing it now. It is really strange for an old-timer to see Forth in lower case. The "bang" I assume is Linux influence. We said "store" and "c-store" as in character store. The last silly standardizing effort tried to make the language platform independent and screwed up any definite meaning or memory or register sizes of "word" or "char". And of course, "#" is not the awkward "pound sign", it is "sharp". The meta-compiling words are where it gets fun. The Bill Ragsdale 6502 in-line assembler code is a study in brilliant code. I used that same method to build libraries for co-processors and such. I have not used Forth in ages, but the way Mecrisp is set up and the optimizing is compelling and I am definitely giving it a try for some peripheral and sensor development! Thanks.
Yeah, I'm a classic UNIX nerd, so "!" is bang, "#" is hash, etc. In my new Forth environment (EvilVM), I use "!!" for OS command execution, and pronounce it "bang bang".
On capitalization, there's old-school LISP code out there that's all caps too, but Lisp migrated into a lower-case convention eventually. I still read a lot of the Forth Dimensions archives, and have read a lot of capitalized Forth, but I don't like holding SHIFT down...
Just starting to look at Mecrisp and have ordered some Blue Pills to play with - so enjoyed your explanation and I'm looking forward to trying it myself. Thank you - a very informative video and I hope you make some more on this particular topic.. (I'll check that resistor too!)
Very interesting video. Have you tried the Scamp by Udamonic? It's an embedded computer that comes with Forth preinstalled, and it has words for analog, digital I/O, serial, SPI, I2C, PWM, DSM etc already in the dictionary. It's very fast to get stuff up and running. Try it. I think you'll like it a lot. It costs more than the BluePill but it's a very cool little machine.
Excellent video! Would love to see more.
Thanks, very useful. I starting on Forth for embedded and you video is a good start point. Did you do a complete project in forth for embedded? Greetings.
thank you for sharing your passion!
I, too, would like to see a follow-up. There are many useful / additional words to do with I/O and I2C which would make very useful viewing. This looks like a powerful FORTH on a powerful chip . Interrupt handling and Timer functions are another topic. I am a amateur and would find explanations very helpful .
Awesome upload. I found this after searching for Mecrisp on YT and watching a short playlist by someone named Alan Cruikshank, and titles Forth.
A lot of this was way over my head but this is certainly a general direction I want to pursue learning more about.
The initialization of registers and all that jazz is certainly challenging after learning on Arduino. I practically go crosseyed while trying to figure out MPlabX. MCC helps but it feels like too much of a bandaid on a bullet wound to me.
What's the deal with different forth versions? I just heard of Mecrisp from someone in the comments section of Andreas Spies's latest upload about Micropython.
I am aware of 0033mer's (YT channel) uploads about Forth. He has several examples of Forth running on AVRs and a few that go into STM32s. I know he has a few uploads about MSP430s but I don't recall if he went into Forth on those. This has me curious.
..anyways...thanks for the upload. I'll have to sit down and try this step by step to explore it further.
From my (ignorant) perspective, this looks like the ideal API for hacking.
Thanks again.
-Jake
Just found this today, what a wonderful short tutorial. Have you posted your utility code on Github? I would love to use it. Also the color coding in your editor, and the workflow you demonstrate would be worth another video.
Thanks for posting!
It would be very nice if you could show how all the process from connecting the st-link, what to do with it, then the usb ttl, how to connect it, how to deal with it. Something for beginners.
Can I get the code for your forth file
upload word?
Very helpful. Thanks
That's really cool!
I think, you can put an 1.8k in specific pins and you can fix the USB port (like parallel resistor)
The problem with the USB is that they used to fit the wrong value pullup on USB D+
Usually soldering a 1.8k resistor between PA12 and 3.3V fixes this.
See
wiki.stm32duino.com/index.php?title=Blue_Pill
Nice video :) Thank you. Where is the broken or missing resistor; is this common to blue pill or just yours?
It's all in the Wiki (as i am sure you have found by now, but this may help others). Just Google "STM32F103 Blue Pill wiki".
Nice! Regarding Forth, are you aware of a forth command which displays word definitions? I know there is a command called “words” which displays all the dictionary words, but is there a command to display the code behind each word?
Most surely not. As jephtai showed in the video, forth is a compiled language. However the confusion is understandable, since the words are still callable by their name after compilation, and he said one time that some words were written in forth. Actually they are not in the chip memory, that's all assembly, but what he meant is that the forth runtime is very minimal in its conception, and is able to compile code very early in its development. Hence you can write most of the runtime directly within the runtime, in forth. But ultimately it's all assembly instructions.
Try the word SEE 👀
Could you please say few words about the magic word "foldable" ?
there are 8 n-foldable words. The n-foldable words tell the optimizer that the word is a pure function with 0..7 parameters on stack. Instead of compiling a call to a function / word with constant parameters the call is substituted by the results - places them as literals on stack e.g. word '+' is 2-foldable that means '+' expects 2 constants and it is a pure function(doesn't use any external variables/states). when you define a word
: test-foldable + 2-foldable ;
: test 1 2 test-foldable ;
the optimizer can optimize the word 'test' by substituting call to test-foldable by a constant, evaluated at compile time :
: test 3 ;
so most mathematical functions can be declared foldable.
Liked the video. Some comments, the address of RCC->APB2ENR is $40021018 thats why you couldn't read it with a meaningful values, also to supply clock for GPIOA you need to toggle bit 2 that is $4 RCC_APB2ENR bis!. by default mecrisp-stellaris inits the ports to be enabled thaats why you could manipulate the state of the GPIOA.
Hey, thanks for the info. I continue to play with mecrisp, and is wonderful. I've always found the C libraries for working with the ARM uCs to be really frustrating, but some of this stuff actually starts to make more sense when you just work directly from the data sheets. Some data sheets are better than others, though! Again, thanks for the clarification.
Yakov Davidovich I agree manipulating the registers directly is more convenient, The C library is not convenient, the HAL is even more inconvenient. ST documentation is not the best, but much better than other manufacturers I worked with. You should try a complex device designed by german engineers translated to english by them without debugging software or hardware.
stack languages are the most interesting of all
Can't read the typing.
Very interesting.
This is awesome! Are you aware that Bitcoin Script is based very very closely on Forth... Bitcoin SV is about to reinstate OP_RETURN to its original (day 1) functionality of returning the top value off of the stack... Shit's about to get real! :)
if you liked Forth, try sysRPL
Forth does "it" better 😁