Port of Espruino to Pi Zero - native - no Linux

Posted on
of 2
/ 2
  • There are a lot of kickstarter boards based on OpenWRT that would probably benefit from Espruino, either because node isn't working on them or because Espruino + IDE are a better fit than node. The one that comes to mind is the Onion Omega, but I know that tiny OpenWRT wifi boards
    are all the rage, each with their own communities, so might be an easy way to grab some interest in espruino.

  • Yes, there's this issue at the moment to track doing an OpenWRT package: https://github.com/espruino/Espruino/iss­ues/143

    I think the Onion will actually run Node, but Espruino's memory requirements mean you could run it one something with maybe just 16mb RAM (that barely runs Linux).

    To be honest there's not a lot to do, it just needs submitting.

    ... while we're on the topic of small things to cram it into, I'm sure it could potentially be stuck into something like Coreboot. It'd be pretty fun to be able to put it into the PC BIOS!

  • @Gordon last I checked the Onion needed an old version of node with a bit of effort put into getting it compiled. I haven't paid much attention though, espruino kind of stole its place for me. :P

  • I was wondering if there was any more work done on this issue.

    As someone just starting out in the embedded space, I can testify that the Pico has a much better beginner experience than a Raspberry Pi, especially for JavaScript.

    I can put some work in on this issue... I like the idea of DietPI that boots directly into a Espruino prompt that can be programmed using the Web IDE.

    Besides the timer issue (BTW, here's the Broadcom datasheet for the Zero), anyone foresee any problems?

  • I haven't done any more work on it, but it'd be great if you were willing to take a look at it - it should be pretty easy, especially as @tve has added a Telnet interface to it now. Hopefully it wouldn't be much more difficult than taking a minimal Pi image, adding Espruino and a few scripts.

    Even as-is, it's still pretty usable - just without the timer you're not going to be able to do totally accurate pulses, but SPI, I2C, etc are still fine.

    Just some ideas:

    • Make the onboard serial port boot straight into Espruino (rather than a shell), so you could program it with a USB-TTL adaptor
    • There's a real-time version of Linux for the Pi I think - you might be able to experiment with that
    • Set up a simple HTTP server which serves up https://github.com/espruino/EspruinoWebI­DE - you'd need to hack up something that'd get you communications with Espruino from the Web Browser though. A simple WebSocket server that forwarded websocket connections to Telnet would work well (and could actually just be another Espruino instance).

    And other slightly harder stuff:

    • Add Wifi.connect-style functions that'd allow you to use WiFi to connect to networks and stuff
    • Add software I2C so you can use I2C on any pins - this would be useful for all devices, but unfortunately hasn't been added yet (SPI already works)
  • Thanks for all the nitty-gritty details, @Gordon!

    About the timer: are we sure this isn't doable? I'm not familiar with the terminology, so I'm not sure what to even Google. The Broadcom datasheet implies there's a timer, but I don't know enough to see if it's the "right kind" of timer.

  • Well, the timer might be possible. The problem is I'm pretty sure Linux uses at least one timer for the Kernel, so it's whether anything is left over for you to use really - I had a quick google but I can't see any examples of getting an IRQ for a timer while under Linux :(

    The WiringPi library is used for getting the IRQs when pins change state, but for its soft PWM it actually uses normal threads, which makes me think that using a timer IRQ directly may not be possible: https://github.com/WiringPi/WiringPi/blo­b/master/wiringPi/softPwm.c

    Doing something similar to that could be an option. It's not perfect but it would be better than nothing.

  • I agree with @TheAlchemist, the beginner experience with the Espruino Pico has been much better than pi and Tessel. It seems all these embedded systems vendors are thinking only of robots / IoT, and completely forgetting about wearables. I think the Espruino project has done really well in avoiding that mistake.

    The pi zero is attractive to me as a platform for an open-source product because users can write in whatever language they like. What's frustrating for me is the long boot time in every distro, since I'm making a wearable product and it shouldn't take 15 seconds to turn on!

    My end goal is to enable users to work in the language of their choosing, and I plan on supporting more than one MCU (like MicroPython). I was thinking the pi zero would be a good fit, but not if I can't get instantaneous boot.

  • Thanks!

    As far as the Pi goes, if you look at what gets loaded when it boots, it's an insane amount. It'd be well worth fiddling with building your own Linux kernel - it's very configurable and you can really strip it back.

    To be honest I bet someone's already come up with a super-minimal distribution. You could try OpenWRT as a start. I bet you could get the boot time well under 1 second with fairly little work.

  • I have spent quite a bit of time getting a pi to fastboot.

    You can use buildroot or yocto to build a custom kernel. I think I had a buildroot version booting in about 4 secs, and the wifi network would be up in about 10 secs - compared to 30-45 secs on the normal pi Distro.

    It is a lot of work to do a custom kernel - not for the faint hearted!
    There are a few minimal pi installs that could be a starting point for you.

  • Ahh, thanks! Looks like under 1 second was a bit optimistic.

    Did a quick google and there's a downloadable image here that does 3 seconds straight into a game emulator: https://www.raspberrypi.org/forums/viewt­opic.php?f=63&t=56413

    So you've got to ask yourself if it's worth the effort writing your own hardware drivers and networking stack in order to save what's realistically only 2 seconds max.

    If you come up with a minimal Espruino/micro python image for Pi I'd be really interested though - it could be really neat (especially as the Pi could even serve up the Web IDE).

  • 'boot time': ...kind of a 'hibernate' mode should be available... save to and load/boot from a flash a memory runtime image. (Espruino got this right from very beginning!... amount of memory not really comparable though...). Some initialization is though still required, especially for connections... cached peripheral/sensor states,...

  • Yes, I'm kind of surprised about that. I'd have thought you could load a compressed image straight from the SD card into RAM and then run from there (I think that's what OpenWRT does on routers).

  • Sorry no hibernate or power management on the pi.

    The sd card is creally the bottle neck. The way pi boots is quite odd, the gpu reads data from thef first fat partition on the disc, loads that into memory, and then hands that over to the arm CPU which then boots and reads the Linux paritition. For a minimized Linux, the kernel boot file is about 200mb.

  • I've seen the game emulator example. The guy who made it doesn't seem to have interest in helping newbies do what he's done. There are people who try to teach others how to do these things, for example, this embedded midi player was built by a guy who created a complete course on OS development.
    and his course, "Baking Pi"

    I also found this really awesome guide on building Arduino sketches for the pi.

    The network access isn't needed immediately upon boot. The device can show a status indicator while the network system is coming up. But a chosen interpreter and associated runtime scripts need to start running immediately, because it will operate the UI, I2C, and be responsible for all device logic. I've read that it's possible to prevent the kernel from waiting for network devices to reach ready state.

    <1s: https://www.youtube.com/watch?v=-l_DSZe8­_F8

    The search continues.

    Getting warmer.


  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Port of Espruino to Pi Zero - native - no Linux

Posted by Avatar for Kolban @Kolban