Virtual Machines on Microcontrollers (Specifically for ARM) - Page 1
Forum section: electronics / general

author: beeboopbeep
author_rank: Contributor
timestamp: July 15, 2017, 06:35:36 am
content: Hi everyone,I was wondering if anyone know successful implementation of virtual machines on microcontrollers used in the industry (specifically, for ARM targets). I started thinking about the advantages of having a virtual machine on uCs but to my surprise, I was not able to find any products with VMs on them. Obviously, implementing native code will always be the better solution with regards to having high performance but the processors we have today can easily support a simple VM running bytecode instructions. In addition, ARM uCs with relatively fast clock speed can be bought for a relatively cheap price compared to other 8-bit processors (e.g., an ATmega328p costs ~2 USD whereas STM32L0 can be bought for ~3 USD). This makes me believe that cost would not be a huge factor for not implementing a VM on a uC for getting the advantages. Furthermore, many projects will not require full processing power of the uCs and I believe power consumption with a VM can closely match the power consumption of the same uC running native code (for "most" tasks).I've also came across a recent dissertation on uCs with VMs in case anyone is interested in further reading about this topic (https://www.researchgate.net/publication/257679030_A_real-time_virtual_machine_implementation_for_small_microcontrollers). The authors in the paper ran the VM performance experiments with an ATxmega128A1 and concluded that having a VM on "small" uCs is a feasible solution to gain the advantages of having a VM in your system.If you think VM is the right or wrong direction in the near future, and if you can share your thoughts on it, I would greatly appreciate it.Thank you.

author: Rerouter
author_rank: Super Contributor
timestamp: July 15, 2017, 06:57:15 am
content: I have to question what you are hoping to accomplish by virtualising the architechture?If its for scripting, call it an interpreter, if its for cross platform compatibility that should be attacked in the compiler stage.If you hoping to do things like restricting access, there are generally built in options to prevent escalation, but know that a jtag interface can generally peer inside and see what your actually doing, and may help who your fighting to peel back what your doing.On my cortex 3 arm i do run 2 scripting language interpreters with a reduced syntax, This was easier for me that bytecode packages, as in the parsing stage i am able to detect errors, write back where they, and it means that all parts of the method is sanitized. It also reduced my R&D time as i only had to edit a text file script on an sd card, rather than recompiling the entire micro's software.

author: ataradov
author_rank: Super Contributor
timestamp: July 15, 2017, 06:57:43 am
content: What is your goal?There are plenty of "experimental VMs" for things like Java and Python. I doubt any of them are actually useful.

author: JPortici
author_rank: Super Contributor
timestamp: July 15, 2017, 07:08:23 am
content: what is the goal? you tipically want a microcontroller to be as close to the hardware as possible

author: beeboopbeep
author_rank: Contributor
timestamp: July 15, 2017, 07:13:18 am
content: I am not trying to accomplish anything yet. However, I can imagine developing a higher level language packaged in an IDE (i.e., with heavy use of GUI and reduce low-level coding as much as possible or eliminate it entirely) to program all uCs (platforms) so that anyone without technical background in uCs can program these devices.The goal would be to get to a certain level of abstraction with regards to programming the uC, to the point where an elementary student can program any uC with interface concepts like 'drag and drop' using a GUI IDE.

author: JPortici
author_rank: Super Contributor
timestamp: July 15, 2017, 07:20:58 am
content: oh i seethat's not a bad idea at allthat reminds me: In high school we studied siemens PLCs, and at the time one of my professors was coding a "ladder style" programming language for pic16/18

