Name Date Size

..27-Apr.-20224 KiB

.git-blame-ignore-revsH A D05-May-20221.6 KiB

.gitattributesH A D18-Aug.-2021709

.github/H18-May-20224 KiB

.gitignoreH A D18-Aug.-2021599

.gitmodulesH A D30-Jun.-20221.8 KiB

ACKNOWLEDGEMENTSH A D18-Aug.-202142.2 KiB

CODECONVENTIONS.mdH A D18-Aug.-20218.5 KiB

CODEOFCONDUCT.mdH A D18-Aug.-20212.6 KiB

CONTRIBUTING.mdH A D18-Aug.-2021357

docs/H21-Jun.-20224 KiB

drivers/H04-Apr.-20224 KiB

examples/H18-Aug.-20214 KiB

extmod/H30-Jun.-20224 KiB

lib/H30-Jun.-20224 KiB

LICENSEH A D06-Jan.-20223.2 KiB

logo/H18-Aug.-20214 KiB

mpy-cross/H26-May-20224 KiB

ports/H29-Apr.-20224 KiB

py/H30-Jun.-20224 KiB

README.mdH A D18-Feb.-20228.1 KiB

shared/H18-Aug.-20214 KiB

tests/H28-Jun.-20224 KiB

tools/H17-Jun.-20224 KiB

README.md

