Author Topic: Lightweight Scripting Language for MCUs  (Read 28237 times)

0 Members and 1 Guest are viewing this topic.

Offline Sal AmmoniacTopic starter

  • Super Contributor
  • ***
  • Posts: 1741
  • Country: us
Lightweight Scripting Language for MCUs
« on: August 22, 2016, 05:34:21 pm »
I often need to do some quick prototyping and testing of sensors on some of my MCU platforms and I find myself writing the code in C and compiling it, downloading it, etc. I'd like something like a small scripting language I can interact with over a serial link to a board to send commands to a sensor, look at the output, etc.

Anyone know of a scripting language small enough to run on an ARM Cortex-M4 and not require too many resources?
"That's not even wrong" -- Wolfgang Pauli
 

Online coppice

  • Super Contributor
  • ***
  • Posts: 8942
  • Country: gb
Re: Lightweight Scripting Language for MCUs
« Reply #1 on: August 22, 2016, 05:48:04 pm »
Lua seems to be the lightweight scripting language of choice/
 

Offline hli

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: de
Re: Lightweight Scripting Language for MCUs
« Reply #2 on: August 22, 2016, 05:52:00 pm »
At 43oh, someone referred to "SIMPL". Its a small interpreted language designed as interactive language for embedded systems.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4240
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #3 on: August 22, 2016, 08:06:27 pm »
Forth?
Probably too tiny?
Someone should do a bit of host side programming to allow a generic forth to import cmsis-style .xml or .h files to pick up words for accessing the peripherals.
 
The following users thanked this post: Ian.M

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6508
  • Country: nl
Re: Lightweight Scripting Language for MCUs
« Reply #4 on: August 22, 2016, 09:04:19 pm »
Lua seems to be the lightweight scripting language of choice/
+1
 

Offline Sal AmmoniacTopic starter

  • Super Contributor
  • ***
  • Posts: 1741
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #5 on: August 22, 2016, 09:07:15 pm »
Forth?
Probably too tiny?
Someone should do a bit of host side programming to allow a generic forth to import cmsis-style .xml or .h files to pick up words for accessing the peripherals.

Forth is an interesting language. I've tried to like it over the years but just haven't been able to get my head around it. Too weird, plus it has the reputation of being a cult language. I remember back in the 80s lots of guys saying that Forth was about to take over and you weren't on the bandwagon you'd be left behind. Never happened...

The thing that turned me off was the stack-oriented nature of the language. Variables were rarely used--instead you needed to keep track of what was on the stack and invoke operations to copy and move things around on the stack. I tried, but could never keep track of what was where in my head and always had to write tedious comments like (n1 n2 n3 -- n2 n3 n1) for every operation to have any hope of keeping track of where everything was. I also found that if I came back to a piece of code I'd written more than about a few days previously I couldn't understand it without staring at it for a long time.
"That's not even wrong" -- Wolfgang Pauli
 
The following users thanked this post: freda

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13837
  • Country: gb
    • Mike's Electric Stuff
Re: Lightweight Scripting Language for MCUs
« Reply #6 on: August 22, 2016, 09:45:06 pm »
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline member_xyz

  • Contributor
  • Posts: 47
  • Country: au
Re: Lightweight Scripting Language for MCUs
« Reply #7 on: August 23, 2016, 02:57:15 am »
micropython, fully interactive runs on wide range of ucontrollers , including STM M4, ESP8266 can connect over wireless wifi web interactive terminal. Based on Python 3 and includes fairly extensive functionality.

http://micropython.org/
http://forum.micropython.org/
 
The following users thanked this post: elecdonia

Offline Pack34

  • Frequent Contributor
  • **
  • Posts: 753
Re: Lightweight Scripting Language for MCUs
« Reply #8 on: August 23, 2016, 03:00:46 am »
If you really want to go down this road, you could write a firmware for a dev board that simply relays commands from USB to spin and then write a python script to command it.

Or just pick up a USB to spin bridge, like this guy:
https://www.amazon.com/Adafruit-FT232H-Breakout-General-Purpose/dp/B00XW2MD30/ref=sr_1_2?ie=UTF8&qid=1471921175&sr=8-2&keywords=usb+to+spi
 

Offline nowlan

  • Frequent Contributor
  • **
  • Posts: 649
  • Country: au
Re: Lightweight Scripting Language for MCUs
« Reply #9 on: August 23, 2016, 04:17:47 am »
Ive been looking for something that can do Expect for serial comms. Would like to hear anything that supports it, that isnt a full blown ARM/linux.

I guess that micropython mentioned might be close enough.
 

Offline mubes

  • Regular Contributor
  • *
  • Posts: 238
  • Country: gb
  • Do Not Boil
Re: Lightweight Scripting Language for MCUs
« Reply #10 on: August 23, 2016, 07:43:59 am »
Ive been looking for something that can do Expect for serial comms. Would like to hear anything that supports it, that isnt a full blown ARM/linux.

I guess that micropython mentioned might be close enough.

