13 ms·
A virtual machine for microcontrollers
- tosh 5y agoAn operating system is a collection of things that don’t fit into a language. There shouldn’t be one. — Dan Ingalls Found the quote in Byte Magazine Volume 06 Number 08 (Smalltalk) page 298 https://archive.org/details/byte-magazine-1981-08/page/n311/mode/2up https://archive.org/details/byte-magazine-1981-08/page/n311/...
- the_only_law 5y agoThe coupling between the smalltalk language and the environment has become mildly interesting to me recently. I’d tried to see if I could find any of the old Tektronix Smalltalk workstations recently, but sadly they will likely become just another very rare item in my list.
- dahart 5y agoI feel like that quote might have been intriguing and made some sense on a home computer in 1981 but has no hope of being true today. Home computers in 1981 typically had no hard drives, ran exactly 1 process at a time, had no virtual memory, no internet connection, no GPU, etc., etc. Even the article you linked to is primarily saying that Smalltalk provides it’s own interface to things the OS also does, but is not even attempting to address concepts like multi-process, security, safety, resource contention & prioritization, and all the other things a modern OS does. So what insight is this quote giving us today, does it still say something interesting, and is it still true in certain ways? I don’t have a Smalltalk history or know much about projects like LispOS or Toit at all, but I do have a clear (to me) picture of what an OS does that is useful and should not be part of a programming language. One example of that is working on console games, for example Nintendo consoles, before they provided an OS. It was a nightmare because the game developer was on the hook for handling a very long list of abnormal system conditions. The certification process for a game on a Nintendo console required all developers to conform to standards that specified exactly what errors needed to be displayed under what circumstances. Game developers needed to handle cases where a player would accidentally bump open the CD tray or pull out a cartridge in the middle of a level load, or repeatedly yank and replace a controller cable, things like that. Think about how silly it is that every single game developer, thousands of them, had to - separately and individually - spend tons of time re-engineering the same solutions to these things that the console itself should have handled, things that a couple of people at Nintendo could have engineered once for everyone. Well, now they have an OS, and this is only one of the many reasons why. It might not be immediately apparent that Nintendo’s certification standards have any bearing or say on what a home computer should be like, but UX standards in system-wide error messages are important, designated responsibility for which process handles hardware errors and user notification are important, and making sure that efforts that have to be common to all programs are implemented in such a way that devs can’t mess them up and don’t need to reinvent the wheel are important.
- CodeWriter23 5y agoWe had MP/M in 1979.
- dahart 5y agoRight, and there was even Multics in 1969. I was giving some benefit of the doubt, but I feel like Ingall’s quote was pretty dodgy even in 1981. Maybe it was tongue in cheek, or being intriguing and controversial just to get readers? Maybe there is some point of view that I’m completely missing?
- CalChris 5y agoI don't think you're missing anything. That was a very Smalltalk way of thinking at the time. However it flies in the face of separation of concerns, security, experience, .... It's a colorful quote but the marketplace of ideas hasn't been kind to it.
- sitkack 5y agoThe hardware should be clean and the language should be able to do everything, there should be no OS/user boundary. There is no reason we can't get back to and surpass this previous state.
- dahart 5y agoWhy do you say that? What does it mean to surpass the previous state? What would it do that is better than what we have today? What does it mean to not have an OS/user boundary? I don’t know what you mean if you don’t elaborate. Note: Ingall's quote was about the programming language in general, and in the context of home (desktop) computers. Things are different, and my reply here does not apply, if we're talking about microcontrollers like in the Toit article. > There is no reason we can’t get back to and surpass this previous state. Yes there is. There are a whole bunch of extremely critical reasons to have an OS and to separate it from a language, which is why we have them and why we’ve always had them (on desktop machines). I already gave some reasons above, but the reasons in my Nintendo story are some of the least important reasons there are today, and they’re still pretty important. Here are a few other reasons: Security. Some processes should be allowed to have special access and do things that most processes cannot. Think about what you’re suggesting if you remove the OS/user boundary: it means that daemon processes written by other people have root access to your system. You do not want that no matter what you claim to want in a programming language. Management of shared resource contention is something an OS should handle. Do you really want to have to write your program to play nice with the network, hard drive, and GPU? I don’t, it would automatically add months or years to any development projects, even if you had libraries and language features to support it, because it would force you into an asynchronous programming model with a responsibility to handle a large number of error conditions (most of which are out of your control). The OS handles virtual memory paging, so you would be on your own for providing a memory system that can have a resident size greater than available RAM. Not only that, every process would be on their own, there would be no shared paging file. (When you think about the paging file, don’t forget security). Other simpler reasons including program bootstrapping (loading and execution), shell & file navigator access, shared system settings (display, audio, network, etc.), temp file creation, etc., etc., etc. The difference between embedded devices and desktop machines is another good reason not to bake the job of the desktop OS into a programming language. So is the fact that there is more than one programming language - even at it's simplest, the OS boundary makes a great language agnostic interface. (Why should every language implement it's own storage, networking, and display? Wouldn't that be a complete waste?) I can’t think of any good reasons why there should be no OS/user boundary, so that is my question: why do you want that? What good would it do? How would you handle virtual memory, shared resource contention, and security, if there was no OS/user boundary?
- Koshkin 5y agoNo, an OS is what you see when you turn the damned thing on.
- dragonwriter 5y ago> No, an OS is what you see when you turn the damned thing on. Maybe, a bit, if it's a chatty OS, but, mostly, no, that’s a shell.
- pjmlp 5y ago**** COMMODORE 64 BASIC V2 **** 64 K RAM SYSTEM 38911 BASIC BYTES FREE READY.
- 542458 5y agoI feel like the title is a bit misleading - the article only mentions V8 once, and is actually about a (still interesting) new VM solution for ESP32s (and potentially others) that provides a more ergonomic development environment and simplifies things like having multiple programs running on the same MCU, OTA software update/install, and pseudo-isolating memory between programs. Easy/low-risk OTA updates in particular seems like it could be pretty killer to me - I know there are ways of doing it today, but the caveats are significant.
- winter_squirrel 5y agoFrom the title I would have expected this to be an article on V8, however there is barely any mention of it besides the title and the author saying he worked on it in the past. Instead, it seems to be an advertisement for a new language / VM, which makes it feel like a bait and switch. (even through the content itself is interesting)
- irjustin 5y agoUgh this article was a total bait and switch. Kasper Lund has a lot of my respect for work he did on V8 and Dart so I was hoping this was going to be super interesting article about trying to struggle to.... make V8 run on a specific microcontroller! I think I feel more cheated because of his background and that it's highly featured on HNews.
- tyingq 5y agoHe does offer a few indirect references as to why running V8 on a microcontroller would suck. Like the section on polymorphic inline cache for method resolution.
- zozbot234 5y agoRunning V8 implies JIT and there is no JIT on most microcontrollers because they're based on Harvard architecture where no code can be written in data memory.
- phpnode 5y agoV8 has an interpreter now FWIW https://v8.dev/blog/ignition-interpreter https://v8.dev/blog/ignition-interpreter
- tyingq 5y agoThe ESP32 has IRAM, which you can write to and execute from.
- codys 5y agoA large number of microcontrollers are ARM based, which isn't Harvard architecture. I presume the thinking is that there's some massive number of Harvard architecture chips in mundane things that lets us say "most" are Harvard arch?
- jeremyjh 5y agoARM Cortex-M is a harvard architecture microcontroller. What ARM Cortex-M has in common with ARMv8 are the letters "ARM".
- phoe-krk 5y agoThe article is not really about V8 not fitting on microcontrollers, but aside from that: > In a nutshell, the problem is that on microcontrollers everything is firmware that is compiled, linked, and deployed together using really old-fashioned tools. Changing anything means changing everything. The author hasn't seemingly heard of http://www.ulisp.com/ http://www.ulisp.com/ which is small enough to fit within kilobytes of memory and at the same time featureful enough to drive complex microcontroller applications. At the same time, it has a normal REPL running on the microcontroller that is accessible from the outside and usable for Lisp-style interactive programming.
- ashtonkem 5y agoOr circuit Python. I’m sure there are others too.
- jeremyjh 5y agoThere is also Micropython and there are a couple of javascriptish options as well. These are all leaky abstractions, none of these languages actually works exactly the same as the versions that run on full OSs with memory protection. As far as I know, none of it is actually used in industry and the workflow the author describes is the standard practice that is followed pretty much everywhere. Of course, Toit will also face an uphill battle to get any adoption in this market. I think they made a mistake using their own language instead of pretending it is Python or Javascript, even if this lets them shed a lot of baggage. Their platform is interesting though and does I think address some real challenges people would face when trying to get in-house IOT-type work done on ESP32.
- petre 5y agoOne can do more stuff with Tasmota and Berry language (which also looks like Python only with useful end statements) or Arduino, NodeMCU, MicroPython than what this platform offers at this time. I2C and SPI drivers, everybody has that. If one wants to do serious stuff they would use an appropriate RTOS and program it in C. MongooseOS does more than this if we're talking ESP32, also other devices, Javascript, C, C++, commercial support, cloud based OTA upgrades and integration with AWS, Azure, Google and IBM Watson IoT cloud services.
- zozbot234 5y agoIt's hard to substantively comment on this when the article is so tl;dr and written in wall-of-text style. What exactly is this proposed tech doing that can't be done by running a simple WASM interpreter on the bare metal? (JIT itself is generally off-limits on microcontrollers due to Harvard architecture, so interpreted code is the best case.)
- deepzn 5y agoCan running WASM solve this?
- deepzn 5y agomy bad, I didn't click on the article haha, but went straight to the comments.
- vajrabum 5y agoKaspar Lund of V8 and Dart fame and Toit.io have brought an IOT platform to market based around a purpose designed dynamic language with a bytecode VM optimized for use in MCUs. That VM engine is hosted in FreeRTOS which together with the VM and a deployment API provide a reliable and crash resistant platform for deploying apps to your IOT fleet. In their words "deploy a long-lived Toit application on your device, as if it was a mobile app being installed on your smart phone." (https://docs.toit.io https://docs.toit.io) The server end of their platform provides the management and app deployment infrastructure. It's claimed that the RTOS and VM environment makes deployment reliable even in the presence of failing apps. And that one app on a IOT device will not prevent other apps from running compromise management or brick the device. Toit.io, the company makes $$ by charging you .10/MB after the first 100MB/mo for use of their management and app deployment and you are left free to choose your own data platform. What I don't have feel for is what sort of utilization per device I can expect for the management and instrumentation traffic. *Edit I dug around the website and the tooling including the language looks like it is mostly closed source.
- leoedin 5y agoIt's a really great concept, and the embedded world is crying out for more solutions like this. However, I'd be very, very hesitant to develop anything significant on this platform. At the very least I'd want to have a. the tooling to run unit tests / simulations of my programs on the PC before deploying and b. a clear migration path for if they went bust. Their value add is the infrastructure around deployment, so why is their language closed source? I really like the Balena.io approach - the whole platform is open, so if they do go bust you could run it yourself, but they provide real value in running the infrastructure - so it makes loads of sense to pay them.
- twic 5y agoSo when Toit.io completes their incredible journey, rather than all their IoT devices being bricked, all their customers' IoT devices get bricked? Depending on what "management" entails, that is. It might only mean that no more updates are possible!
- scoutt 5y agoSo basically this is an RTOS that runs an interpreter for a script(s) stored in flash. Correct? I didn't understand if this script is precompiled or not. I'm sure that if you want to avoid uint8_t* ptr = 0x20000000; while(1) { *ptr = 0xFF; ptr++; } you have to be interpreting something else that is not C. But this is a very interesting project in the way it's presented. I did once something similar, running in parallel some sort of reduced LUA scripts. Even though, after 20 years of working in embedded, my free and unsolicited advice would be this: if you want to learn embedded, no matter how hard you are trying to avoid it, you need to learn some low-level language like C (or Rust or whatever is fancy now). Put your mind at ease and do the extra mile. At the end learning C is not that hard. And I suppose you are learning, because if you propose Toit in your workplace is because you don't know how to code anything better at the moment. I don't want to hurt anyone's feelings or sound dismissive but... learn C (or anything low-level). The rest are just toys of the moment.
- MayeulC 5y agoIt really depends on your needs. Overkill microcontrollers aren't that expensive anymore. It's probably faster to prototype something with micropython than C. And I say that as a very proficient C developer. On the other hand, C isn't hard to learn, since the language is so small. What's harder is to learn its pitfalls and the parts that are actually implementation-specific, and not specified. I'd argue that learning some assembly (enough for a few toy projects) is more useful to understand the system. C is required if you want to make the most out of the hardware, at least for now.
- scoutt 5y ago> Overkill microcontrollers aren't that expensive anymore I knew that this would be mentioned but I didn't want to write an extensive comment. In many embedded markets, cents make the difference. Also, space constraints, power consumption, availability, etc., makes you reconsider overkillability/price relationship. Someone will put a 16KB MSP430 in the BOM and there you go. What I wouldn't buy is something like "hey, chips are cheaper, let use a prototyped javascript-system over a VM over an RTOS, just because". > What's harder is to learn its pitfalls and the parts that are actually implementation-specific Yes. There are tradeoffs, like in everything in embedded. > It's probably faster to prototype something with micropython than C. Personally I wouldn't know where to start with micropython.
- deleted 5y ago[deleted]
- the__alchemist 5y ago> The problem is that on microcontrollers everything is compiled, linked, and deployed together using really old-fashioned tools. Not necessarily. There are modern and pleasant workflows using Rust. This article is somewhat general. Ie, what is his intended use case? What is he building? Part of the beauty of embedded programming is you can avoid the complications of abstractions like virtual machines and operating systems, and the performance penalties that accompany them.
- ashtonkem 5y agoAlso, there are a variety of interpreted language environments for microcontrollers, including at least one in Python and one in lisp. Saying that microcontrollers must used statically compiled code is objectively incorrect. Now most projects will use C due to space issues, but that’s a different argument.
- sjburt 5y agoMost projects use C because there was zero consideration for anything else. No embedded team sits down at the beginning of the project and says "should we use lisp?". It's just C. Or maybe "C, but use a C++ compiler with less UB".
- pjmlp 5y agoIndeed, if one moves into maker community there have been Basic, Pascal, Oberon, Java compilers for ages. Those companies manage to stay in business selling such compilers for at least three decades now, which kind of proves there is a market of people willing to pay for them, instead of going with C like everyone else.
- markdeloura 5y agoCircuitPython (derived from MicroPython) is objectively pretty excellent, and running on an increasing number of platforms. It's been a really great platform for education.
- eqvinox 5y agoAside from the massively misleading HN title, I don't see the point of replacing one machine language with another machine language. Even if the latter is a virtual machine language. The microcontrollers you would use this on (i.e. not the absolute bottom end, which would be too slow for a VM) may not have a MMU, but they do have a MPU. That's enough to get process isolation. And implementing relocation to load an ELF image isn't rocket science. Also, I'd like to point out the billions of embedded systems implementing safety critical functions like huge industrial robot controls, or the brakes in your car. They're all built (and certified) without a VM. As a matter of fact, the VM would probably make them fail certification, unless it is specified and verified itself to a very fine degree.
- scoutt 5y ago> billions of embedded systems implementing safety critical functions I realize that there is a pattern: when high-level programmers talk about security and reliability, they basically mean "hackers breaking your system to steal your passwords". To the point that memory bugs = security vulnerabilities, and nothing else. This, of course, has another meaning for embedded.
- segfaultbuserr 5y agoFor application development, a memory corruption bug or a race condition is a safety issue that causes data corruption, and when the same corruption can be used to compromise the system, it's a security issue, as you said, often there's no point to distinguish them. In the embedded world, this distinction can be important. If a vendor says its microcontrollers have safety features, it means an elaborate system of watchdog timers, glitch-filtered inputs, and checksums. On the other hand, "a microcontroller with security features" means a crypto engine and secure key storage memory.
- scoutt 5y agoI agree with what you wrote. > there's no point to distinguish them I think the distinction should be clearly made when someone wants to sell me something like Rust. They come up with the daily link about 70% of the bugs are memory issues plus something in the lines of "memory vulnerabilities! think about the hackers! exploits!", when it's clear that these arguments don't click in (many areas of) embedded. Safety and security have another meaning. The steal of a password is the least of my fears, if I think a bad implementation of mine can chop-off the hand of an operator.
- hrishi 5y agoI see how the title might mislead one into thinking that the author was about to outline his problems fitting V8 into a uC, but I don't understand the upset that he was successful. If successful, the streaming service with lack of relocation should be a useful tool in the toolkit for working with microcontrollers. I don't see much use for it for me at the moment, but then I haven't used uLisp much either.
- apaprocki 5y ago... but if you do want a modern JS engine running on a microcontroller: https://github.com/Moddable-OpenSource/moddable#moddable-sdk https://github.com/Moddable-OpenSource/moddable#moddable-sdk
- kabdib 5y agoHmmm. If I chose a chip with the resources to run this Toit thing, I can reduce costs by switching to a cheaper, less powerful chip and writing native code. If I'm shipping several million of these, it's a no-brainer; it saves real money. In some products I've worked on, saving ten cents per board would be a big deal. Also note that you're paying more than money; fancier and more capable chips usually consume more power, so imagine some lively conversations with the industrial design folks about battery lifetime and size, too. If you're using off-the-shelf consumer-y ESP things, you're likely insensitive to cost and you're probably paying for performance you don't need. I last saw this technique (maybe 15 years ago) used by a super tiny .NET runtime environment intended for devices like smart watches; you wrote to "tiny" APIs, a tool did a bunch of reprocessing of your binary into smaller tables and whatnot, and poof, it would run on a watch. With all the GC and so forth going on, it's not something I'd want to write a whole embedded system in, though it was okay for applets. I'm not oblivious to the security advantages of using a bytecode interpreter, but on a high-volume product you'd have to make a case for how important this kind of thing is.
- buescher 5y agoESP32 is extremely price competitive in its space. The use case is internet connected applications, which are going to need the kinds of resources Toit requires anyway. What gets me is the implicit promotion of javascript as the gold standard of available tooling. That gives me hives, even though it's probably true.
- iainctduncan 5y agoPeople who write these bait-and-switch marketing articles really need to learn that once you do it, you lose potential readers for a long time. There are so many interesting things to read every day - I'm not going to waste any of my precious attention on his writing again after that.
- adunk 5y agoI have been in the embedded domain for many years. I really like the approach taken by the team here. Particularly since this team is really well-versed in developing virtual machines and programming languages. But I am very much biased in their favor. Embedded development is tricky, and anything that can help improve the productivity is useful. The problem is that there have been many, many attempts at doing this exact same thing over the years. And they all have to fight the same fight: to get some serious traction for their particular approach. Back in the 00's, Sentilla did a Java VM for the MSP430. This got a lot of traction - they even had James Gosling himself vouch for the project. More recently, Electric Imp and Particle.io have taken similar approaches, but with other languages. Micropython and a variety of mini-JS engines are also around. Espruino, Tessel.io, and many more. In a technical sense, running a virtual machine on a microcontroller is a really good way to go. You remove a lot of low-level friction that you otherwise have to deal with. And you get a lot of things almost for free, such as Over-The-Air (OTA) updates, and more control over security. But when you get down to actually doing the work, you frequently end up wanting to have all that low-level access, even if you have to endure a bit of pain. Sometimes you don't even want to have an operating system with a hardware abstraction layer. You kinda want the bare metal. So Toit are in a tricky situation. They may have a really good product. But they will have to get some serious traction. Developing a rock solid programming language and virtual machine is hard. Really hard. But it is way easier than to get that sweet, sweet traction.
- lurkerasdfh8 5y agoIt is the same problem all over again. embedded is tricky because you want to do too much with too little. Then every time there's advancements in what you have available, people add all the niceties back. And at this point it is not embedded anymore. It's just a low power full device. Just like java for the MSP430 (like anyone would spend $7.99 per chip for a TV remote with 2week batteries, instead of $0.004 and 2+month) True embedded development usually doesn't even have room for a watchdog timer. let alone virtualization and memory protection. This is not new. This is not embedded. This is just the usual cycle of hardware generation changing and people in academia ivory tower (or worse, google solid gold tower) having nicer toys than everyone else.
- rattray 5y agoThe author started with the premise that V8 won't fit on a microcontroller, but didn't really justify why a new language was needed. Why would someone choose Toit over Espruino or QuickJS, which seem to promise JS on a microcontroller? http://www.espruino.com http://www.espruino.com https://bellard.org/quickjs https://bellard.org/quickjs
- skybrian 5y agoIt seems like a neat technology but it would be useful to have some concrete examples of what you can do. The company sales pitch seems to be about fleet management and over-the-air updates. This doesn’t seem very relevant to me considering that I’m a hobbyist flashing a single microcontroller over USB, and I never run more than one program at a time. But perhaps I’m just not the target market and I’m not imagining the right use cases?
- buescher 5y agoKaspar Lund is very smart and amazingly productive so this sales pitch is disappointing. Amazon's work on formal verification of portions of FreeRTOS, for example, is sophisticated and impressive. What Lund misses in his characterization of FreeRTOS as "primitive" is how much refinement goes into simplicity in embedded work. Here's an example: FreeRTOS' over-the-air update (OTA) mechanism has been formally verified. Why would you formally verify your OTA update mechanism? Because getting OTA updates right is one of those simple things that turns out to be hard. Hard problems aren't solved by just adding another layer of abstraction; my expectation is that it will be more difficult to establish a Toit system is performing correctly than a conventional bare-metal or RTOS-based embedded system.
- skybrian 5y agoI would charitably reinterpret "primitive" more positively like in "language primitives." They are essential.
- ngrilly 5y agoI got interested by the idea of a virtual machine for microcontrollers, but I'm less excited about having to use a new dedicated programming language, and the ESP32 being the only supported hardware.
- abraae 5y agoAll sounds amazing. On esp32 though I'd settle for simply a way to emulate the TFT display. It gets old re-flashing the device to move a pixel one to the right or to add a println for debugging.
- kgr 5y agoSeems to be heavily influenced by the Smalltalk language and VM. I find it interesting that people will say that embedded microcontrollers are too resource constrained for this type of system, despite many being significantly more powerful than the original Xerox workstations that ran Smalltalk. And those machines were considered mini-computer-class machines at the time.
- ostenning 5y agoOver the past 8 months I’ve been working with Rust on STM32’s and it’s pretty impressive to say the least. For me, a solid, well documented HAL that works well is key to efficiency in embedded development. Rusts language features and the ability to abstract things like SPI or I2C peripherals that were once impossible in C are totally doable in Rust, and the community is growing. Highly recommend checking it out
- anthk 5y ago> like SPI or I2C peripherals that were once impossible in C How so?
- ostenning 5y agoI can write a Rust library for an OLED device that is driven by a platform agnostic I2C device that will run on any microcontroller that implements the necessary abstractions. The `embedded-hal` (https://github.com/rust-embedded/embedded-hal https://github.com/rust-embedded/embedded-hal) are these abstractions that allow this to happen