Port of MicroPython to the mbed platform. See micropython-repl for an interactive program.
This a port of MicroPython to the mbed Classic platform.
This provides an interpreter running on the board's USB serial connection.
Getting Started
Import the micropython-repl program into your IDE workspace on developer.mbed.org. Compile and download to your board. Connect to the USB serial port in your usual manner. You should get a startup message similar to the following:
MicroPython v1.7-155-gdddcdd8 on 2016-04-23; K64F with ARM Type "help()" for more information. >>>
Then you can start using micropython. For example:
>>> from mbed import DigitalOut >>> from pins import LED1 >>> led = DigitalOut(LED1) >>> led.write(1)
Requirements
You need approximately 100K of flash memory, so this will be no good for boards with smaller amounts of storage.
Caveats
This can be considered an alpha release of the port; things may not work; APIs may change in later releases. It is NOT an official part part the micropython project, so if anything doesn't work, blame me. If it does work, most of the credit is due to micropython.
- Only a few of the mbed classes are available in micropython so far, and not all methods of those that are.
- Only a few boards have their full range of pin names available; for others, only a few standard ones (USBTX, USBRX, LED1) are implemented.
- The garbage collector is not yet implemented. The interpreter will gradually consume memory and then fail.
- Exceptions from the mbed classes are not yet handled.
- Asynchronous processing (e.g. events on inputs) is not supported.
Credits
- Damien P. George and other contributors who created micropython.
- Colin Hogben, author of this port.
py/mkrules.mk@10:33521d742af1, 2016-04-27 (annotated)
- Committer:
- Colin Hogben
- Date:
- Wed Apr 27 22:11:29 2016 +0100
- Revision:
- 10:33521d742af1
- Parent:
- 0:5868e8752d44
Update README and version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pythontech | 0:5868e8752d44 | 1 | ifneq ($(MKENV_INCLUDED),1) |
pythontech | 0:5868e8752d44 | 2 | # We assume that mkenv is in the same directory as this file. |
pythontech | 0:5868e8752d44 | 3 | THIS_MAKEFILE = $(lastword $(MAKEFILE_LIST)) |
pythontech | 0:5868e8752d44 | 4 | include $(dir $(THIS_MAKEFILE))mkenv.mk |
pythontech | 0:5868e8752d44 | 5 | endif |
pythontech | 0:5868e8752d44 | 6 | |
pythontech | 0:5868e8752d44 | 7 | # This file expects that OBJ contains a list of all of the object files. |
pythontech | 0:5868e8752d44 | 8 | # The directory portion of each object file is used to locate the source |
pythontech | 0:5868e8752d44 | 9 | # and should not contain any ..'s but rather be relative to the top of the |
pythontech | 0:5868e8752d44 | 10 | # tree. |
pythontech | 0:5868e8752d44 | 11 | # |
pythontech | 0:5868e8752d44 | 12 | # So for example, py/map.c would have an object file name py/map.o |
pythontech | 0:5868e8752d44 | 13 | # The object files will go into the build directory and mantain the same |
pythontech | 0:5868e8752d44 | 14 | # directory structure as the source tree. So the final dependency will look |
pythontech | 0:5868e8752d44 | 15 | # like this: |
pythontech | 0:5868e8752d44 | 16 | # |
pythontech | 0:5868e8752d44 | 17 | # build/py/map.o: py/map.c |
pythontech | 0:5868e8752d44 | 18 | # |
pythontech | 0:5868e8752d44 | 19 | # We set vpath to point to the top of the tree so that the source files |
pythontech | 0:5868e8752d44 | 20 | # can be located. By following this scheme, it allows a single build rule |
pythontech | 0:5868e8752d44 | 21 | # to be used to compile all .c files. |
pythontech | 0:5868e8752d44 | 22 | |
pythontech | 0:5868e8752d44 | 23 | vpath %.S . $(TOP) |
pythontech | 0:5868e8752d44 | 24 | $(BUILD)/%.o: %.S |
pythontech | 0:5868e8752d44 | 25 | $(ECHO) "CC $<" |
pythontech | 0:5868e8752d44 | 26 | $(Q)$(CC) $(CFLAGS) -c -o $@ $< |
pythontech | 0:5868e8752d44 | 27 | |
pythontech | 0:5868e8752d44 | 28 | vpath %.s . $(TOP) |
pythontech | 0:5868e8752d44 | 29 | $(BUILD)/%.o: %.s |
pythontech | 0:5868e8752d44 | 30 | $(ECHO) "AS $<" |
pythontech | 0:5868e8752d44 | 31 | $(Q)$(AS) -o $@ $< |
pythontech | 0:5868e8752d44 | 32 | |
pythontech | 0:5868e8752d44 | 33 | define compile_c |
pythontech | 0:5868e8752d44 | 34 | $(ECHO) "CC $<" |
pythontech | 0:5868e8752d44 | 35 | $(Q)$(CC) $(CFLAGS) -c -MD -o $@ $< |
pythontech | 0:5868e8752d44 | 36 | @# The following fixes the dependency file. |
pythontech | 0:5868e8752d44 | 37 | @# See http://make.paulandlesley.org/autodep.html for details. |
pythontech | 0:5868e8752d44 | 38 | @# Regex adjusted from the above to play better with Windows paths, etc. |
pythontech | 0:5868e8752d44 | 39 | @$(CP) $(@:.o=.d) $(@:.o=.P); \ |
pythontech | 0:5868e8752d44 | 40 | $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \ |
pythontech | 0:5868e8752d44 | 41 | -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \ |
pythontech | 0:5868e8752d44 | 42 | $(RM) -f $(@:.o=.d) |
pythontech | 0:5868e8752d44 | 43 | endef |
pythontech | 0:5868e8752d44 | 44 | |
pythontech | 0:5868e8752d44 | 45 | vpath %.c . $(TOP) |
pythontech | 0:5868e8752d44 | 46 | $(BUILD)/%.o: %.c |
pythontech | 0:5868e8752d44 | 47 | $(call compile_c) |
pythontech | 0:5868e8752d44 | 48 | |
pythontech | 0:5868e8752d44 | 49 | $(BUILD)/%.pp: %.c |
pythontech | 0:5868e8752d44 | 50 | $(ECHO) "PreProcess $<" |
pythontech | 0:5868e8752d44 | 51 | $(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $< |
pythontech | 0:5868e8752d44 | 52 | |
pythontech | 0:5868e8752d44 | 53 | # The following rule uses | to create an order only prereuisite. Order only |
pythontech | 0:5868e8752d44 | 54 | # prerequisites only get built if they don't exist. They don't cause timestamp |
pythontech | 0:5868e8752d44 | 55 | # checking to be performed. |
pythontech | 0:5868e8752d44 | 56 | # |
pythontech | 0:5868e8752d44 | 57 | # We don't know which source files actually need the generated.h (since |
pythontech | 0:5868e8752d44 | 58 | # it is #included from str.h). The compiler generated dependencies will cause |
pythontech | 0:5868e8752d44 | 59 | # the right .o's to get recompiled if the generated.h file changes. Adding |
pythontech | 0:5868e8752d44 | 60 | # an order-only dependendency to all of the .o's will cause the generated .h |
pythontech | 0:5868e8752d44 | 61 | # to get built before we try to compile any of them. |
pythontech | 0:5868e8752d44 | 62 | $(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/mpversion.h |
pythontech | 0:5868e8752d44 | 63 | |
pythontech | 0:5868e8752d44 | 64 | # $(sort $(var)) removes duplicates |
pythontech | 0:5868e8752d44 | 65 | # |
pythontech | 0:5868e8752d44 | 66 | # The net effect of this, is it causes the objects to depend on the |
pythontech | 0:5868e8752d44 | 67 | # object directories (but only for existence), and the object directories |
pythontech | 0:5868e8752d44 | 68 | # will be created if they don't exist. |
pythontech | 0:5868e8752d44 | 69 | OBJ_DIRS = $(sort $(dir $(OBJ))) |
pythontech | 0:5868e8752d44 | 70 | $(OBJ): | $(OBJ_DIRS) |
pythontech | 0:5868e8752d44 | 71 | $(OBJ_DIRS): |
pythontech | 0:5868e8752d44 | 72 | $(MKDIR) -p $@ |
pythontech | 0:5868e8752d44 | 73 | |
pythontech | 0:5868e8752d44 | 74 | $(HEADER_BUILD): |
pythontech | 0:5868e8752d44 | 75 | $(MKDIR) -p $@ |
pythontech | 0:5868e8752d44 | 76 | |
pythontech | 0:5868e8752d44 | 77 | ifneq ($(PROG),) |
pythontech | 0:5868e8752d44 | 78 | # Build a standalone executable (unix does this) |
pythontech | 0:5868e8752d44 | 79 | |
pythontech | 0:5868e8752d44 | 80 | all: $(PROG) |
pythontech | 0:5868e8752d44 | 81 | |
pythontech | 0:5868e8752d44 | 82 | $(PROG): $(OBJ) |
pythontech | 0:5868e8752d44 | 83 | $(ECHO) "LINK $@" |
pythontech | 0:5868e8752d44 | 84 | # Do not pass COPT here - it's *C* compiler optimizations. For example, |
pythontech | 0:5868e8752d44 | 85 | # we may want to compile using Thumb, but link with non-Thumb libc. |
pythontech | 0:5868e8752d44 | 86 | $(Q)$(CC) -o $@ $^ $(LIB) $(LDFLAGS) |
pythontech | 0:5868e8752d44 | 87 | ifndef DEBUG |
pythontech | 0:5868e8752d44 | 88 | $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG) |
pythontech | 0:5868e8752d44 | 89 | endif |
pythontech | 0:5868e8752d44 | 90 | $(Q)$(SIZE) $(PROG) |
pythontech | 0:5868e8752d44 | 91 | |
pythontech | 0:5868e8752d44 | 92 | lib: $(OBJ) |
pythontech | 0:5868e8752d44 | 93 | $(AR) rcs libmicropython.a $^ |
pythontech | 0:5868e8752d44 | 94 | |
pythontech | 0:5868e8752d44 | 95 | clean: clean-prog |
pythontech | 0:5868e8752d44 | 96 | clean-prog: |
pythontech | 0:5868e8752d44 | 97 | $(RM) -f $(PROG) |
pythontech | 0:5868e8752d44 | 98 | $(RM) -f $(PROG).map |
pythontech | 0:5868e8752d44 | 99 | |
pythontech | 0:5868e8752d44 | 100 | .PHONY: clean-prog |
pythontech | 0:5868e8752d44 | 101 | endif |
pythontech | 0:5868e8752d44 | 102 | |
pythontech | 0:5868e8752d44 | 103 | clean: |
pythontech | 0:5868e8752d44 | 104 | $(RM) -rf $(BUILD) |
pythontech | 0:5868e8752d44 | 105 | .PHONY: clean |
pythontech | 0:5868e8752d44 | 106 | |
pythontech | 0:5868e8752d44 | 107 | print-cfg: |
pythontech | 0:5868e8752d44 | 108 | $(ECHO) "PY_SRC = $(PY_SRC)" |
pythontech | 0:5868e8752d44 | 109 | $(ECHO) "BUILD = $(BUILD)" |
pythontech | 0:5868e8752d44 | 110 | $(ECHO) "OBJ = $(OBJ)" |
pythontech | 0:5868e8752d44 | 111 | .PHONY: print-cfg |
pythontech | 0:5868e8752d44 | 112 | |
pythontech | 0:5868e8752d44 | 113 | print-def: |
pythontech | 0:5868e8752d44 | 114 | @$(ECHO) "The following defines are built into the $(CC) compiler" |
pythontech | 0:5868e8752d44 | 115 | touch __empty__.c |
pythontech | 0:5868e8752d44 | 116 | @$(CC) -E -Wp,-dM __empty__.c |
pythontech | 0:5868e8752d44 | 117 | @$(RM) -f __empty__.c |
pythontech | 0:5868e8752d44 | 118 | |
pythontech | 0:5868e8752d44 | 119 | -include $(OBJ:.o=.P) |