Micropython is pretty simple to port too... There's a 'core'  implementation in the distribution directories which is straightforward to integrate into your own code. 

Of course,  OS integration is a how long is a piece of string issue....

Dave
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 20027
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Lightweight Scripting Language for MCUs
« Reply #11 on: August 23, 2016, 08:06:59 am »
There's a common mistake that I've seen repeatedly; I made it once myself.

The chain of events is
  • see a need to be able do a few simple things on-the-fly
  • create a little scripting language to do those
  • then find "oh, if only I could also do X", where X is something like conditional statements, or loops, or globbing/regexps
  • add those
  • repeat 3 and 4
Very soon the "little language" has grown like cancer until nobody, even the designer, understands all the interactions between features.

The solution is to use an existing language, Forth being the simplest but others have been suggested above.

Oh, as to whether an ARM Cortex M4 would be sufficient... The first full C compiler I used professionally ran on a 64kbyte Z80 CP/M machine. So why don't you just put that in the ARM :)
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: newbrain

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1740
  • Country: se
Re: Lightweight Scripting Language for MCUs
« Reply #12 on: August 23, 2016, 08:39:22 am »
I'll state once again my love for Forth.
Implementations for various MCUs exist, and it's not difficult to roll your own.
Mmmh, I have yet to do it for STM32, now that would be a nice side project (I know it's already available, but I'm in it for the fun).

The programming model based on stacks comes quite natural to me (my fist calculator was an HP one), it can be definitely be confusing for a newcomer.

Success against BASIC was really impossible, as the entry barrier is quite higher.
Then Chuck Moore went astray in stranger and stranger implementations (machine Forth, colorForth)...
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline helius

  • Super Contributor
  • ***
  • Posts: 3659
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #13 on: August 23, 2016, 09:37:33 am »
arrayforth (colorforth) is beautiful. it takes a lot of courage to begin designing something without leaning on convention. Urbit is another example of amazing de novo design.

"If I haven't seen farther, it is from standing in the footprints of giants."
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Lightweight Scripting Language for MCUs
« Reply #14 on: August 23, 2016, 09:49:21 am »
I've used Espruino and I have a small LISP running on atmega328 (yes, Arduino) which for me at least - is fun and useful for quick dirty proofing of concepts.
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Lightweight Scripting Language for MCUs
« Reply #15 on: August 23, 2016, 11:53:25 am »
perhaps ... my toy little language might be useful for something, it needs some works, it's an interpreter written in C (on the repository you can find the C++ version, send me a PM for the C version), it's able to support very basic features like loops and if-then-else

Code: [Select]
Program factorial
Begin
    Input n
    factorial = 1
    While n > 1
    Begin
        factorial = factorial * n
        n = n - 1
    End
    Output factorial
End

procedures and functions are not supported, and it's 100% abandonware  :popcorn:
« Last Edit: August 23, 2016, 12:04:00 pm by legacy »
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Lightweight Scripting Language for MCUs
« Reply #16 on: August 23, 2016, 12:02:54 pm »
The solution is to use an existing language

also the problem is the editor, what do you use to see the code on the target machine, and what do you use to edit existing lines or to add new lines ?

gwbasic comes with LED (Line EDitor), which is embedded within the interpreter and covers all the needs

  • see code (list)
  • edit existing code
  • insert new code
« Last Edit: August 23, 2016, 12:05:18 pm by legacy »
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 20027
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Lightweight Scripting Language for MCUs
« Reply #17 on: August 23, 2016, 01:11:31 pm »
The solution is to use an existing language
also the problem is the editor, what do you use to see the code on the target machine, and what do you use to edit existing lines or to add new lines ?

For scrotty little scripting languages, the problem is far worse: there's no tooling, plus you have to train staff in something they can only use in your company. Usually it is better to invent a domain specific library than a domain specific language.

I've seen a company taken down by their own DSL.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9914
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #18 on: August 23, 2016, 03:03:21 pm »
Forth?
Probably too tiny?
Someone should do a bit of host side programming to allow a generic forth to import cmsis-style .xml or .h files to pick up words for accessing the peripherals.

Forth is an interesting language. I've tried to like it over the years but just haven't been able to get my head around it. Too weird, plus it has the reputation of being a cult language. I remember back in the 80s lots of guys saying that Forth was about to take over and you weren't on the bandwagon you'd be left behind. Never happened...

The thing that turned me off was the stack-oriented nature of the language. Variables were rarely used--instead you needed to keep track of what was on the stack and invoke operations to copy and move things around on the stack. I tried, but could never keep track of what was where in my head and always had to write tedious comments like (n1 n2 n3 -- n2 n3 n1) for every operation to have any hope of keeping track of where everything was. I also found that if I came back to a piece of code I'd written more than about a few days previously I couldn't understand it without staring at it for a long time.

Forth is an excellent choice for a scripting language!  Back in the early '80s, I made a bit of side money writing BIOS code for various hard drives and I spent a few hours at one of the vendors' shop.  Their entire testing operation was built on Forth because it gave them the ability to write code from the bottom up.  Functions that already existing were usable from the command line so creating a new test really involved calling functions that already existed with a different set of parameters.  It is not unlike programming an HP calculator...

