
Python-on-a-chip - coderdude
http://code.google.com/p/python-on-a-chip/
======
TimothyFitz
Tangentially related: Four or five years ago I was an R&D intern working on
replacing an ancient EOL'd embedded processor. We were targeting an FPGA with
a soft processor (Alterra's Nios II), and found out they were powerful enough
to run Linux directly. The device was doing realtime motion control, so we
slapped two soft cores onto the FPGA and had them talk over drop-in bus. One
did realtime, the other ran Python. It was a nifty way to hack on an HTTP
status page, a test runner... not sure if it ever shipped.

------
kqr2
The reference platform is mbed:

<http://mbed.org/tour/>

It's kind of neat that they have an online c++ compiler for it.

<http://mbed.org/democompiler/>

------
nickpinkston
For you Rubyists out there, there is also RAD - a Ruby version of this for the
Arduino platform:

<http://rad.rubyforge.org/>

~~~
SingAlong
That converts ruby programs to Arduino compatible C program.

The project linked from the thread's title says that Python runs on the chip
itself unlike the RAD for Arduino that compiles down to a C program.

~~~
nickpinkston
Yea, it's true - not an apple to apples comparison, but still: Ruby for the
'duino!

------
tsally
Makes me miss Lisp machines :-/

~~~
rbanffy
I keep trying to convince myself I should learn some HDL. Reconstructing a
Lisp machine would be a nice project.

A fully functional Lisp machine with a USB keyboard and mouse to match would
be the ultimate übergeek gift.

A small Alto would also be pretty neat. The vertical screen could be tricky.

~~~
torpor
I just have to ask why? What is so neat about it? Please enlighten ..

~~~
rbanffy
The Alto was, IIRC, the first machine with a bit-mapped display, overlapping
windows, Smalltalk, a mouse...

Seriously: more than once we have lost a technology because we turned the
other way at some point. The Lisa'a stationery idea is one example off the top
of my mind of a great idea that was not only ahead of its time but ahead of
our time. We install programs and run them to create documents instead of
using a desktop to create a document of a new type that the program we
installed happens to support. I like to joke Smalltalk 80 made Java 2010 look
primitive. I am only half joking on that.

------
sliverstorm
"Requires roughly 40 KB program memory and initializes in under 3 KB of RAM"

Maybe I'm just not 'with it', but last microcontroller I used had 64KB of
address space. 43KB overhead seems like a lot.

~~~
xkenneth86
Well, there are a ton of Micro's today that can easily support that and there
a ton that aren't. We work with high temperature microcontrollers so our
devices end up having about 32k flash and about 8k ram.

------
dfox
Losely related: does anyone know of cheap (and fast) microcontroller with von
neuman architecture (ie. able to execute code from RAM) and usable amount of
embedded RAM (say 32KB at least)?

Only microcontroller architecture than I know of than can be (ab)used as von
neuman machine is MCS-51 (and there are even some mass produced products that
do that and have self-modifing firmware). But MCS-51 is not exactly fast and
moreover this hack requires considerate amount of external components.

~~~
ComputerGuru
I don't understand: they all (more or less) execute code from RAM. You can't
execute code from ROM, and you can only fit an instruction at a time (or so)
in the IR within the CPU. Von Neuman doesn't have an exclusive on that.

The architecture of the CPU refers more to how the data is processed
internally, but generally speaking, it's always "load from ROM, stick in RAM,
execute in CPU, write results back to RAM." Rinse and repeat.

However, the Von Neuman views both ROM and RAM as a single, vertical unit. You
can shift data to and from the ROM & RAM as needed to represent a single high-
speed high-volume storage unit, _but_ that's only needed if you want an easy
way to page RAM to disk (not run programs from RAM).

The Modified Harvard Architecture is nice, and is popular with many embedded
devices. I primarily use Atmel, and their Modified Harvard works great for me.

Have a look: <http://en.wikipedia.org/wiki/Modified_Harvard_architecture>

When you're dealing with embedded devices, there's (almost always) another way
of dealing with the RAM requirements. For instance, I highly recommend the
AT90USB1286 CPUs for hobbyists and entry-level enterprise stuff because of
their true USB support and super-low cost. These only have 8k of RAM, but they
have 128k Flash memory. You should be able to use the flash to do what you
need.

The only time you need the kind of stuff you describe is when you're basically
running software meant for "normal" CPUs on microcontrollers. When you're
trying to run "operating systems" instead of firmware, and "packages" instead
of highly-optimized and platform-specific code, that's when you need 32KB+
RAM. For everything else, a larger (32KB+ all the way till 1MB) ROM backend
will do.

My only problem with the ATMEL was the limited EEPROM size for the actual
firmware, and since it's a Harvard architecture the separation between data
and instructions makes it difficult to run code from the flash ROM. But the
new generation now has 8k+ EEPROM for the firmware, which is a nice
improvement.

~~~
dfox
And running "operating system" is exactly what I'm trying to achieve. What I
want is simple and cheap hardware platform for teaching.

~~~
ComputerGuru
Then you don't want a microcontroller. What you want is a dirt-cheap all-in-
one CPU/RAM/ROM package.

Have a look at mini PCs and plug PCs.

<http://www.hawkboard.org/distributors>
[http://www.linuxfordevices.com/c/a/News/Mini-Linux-PC-
breaks...](http://www.linuxfordevices.com/c/a/News/Mini-Linux-PC-
breaks-100-barrier/) <http://www.wired.com/gadgetlab/2009/02/marvell-offers/>

Of course, you don't say _what_ you want to teach, so these could be totally
missing the mark.

------
jey
What's the motivation for this?

~~~
coderdude
The ability to use Python (instead of C, C++, or some flavor of assembly) on
small chips and microcontrollers.

~~~
jey
That doesn't really answer the question. Why would one want to do that, and
why's that worth the trouble?

"What's the motivation to make a chip that runs Python?" "To be able to run
Python on a chip."

~~~
coderdude
Write once/run anywhere would be a motivation. By the looks of it you wouldn't
be able to literally run just any script on the chips that you bring over from
a desktop machine, but the amount of tweaking would be minimal I think.

Being able to use Python's standard library on a chip would be useful. It's a
dynamic language so you can _do_ things you couldn't do with C. It's type-safe
and easy as all hell to use. The usual motivations for using Python apply
here. It just uses more resources and is understandably slower to execute.

~~~
viraptor
Some objections:

 _Write once/run anywhere would be a motivation._ \- "Run anywhere" is not
true for most desktop programs and definitely not true for embedded stuff.
When you're at 64k, you usually don't even reuse stuff like display handling,
because your PCB layout is different enough that you'd have to rewrite the i/o
layer anyways. Or because you a specific way to get the data. Or...

I can't imagine much reasonable code reuse outside of standardised platforms
like Arduino. Much less any "run anywhere" programs.

 _It's a dynamic language so you can do things you couldn't do with C_ \-
There's nothing in language X, that you cannot do in C.

Since it seems to be a google project, I guess they're just trying to create
something that can be pushed onto Android, much like their own Java VM.

------
samratjp
Sweet! Hope we can soon have Arduino support! I love the Arduino python
libraries and would love to see this embeddable!

~~~
dfox
AVR is probably too limited to run almost any kind of dynamic VM effectively
(with notable exception of forth).

Classic microcontrollers (which AVR essentially is) have relatively large
amounts of program memory combined with miniscule RAM, for dynamic VM you need
it exactly other way around.

~~~
jsnyder
It will run on 8-bit AVRs, however, mainly the the ones with the largest
quantities of RAM. I'm not sure if any of the available Arduino platforms meet
the requirements.

------
joezydeco
You have to wonder who will be the first to put the Dalvik VM on a chip. Yeah,
I know it's been tried with Java before.

~~~
nl
Ironically, many ARM chips - including the ones Dalvik run on - include
Jazelle, which allows them to run Java bytecode directly. But then many argue
that a good JIT will give you better performance anyway. There's a reasonable
discussion on StackOverflow: [http://stackoverflow.com/questions/1153076/does-
andriod-cast...](http://stackoverflow.com/questions/1153076/does-andriod-
castrate-the-arms-jazelle-technology)

(I wasn't clear from your statement "I know it's been tried with Java before"
if you knew it is working on ARM, or if you were referring to niche chips like
the JavaChip etc)

~~~
joezydeco
I was referring to JavaChip specifically.

I'm just wondering as the Android footprint grows if this could be an
evolutionary step. It's also been rumoured that Apple could buy out ARM
Holdings.

