PyMite Overview
| Author: | Dean Hall |
|---|
Purpose
This document gives an overview of PyMite the software and the project that develops it. In doing so, it helps the newcomer understand the scope of the project and intended purpose of the software.
Introduction
PyMite is a flyweight Python interpreter written from scratch to execute on 8-bit and larger microcontrollers with resources as limited as 64 KiB of program memory (flash) and 4 KiB of RAM. PyMite supports a subset of the Python syntax and can execute a subset of its bytecodes. PyMite can also be compiled, tested and executed on a desktop computer.
PyMite is targeted toward microcontrollers with extremely limited program memory and RAM. In order to operate in this embedded environment, PyMite sacrifices many features found in desktop Python. However, the author believes that enough of Python's core abilities are present in PyMite to make PyMite valuable embedded programming platform.
Intended Audience
With Python's reputation for being friendly to beginning programmers, PyMite should appeal to those who are programming microcontrollers for the first time. For those familiar with Python, PyMite provides a rapid development language for embedded systems. And for those with Python and C or assembly experience, PyMite's Native Function interface provides a powerful way to embed low-level code in a PyMite function. In short, PyMite has something for all levels of programmers.
Target Devices
PyMite's first target device was the Atmel AtMega103 that was used in the author's control board for mobile robotics. PyMite has since been made to support any device in the AVR family that has at least 64 KiB program memory and 4 KiB RAM.
The second target device is Atmel's ARM7TDMI family, a.k.a. the SAM7 family. This is a 32-bit platform with no MMU.
Porting to a new 8-bit or 32-bit platform is extremely easy. Usually only one function to access a device's special memory areas needs to be written. PyMite has no external dependencies unless compiling for the Desktop where printf() is used to display debug messages.
Python Language Support
There is no way to support the full set of Python's language features on these small, embedded target devices. The following lists give an overview of what features PyMite supports:
- PyMite supports these features:
- Data types: Int, String, Tuple, List, Dict
- Most basic operators on supported types
- All control flow statements except yield
- Limited iterators (sequence-iterators in for-loops only)
- Bit operations
- Object organization: modules
- Garbage collection (mark-sweep)
- Built-in functions: abs, chr, globals, id, len, locals, map, ord, pow, range, sum, type
- Exceptions in the C API and interpreter
- PyMite-specific library modules
- PyMite DOES NOT support these features:
- Data types: Boolean, Float, Complex, Long, Unicode, File, Set
- Object methods of any built-in datatype (e.g.: string.reverse())
- Sequence slicing
- Operator overloading
- Anonymous functions
- Function decorators
- Object organization: packages, classes
- Raising and catching exceptions
- Object deletion and finalization
- Complex features: list comprehension, generators, coroutines, threading
- Any Python library
See PyMiteFeatures for a detailed description of what PyMite supports. Suffice to say, PyMite has enough to keep you busy.
Additional Features
PyMite would not be complete without a way for the Python application code to call low-level routines to access the special features of a microcontroller. PyMite provides this advanced feature called Native Function and has a slick and easy way to implement them. Native Functions are written by defining a function in Python code with the keyword pass as the function's body, but inserting C code in the function's documentation string. Macros are provided to access the PyMite stack and arguments to the function. Within the C code, the developer may write assembly code using the asm() statement if desired. The context switch overhead to call a Native Function is near that of calling a function from within C. This fast and convenient interface between Python code and C code provides the advanced developer a means to access the low-level features of the microcontroller and PyMite itself.
The PyMite Project
http://pymite.python-hosting.com is a Trac site which serves as the center for PyMite development. All releases, defects and documentation can be found there. PyMite comes as a source code distribution only. The user must install a cross-compile toolchain (such as WinAvr, avr-gcc or arm-elf-gcc) in order to build PyMite for a target device. PyMite uses a Makefile system and the GCC toolchain by default to build the PyMite library file. The user must write a main() function in C, compile that to an executable, link in PyMite and download the binary to the microcontroller. Sample projects are provided.
PyMite does not have a set schedule for releases. The current system is to make a release when a significant set of changes have been mainlined and a fair set of tests has shown the changes to be working to some degree. The determination of "significant" is up to the lead developer.
If PyMite does not support your needs now, join the PyMite discussion list to make your desire known and help make it happen.
Downloading PyMite
The PyMite project is hosted at http://pymite.python-hosting.com. The latest PyMite release is available for download from that site. The site also explains how to obtain the latest development version of PyMite via the Subversion source code management tool.
Future Work
- The big areas for future work in PyMite are:
- Increase ease-of-use for novice users
- Provide a useful interface library for the AVR microcontroller
- Support threading with a thread library and scheduler
See the following page for more LongTermIdeas