I'm not a big fan of Forth but I do recognize the utility for development work.

When I was messing around with the 8080, Z80 and 8085 chips I used to bring up the Intel monitor first.  This gave me basic program load and debug capability.  But right after that I brought up a modified version of Palo Alto Tiny Basic.  Modified in the sense that I added Port and Mem variables and functions.  I could write simple code in Basic to exercise the hardware.  I believe the earliest versions would fit in a 1K EPROM (my memory fades...).
« Last Edit: August 23, 2016, 04:41:52 pm by rstofer »
 
The following users thanked this post: elecdonia

Offline Sal AmmoniacTopic starter

  • Super Contributor
  • ***
  • Posts: 1741
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #19 on: August 23, 2016, 04:15:27 pm »
I'll state once again my love for Forth.
Implementations for various MCUs exist, and it's not difficult to roll your own.
Mmmh, I have yet to do it for STM32, now that would be a nice side project (I know it's already available, but I'm in it for the fun).

The programming model based on stacks comes quite natural to me (my fist calculator was an HP one), it can be definitely be confusing for a newcomer.

I tried it a bit back in the early 1980s (I implemented a Forth for a 6502 board I built), but quickly got tired of it for the reasons I mentioned in another post, primarily having to keep track of things on a stack.

There's nothing wrong with stack models--I was an early HP calculator user (HP35) and like RPN. In fact, I've only ever used HP calculators. An HP calculator only has a four level stack, which makes it rather easy to remember what's on the stack. With Forth programs more complex than trivial one liners you have more to keep track of, and this is compounded by operators that manipulate the stack in ways you can't do on an HP calculator (like 2over and 2rot). That, plus the fact that Forth code just looks plain ugly, was enough to turn me off.
"That's not even wrong" -- Wolfgang Pauli
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9914
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #20 on: August 23, 2016, 05:06:38 pm »
I'm not going to word this correctly but here goes:  Forth programs are built from the bottom up.  It is natural to assume that at the bottom layer there will be some swap, rot, 2over and so on.  As we move up, these may not be all that common.  In testing a disk drive, we tell some lower level function to do a seek followed by calling another function to write and a third function to read.  Perhaps there will be a call to compare the two buffers.  There may not be any low level operations (like swap) required at this level.

Yes, thinking in Forth takes a bit of effort to get started.  So did writing a celestial navigation program for my HP48GX.  But after the first hundred lines or so the code takes on a pattern.

Then we get to the Chicken and Egg problem.  To implement Forth requires, at a minimum, an assembler for the target and most of the larger incantations require a C compiler.  If I had a C compiler, why would I need a scripting language?

Anyway, here is a lecture on implementing a minimal Forth with assembly code for the ARM
http://www.sifflez.org/lectures/ASE/C3.pdf

This sounds interesting enough that it bears further investigation.  It's not like I am short of ARM boards, particularly STM32F's.
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2278
  • Country: ca
Re: Lightweight Scripting Language for MCUs
« Reply #21 on: August 23, 2016, 05:13:55 pm »
I find myself frequently turning to my Bus Pirate to do this type of task. It can talk almost any serial protocol including non-standard ones. It has built-in BASIC scripting. This has limitations, but it is very useful for taking readings, formatting them and displaying them. I downloaded the source and enhanced the scripting engine for my own needs (printing numbers in Hexadecimal format for example). Maybe you are looking for something more powerful, but for just testing sensors, displays, memories, and other serial devices, this works quite well for me.
 
The following users thanked this post: elecdonia

Offline kripton2035

  • Super Contributor
  • ***
  • Posts: 2648
  • Country: fr
    • kripton2035 schematics repository
Re: Lightweight Scripting Language for MCUs
« Reply #22 on: August 23, 2016, 05:16:02 pm »
Lua seems to be the lightweight scripting language of choice/
+1
 

Offline Sal AmmoniacTopic starter

  • Super Contributor
  • ***
  • Posts: 1741
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #23 on: August 23, 2016, 05:25:22 pm »
Lua seems to be the lightweight scripting language of choice/
+1

How "lightweight" is it? I found this on the Lua website:

Quote
The source contains around 24000 lines of C. Under 64-bit Linux, the Lua interpreter built with all standard Lua libraries takes 245K and the Lua library takes 420K.

That's awfully big! I doubt it would be as large when built for a 32-bit MCU, but it's still not exactly what I'd call lightweight. How much can you strip out of it while maintaining its usefulness?
"That's not even wrong" -- Wolfgang Pauli
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 7951
  • Country: de
  • A qualified hobbyist ;)
Re: Lightweight Scripting Language for MCUs
« Reply #24 on: August 23, 2016, 05:44:47 pm »
Would some kind of interpreter really speed up the development process? What about time critical or interrupt driven stuff? For "playing" an USB based I/O box connected to your computer might be a better option.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf