Importance of Python

Large scale deployment of embedded systems demands inexpensive components. Considerations such as small size, high reliability and low power consumption are also very important. Specialized processor chips, called microcontrollers, have been developed to meet these goals. Combining CPU, memory and peripherals (such as UARTs) on a single chip, modern microcontrollers are marvelous devices. These features, however, come at a significant price. A typical microcontroller has only a few hundred bytes of RAM, several K of ROM (to store the program) and orders of magnitude less processing capability than a conventional desktop microprocessor. Hardly an environment for running Python!



There are projects to adapt Python for embedded applications, but they require significant resources on the microcontroller, and are still in the very early stages. Surprisingly, however, it turns out that standard Python is of tremendous value throughout an embedded system's lifecycle. This is because the highly resource-constrained nature of embedded devices make them dependent on standard PCs for many tasks -- both during development and during deployment.
For example, embedded software is compiled on conventional desktop systems, and the resulting object code is then loaded onto the target microcontroller. Another example is troubleshooting a device in the field, which usually requires additional hardware to run a diagnostic utility. Ordinary laptops are a very attractive platform for this application, due to their ready availability and relatively high level of standardization.

Thus, a major part of any embedded software development effort is writing the required support code, to run on a standard PC. There are quite a few languages available for this task, but the advantages of Python are many. Python is quite easily learned by people from various programming backgrounds, such as Java, C or Visual Basic. After becoming familiar with Python, development proceeds very quickly -- perhaps faster than with any other language. At the same time, Python lends itself to the creation of highly readable, compact and well structured code.
Python's particular mix of features also helps embedded developers be more effective when programming a PC. While these developers are well familiar with C (by far the most popular high level language for embedded systems) a C program written for a standard desktop or server is quite different in style from one for a microcontroller.

The compactness of Python programs is especially important, because embedded developers have, by necessity, learned to express their designs in a very small amount of code. Python's automated memory management also helps, because many embedded developers have little experience with dynamic memory allocation -- a technique that is not practical in most embedded environments. In addition, the Object-Oriented facilities of Python are simple, powerful yet not coercive. This allows embedded developers (who are often less familiar with OOP) to gradually adopt the Object-Oriented paradigm in their work.

As embedded systems grow in complexity, the advantage of using Python to augment traditional techniques becomes more and more important. At Carmanah, Python adoption (which began with the crosswalk traffic beacon, a sophisticated device that includes wireless networking) has spread to several key areas of the embedded system's lifecycle.

A Python program controls the software build process, allowing firmware for different products to be put together from a large number of shared components. The build system is simple yet a lot more flexible than makefiles, as well as easier to customize, configure and extend. Unlike the build tools supplied by compiler vendors, the Python-based build system can work with different compilers.
Python is also used for stress tests and unit testing -- an aspect of development particularly vital in embedded systems, due to the inherent difficulty of upgrading devices once they are in the field. Additional uses of Python, such as for control panels and code generation, are being considered as well.

No comments:

Post a Comment