1[![CI badge](https://github.com/micropython/micropython/workflows/unix%20port/badge.svg)](https://github.com/micropython/micropython/actions?query=branch%3Amaster+event%3Apush) [![codecov](https://codecov.io/gh/micropython/micropython/branch/master/graph/badge.svg?token=I92PfD05sD)](https://codecov.io/gh/micropython/micropython)
2
3The MicroPython project
4=======================
5<p align="center">
6  <img src="https://raw.githubusercontent.com/micropython/micropython/master/logo/upython-with-micro.jpg" alt="MicroPython Logo"/>
7</p>
8
9This is the MicroPython project, which aims to put an implementation
10of Python 3.x on microcontrollers and small embedded systems.
11You can find the official website at [micropython.org](http://www.micropython.org).
12
13WARNING: this project is in beta stage and is subject to changes of the
14code-base, including project-wide name changes and API changes.
15
16MicroPython implements the entire Python 3.4 syntax (including exceptions,
17`with`, `yield from`, etc., and additionally `async`/`await` keywords from
18Python 3.5). The following core datatypes are provided: `str` (including
19basic Unicode support), `bytes`, `bytearray`, `tuple`, `list`, `dict`, `set`,
20`frozenset`, `array.array`, `collections.namedtuple`, classes and instances.
21Builtin modules include `sys`, `time`, and `struct`, etc. Select ports have
22support for `_thread` module (multithreading). Note that only a subset of
23Python 3 functionality is implemented for the data types and modules.
24
25MicroPython can execute scripts in textual source form or from precompiled
26bytecode, in both cases either from an on-device filesystem or "frozen" into
27the MicroPython executable.
28
29See the repository http://github.com/micropython/pyboard for the MicroPython
30board (PyBoard), the officially supported reference electronic circuit board.
31
32Major components in this repository:
33- py/ -- the core Python implementation, including compiler, runtime, and
34  core library.
35- mpy-cross/ -- the MicroPython cross-compiler which is used to turn scripts
36  into precompiled bytecode.
37- ports/unix/ -- a version of MicroPython that runs on Unix.
38- ports/stm32/ -- a version of MicroPython that runs on the PyBoard and similar
39  STM32 boards (using ST's Cube HAL drivers).
40- ports/minimal/ -- a minimal MicroPython port. Start with this if you want
41  to port MicroPython to another microcontroller.
42- tests/ -- test framework and test scripts.
43- docs/ -- user documentation in Sphinx reStructuredText format. Rendered
44  HTML documentation is available at http://docs.micropython.org.
45
46Additional components:
47- ports/bare-arm/ -- a bare minimum version of MicroPython for ARM MCUs. Used
48  mostly to control code size.
49- ports/teensy/ -- a version of MicroPython that runs on the Teensy 3.1
50  (preliminary but functional).
51- ports/pic16bit/ -- a version of MicroPython for 16-bit PIC microcontrollers.
52- ports/cc3200/ -- a version of MicroPython that runs on the CC3200 from TI.
53- ports/esp8266/ -- a version of MicroPython that runs on Espressif's ESP8266 SoC.
54- ports/esp32/ -- a version of MicroPython that runs on Espressif's ESP32 SoC.
55- ports/nrf/ -- a version of MicroPython that runs on Nordic's nRF51 and nRF52 MCUs.
56- extmod/ -- additional (non-core) modules implemented in C.
57- tools/ -- various tools, including the pyboard.py module.
58- examples/ -- a few example Python scripts.
59
60The subdirectories above may include READMEs with additional info.
61
62"make" is used to build the components, or "gmake" on BSD-based systems.
63You will also need bash, gcc, and Python 3.3+ available as the command `python3`
64(if your system only has Python 2.7 then invoke make with the additional option
65`PYTHON=python2`).
66
67The MicroPython cross-compiler, mpy-cross
68-----------------------------------------
69
70Most ports require the MicroPython cross-compiler to be built first.  This
71program, called mpy-cross, is used to pre-compile Python scripts to .mpy
72files which can then be included (frozen) into the firmware/executable for
73a port.  To build mpy-cross use:
74
75    $ cd mpy-cross
76    $ make
77
78The Unix version
79----------------
80
81The "unix" port requires a standard Unix environment with gcc and GNU make.
82x86 and x64 architectures are supported (i.e. x86 32- and 64-bit), as well
83as ARM and MIPS. Making full-featured port to another architecture requires
84writing some assembly code for the exception handling and garbage collection.
85Alternatively, fallback implementation based on setjmp/longjmp can be used.
86
87To build (see section below for required dependencies):
88
89    $ cd ports/unix
90    $ make submodules
91    $ make
92
93Then to give it a try:
94
95    $ ./micropython
96    >>> list(5 * x + y for x in range(10) for y in [4, 2, 1])
97
98Use `CTRL-D` (i.e. EOF) to exit the shell.
99Learn about command-line options (in particular, how to increase heap size
100which may be needed for larger applications):
101
102    $ ./micropython -h
103
104Run complete testsuite:
105
106    $ make test
107
108Unix version comes with a builtin package manager called upip, e.g.:
109
110    $ ./micropython -m upip install micropython-pystone
111    $ ./micropython -m pystone
112
113Browse available modules on
114[PyPI](https://pypi.python.org/pypi?%3Aaction=search&term=micropython).
115Standard library modules come from
116[micropython-lib](https://github.com/micropython/micropython-lib) project.
117
118External dependencies
119---------------------
120
121Building MicroPython ports may require some dependencies installed.
122
123For Unix port, `libffi` library and `pkg-config` tool are required. On
124Debian/Ubuntu/Mint derivative Linux distros, install `build-essential`
125(includes toolchain and make), `libffi-dev`, and `pkg-config` packages.
126
127Other dependencies can be built together with MicroPython. This may
128be required to enable extra features or capabilities, and in recent
129versions of MicroPython, these may be enabled by default. To build
130these additional dependencies, in the port directory you're
131interested in (e.g. `ports/unix/`) first execute:
132
133    $ make submodules
134
135This will fetch all the relevant git submodules (sub repositories) that
136the port needs.  Use the same command to get the latest versions of
137submodules as they are updated from time to time. After that execute:
138
139    $ make deplibs
140
141This will build all available dependencies (regardless whether they
142are used or not). If you intend to build MicroPython with additional
143options (like cross-compiling), the same set of options should be passed
144to `make deplibs`. To actually enable/disable use of dependencies, edit
145`ports/unix/mpconfigport.mk` file, which has inline descriptions of the options.
146For example, to build SSL module (required for `upip` tool described above,
147and so enabled by default), `MICROPY_PY_USSL` should be set to 1.
148
149For some ports, building required dependences is transparent, and happens
150automatically.  But they still need to be fetched with the `make submodules`
151command.
152
153The STM32 version
154-----------------
155
156The "stm32" port requires an ARM compiler, arm-none-eabi-gcc, and associated
157bin-utils.  For those using Arch Linux, you need arm-none-eabi-binutils,
158arm-none-eabi-gcc and arm-none-eabi-newlib packages.  Otherwise, try here:
159https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm
160
161To build:
162
163    $ cd ports/stm32
164    $ make submodules
165    $ make
166
167You then need to get your board into DFU mode.  On the pyboard, connect the
1683V3 pin to the P1/DFU pin with a wire (on PYBv1.0 they are next to each other
169on the bottom left of the board, second row from the bottom).
170
171Then to flash the code via USB DFU to your device:
172
173    $ make deploy
174
175This will use the included `tools/pydfu.py` script.  If flashing the firmware
176does not work it may be because you don't have the correct permissions, and
177need to use `sudo make deploy`.
178See the README.md file in the ports/stm32/ directory for further details.
179
180Contributing
181------------
182
183MicroPython is an open-source project and welcomes contributions. To be
184productive, please be sure to follow the
185[Contributors' Guidelines](https://github.com/micropython/micropython/wiki/ContributorGuidelines)
186and the [Code Conventions](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md).
187Note that MicroPython is licenced under the MIT license, and all contributions
188should follow this license.
189