Port of MicroPython to the mbed platform. See micropython-repl for an interactive program.

Dependents:   micropython-repl

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.
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?

UserRevisionLine numberNew contents of line
pythontech 0:5868e8752d44 1 ifneq ($(lastword a b),b)
pythontech 0:5868e8752d44 2 $(error These Makefiles require make 3.81 or newer)
pythontech 0:5868e8752d44 3 endif
pythontech 0:5868e8752d44 4
pythontech 0:5868e8752d44 5 # Set TOP to be the path to get from the current directory (where make was
pythontech 0:5868e8752d44 6 # invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
pythontech 0:5868e8752d44 7 # the name of this makefile relative to where make was invoked.
pythontech 0:5868e8752d44 8 #
pythontech 0:5868e8752d44 9 # We assume that this file is in the py directory so we use $(dir ) twice
pythontech 0:5868e8752d44 10 # to get to the top of the tree.
pythontech 0:5868e8752d44 11
pythontech 0:5868e8752d44 12 THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
pythontech 0:5868e8752d44 13 TOP := $(patsubst %/py/mkenv.mk,%,$(THIS_MAKEFILE))
pythontech 0:5868e8752d44 14
pythontech 0:5868e8752d44 15 # Turn on increased build verbosity by defining BUILD_VERBOSE in your main
pythontech 0:5868e8752d44 16 # Makefile or in your environment. You can also use V=1 on the make command
pythontech 0:5868e8752d44 17 # line.
pythontech 0:5868e8752d44 18
pythontech 0:5868e8752d44 19 ifeq ("$(origin V)", "command line")
pythontech 0:5868e8752d44 20 BUILD_VERBOSE=$(V)
pythontech 0:5868e8752d44 21 endif
pythontech 0:5868e8752d44 22 ifndef BUILD_VERBOSE
pythontech 0:5868e8752d44 23 BUILD_VERBOSE = 0
pythontech 0:5868e8752d44 24 endif
pythontech 0:5868e8752d44 25 ifeq ($(BUILD_VERBOSE),0)
pythontech 0:5868e8752d44 26 Q = @
pythontech 0:5868e8752d44 27 else
pythontech 0:5868e8752d44 28 Q =
pythontech 0:5868e8752d44 29 endif
pythontech 0:5868e8752d44 30 # Since this is a new feature, advertise it
pythontech 0:5868e8752d44 31 ifeq ($(BUILD_VERBOSE),0)
pythontech 0:5868e8752d44 32 $(info Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.)
pythontech 0:5868e8752d44 33 endif
pythontech 0:5868e8752d44 34
pythontech 0:5868e8752d44 35 # default settings; can be overriden in main Makefile
pythontech 0:5868e8752d44 36
pythontech 0:5868e8752d44 37 PY_SRC ?= $(TOP)/py
pythontech 0:5868e8752d44 38 BUILD ?= build
pythontech 0:5868e8752d44 39
pythontech 0:5868e8752d44 40 RM = rm
pythontech 0:5868e8752d44 41 ECHO = @echo
pythontech 0:5868e8752d44 42 CP = cp
pythontech 0:5868e8752d44 43 MKDIR = mkdir
pythontech 0:5868e8752d44 44 SED = sed
pythontech 0:5868e8752d44 45 PYTHON = python
pythontech 0:5868e8752d44 46
pythontech 0:5868e8752d44 47 AS = $(CROSS_COMPILE)as
pythontech 0:5868e8752d44 48 CC = $(CROSS_COMPILE)gcc
pythontech 0:5868e8752d44 49 CXX = $(CROSS_COMPILE)g++
pythontech 0:5868e8752d44 50 LD = $(CROSS_COMPILE)ld
pythontech 0:5868e8752d44 51 OBJCOPY = $(CROSS_COMPILE)objcopy
pythontech 0:5868e8752d44 52 SIZE = $(CROSS_COMPILE)size
pythontech 0:5868e8752d44 53 STRIP = $(CROSS_COMPILE)strip
pythontech 0:5868e8752d44 54 AR = $(CROSS_COMPILE)ar
pythontech 0:5868e8752d44 55 ifeq ($(MICROPY_FORCE_32BIT),1)
pythontech 0:5868e8752d44 56 CC += -m32
pythontech 0:5868e8752d44 57 CXX += -m32
pythontech 0:5868e8752d44 58 LD += -m32
pythontech 0:5868e8752d44 59 endif
pythontech 0:5868e8752d44 60
pythontech 0:5868e8752d44 61 all:
pythontech 0:5868e8752d44 62 .PHONY: all
pythontech 0:5868e8752d44 63
pythontech 0:5868e8752d44 64 .DELETE_ON_ERROR:
pythontech 0:5868e8752d44 65
pythontech 0:5868e8752d44 66 MKENV_INCLUDED = 1