author: nfmax
author_rank: Super Contributor
timestamp: July 15, 2017, 07:32:36 am
content: Quote from: beeboopbeep on July 15, 2017, 07:13:18 amHave you come across Node-RED (https://nodered.org/)?It's not exactly what you describe, but it does allow largely graphical programming of Raspberry Pi's and similar systems. The implementation uses JavaScript, running on the V8 engine of NodeJS. This is actually a native-code compiler, rather than a byte code VM, but it is cross platform.

author: beeboopbeep
author_rank: Contributor
timestamp: July 15, 2017, 07:51:10 am
content: Quote from: JPortici on July 15, 2017, 07:20:58 amLadder programming is something I have never came across. I'll take a closer look.Quote from: ataradov on July 15, 2017, 06:57:43 amThere is a recent startup company that I saw which (I'm assuming) uses a customized FreeRTOS for implementing a VM on various uCs in order to allow users to program in Python (https://www.zerynth.com/). Not sure how well they are doing but it seems like a step towards the right direction for people who want to heavily script using various uCs.Quote from: nfmax on July 15, 2017, 07:32:36 amI have not come across this until now and it looks great! I saw the introduction video and an example video of using Node-Red with a Pi and it seems a lot to take in. I'll be looking into this as well.Quote from: evb149 on July 15, 2017, 07:36:05 amI'll have a look at these links.Thank you everyone for the info!

author: JPortici
author_rank: Super Contributor
timestamp: July 15, 2017, 08:35:37 am
content: Quote from: beeboopbeep on July 15, 2017, 07:51:10 amoh, it's just a visual programming environment for industrial PLCs, makes sense where you mostly want to do logic, interconnect blocks

author: voltsandjolts
author_rank: Unknown
timestamp: July 15, 2017, 08:37:34 am
content: This isn't a virtual machine implementation but does allow easy graphical programming of a microcontroller in an educational environment.Using Arduino means there is a wide range of hardware ready to go.Scratch is an open graphical programming language.Scratch for Arduino (with IDE):http://s4a.cat/Nice student lab doc:http://scratched.gse.harvard.edu/resources/expand-scratch-environment-microcontrollerScratch:https://scratch.mit.edu/https://en.wikipedia.org/wiki/Scratch_(programming_language)

author: rstofer
author_rank: Super Contributor
timestamp: July 15, 2017, 07:32:58 pm
content: Quote from: JPortici on July 15, 2017, 08:35:37 amIt is usually a graphical approach to creating machine control systems. Each rung of the ladder has a number of inputs combined in some way to create an output. Electrical control systems rarely use a 'schematic' representation of the logic but rather this ladder approach because it is simpler to understand (you're usually only looking at a single rung) and, in the old days, it was easier to draw.Note in the following page how the 'graphics' looks a lot like ASCII art. This is what was used in the very early days.https://en.wikipedia.org/wiki/Ladder_logic

author: rstofer
author_rank: Super Contributor
timestamp: July 15, 2017, 07:51:34 pm
content: National Instrument LabView has been used as a graphical programming platform for Lego Robotics for a very long time.http://k12lab-support-pages.s3.amazonaws.com/lvbasichome1.htmlJust pick up an element, place it on the page and wire it in.MatLab has a nice interface to Arduino as well as some kind of interaction with ARM processors which I have not tried. The Arduino add-on supports, among other things, the WiFi Shield. Networking right out of a simulation!It is possible to interface real world gadgets (sensors, switches, knobs and dials) with MatLab SimuLink simulations. Very cool!Still, I don't quite understand why somebody would write a byte-code interpreter for an embedded processor. Unless, the interpreter was a separate contract using some documentation of how the byte codes would be interpreted but the byte code stream itself of unavailable (for any of several reasons).Many Pascal implementations have used Niklaus Wirth's original P-code implementation. Certainly the original P4 implementation as well as the UCSD Pascal implementation and others. It was easier to get the compiler to emit P-codes and just leave the interpretation scheme to the run time interpreter. This made the system quite portable. Write an interpreter and you're up and running.

author: IanB
author_rank: Super Contributor
timestamp: July 15, 2017, 09:52:23 pm
content: Quote from: beeboopbeep on July 15, 2017, 07:13:18 amI think the goal here would be less of a VM and more of a hardware abstraction layer (HAL)? If you abstract away the details of the hardware you can have a generic programming environment that can work on a variety of different hardware platforms. The Arduino system might be considered an example of this.

author: julian1
author_rank: Frequent Contributor
timestamp: July 15, 2017, 11:40:30 pm
content: Microsoft have been working on virtualizing X86 on ARM for some time,http://www.zdnet.com/article/microsofts-x86-on-arm64-emulation-a-windows-10-redstone-3-fall-2017-deliverable/There is even a future patent dispute with Intel looming if they can't work out an agreement,https://news.ycombinator.com/item?id=14318406As for programming using visual metaphors, that's been a thing for a while,https://en.wikipedia.org/wiki/Visual_programming_languageIt's arguable GUI based filesystems, GUI client DB apps to manage relational structures, and GUI template wizards in IDEs, are all examples.

author: Marco
author_rank: Super Contributor
timestamp: July 16, 2017, 12:21:10 am
content: There's less LoC's of architecture specific code which has to be preserved on microcontrollers and less focus on performance.If you want security domains then simply creating a sandbox using a "safe" programming language is good enough, also has the advantage that you are using a non retarded language so the security within the domain is vastly increased as well.

author: westfw
author_rank: Super Contributor
timestamp: July 16, 2017, 10:56:14 pm
content: I gather that when you say "VM", you don't mean "ARM on ARM" style VMs, but instead just some arbitrary byteCode based abstraction?Where do you want to draw the line between "VM" and "Interpreter" ? There are lots of interpreters for microcontrollers - BASIC, Python, Lua, Forth... I'm not sure which ones have "pre-compile to bytecode", but it's probably not uncommon. PICAxe seems like it would be close...