2018-06-17 22:29:22 -04:00
|
|
|
Example of embedding MicroPython in a standalone C application
|
|
|
|
==============================================================
|
2016-06-15 19:30:08 -04:00
|
|
|
|
2022-10-05 20:14:58 -04:00
|
|
|
This directory contains a simple example of how to embed MicroPython in an
|
|
|
|
existing C application.
|
2016-06-15 19:30:08 -04:00
|
|
|
|
2022-10-05 20:14:58 -04:00
|
|
|
A C application is represented here by the file `main.c`. It executes two
|
|
|
|
simple Python scripts which print things to the standard output.
|
2016-06-15 19:30:08 -04:00
|
|
|
|
|
|
|
Building the example
|
|
|
|
--------------------
|
|
|
|
|
2022-10-05 20:14:58 -04:00
|
|
|
First build the embed port using:
|
2016-06-15 19:30:08 -04:00
|
|
|
|
2022-10-05 20:14:58 -04:00
|
|
|
$ make -f micropython_embed.mk
|
2016-06-15 19:30:08 -04:00
|
|
|
|
2022-10-05 20:14:58 -04:00
|
|
|
This will generate the `micropython_embed` directory which is a self-contained
|
|
|
|
copy of MicroPython suitable for embedding. The .c files in this directory need
|
|
|
|
to be compiled into your project, in whatever way your project can do that. The
|
|
|
|
example here uses make and a provided `Makefile`.
|
2016-06-15 19:30:08 -04:00
|
|
|
|
2022-10-05 20:14:58 -04:00
|
|
|
To build the example project, based on `main.c`, use:
|
2016-06-15 19:30:08 -04:00
|
|
|
|
2022-10-05 20:14:58 -04:00
|
|
|
$ make
|
2016-06-15 19:30:08 -04:00
|
|
|
|
2023-03-07 22:10:02 -05:00
|
|
|
That will create an executable called `embed` which you can run:
|
2016-06-15 19:30:08 -04:00
|
|
|
|
2022-10-05 20:14:58 -04:00
|
|
|
$ ./embed
|
2016-06-15 19:30:08 -04:00
|
|
|
|
|
|
|
Out of tree build
|
|
|
|
-----------------
|
|
|
|
|
2017-02-15 05:12:23 -05:00
|
|
|
This example is set up to work out of the box, being part of the MicroPython
|
2022-10-05 20:14:58 -04:00
|
|
|
tree. Your application will be outside of this tree, but the only thing you
|
|
|
|
need to do for that is to change `MICROPYTHON_TOP` (found in `micropython_embed.mk`)
|
|
|
|
to point to the location of the MicroPython repository. The MicroPython
|
|
|
|
repository may, for example, be a git submodule in your project.
|