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:
pythontech
Date:
Sat Apr 16 17:11:56 2016 +0000
Revision:
0:5868e8752d44
Split off library from repl

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pythontech 0:5868e8752d44 1 /*
pythontech 0:5868e8752d44 2 * This file is part of the Micro Python project, http://micropython.org/
pythontech 0:5868e8752d44 3 *
pythontech 0:5868e8752d44 4 * The MIT License (MIT)
pythontech 0:5868e8752d44 5 *
pythontech 0:5868e8752d44 6 * Copyright (c) 2013, 2014 Damien P. George
pythontech 0:5868e8752d44 7 *
pythontech 0:5868e8752d44 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
pythontech 0:5868e8752d44 9 * of this software and associated documentation files (the "Software"), to deal
pythontech 0:5868e8752d44 10 * in the Software without restriction, including without limitation the rights
pythontech 0:5868e8752d44 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pythontech 0:5868e8752d44 12 * copies of the Software, and to permit persons to whom the Software is
pythontech 0:5868e8752d44 13 * furnished to do so, subject to the following conditions:
pythontech 0:5868e8752d44 14 *
pythontech 0:5868e8752d44 15 * The above copyright notice and this permission notice shall be included in
pythontech 0:5868e8752d44 16 * all copies or substantial portions of the Software.
pythontech 0:5868e8752d44 17 *
pythontech 0:5868e8752d44 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pythontech 0:5868e8752d44 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pythontech 0:5868e8752d44 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pythontech 0:5868e8752d44 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pythontech 0:5868e8752d44 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pythontech 0:5868e8752d44 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pythontech 0:5868e8752d44 24 * THE SOFTWARE.
pythontech 0:5868e8752d44 25 */
pythontech 0:5868e8752d44 26 #ifndef __MICROPY_INCLUDED_PY_BC0_H__
pythontech 0:5868e8752d44 27 #define __MICROPY_INCLUDED_PY_BC0_H__
pythontech 0:5868e8752d44 28
pythontech 0:5868e8752d44 29 // Micro Python byte-codes.
pythontech 0:5868e8752d44 30 // The comment at the end of the line (if it exists) tells the arguments to the byte-code.
pythontech 0:5868e8752d44 31
pythontech 0:5868e8752d44 32 #define MP_BC_LOAD_CONST_FALSE (0x10)
pythontech 0:5868e8752d44 33 #define MP_BC_LOAD_CONST_NONE (0x11)
pythontech 0:5868e8752d44 34 #define MP_BC_LOAD_CONST_TRUE (0x12)
pythontech 0:5868e8752d44 35 #define MP_BC_LOAD_CONST_SMALL_INT (0x14) // signed var-int
pythontech 0:5868e8752d44 36 #define MP_BC_LOAD_CONST_STRING (0x16) // qstr
pythontech 0:5868e8752d44 37 #define MP_BC_LOAD_CONST_OBJ (0x17) // ptr
pythontech 0:5868e8752d44 38 #define MP_BC_LOAD_NULL (0x18)
pythontech 0:5868e8752d44 39
pythontech 0:5868e8752d44 40 #define MP_BC_LOAD_FAST_N (0x1a) // uint
pythontech 0:5868e8752d44 41 #define MP_BC_LOAD_DEREF (0x1b) // uint
pythontech 0:5868e8752d44 42 #define MP_BC_LOAD_NAME (0x1c) // qstr
pythontech 0:5868e8752d44 43 #define MP_BC_LOAD_GLOBAL (0x1d) // qstr
pythontech 0:5868e8752d44 44 #define MP_BC_LOAD_ATTR (0x1e) // qstr
pythontech 0:5868e8752d44 45 #define MP_BC_LOAD_METHOD (0x1f) // qstr
pythontech 0:5868e8752d44 46 #define MP_BC_LOAD_BUILD_CLASS (0x20)
pythontech 0:5868e8752d44 47 #define MP_BC_LOAD_SUBSCR (0x21)
pythontech 0:5868e8752d44 48
pythontech 0:5868e8752d44 49 #define MP_BC_STORE_FAST_N (0x22) // uint
pythontech 0:5868e8752d44 50 #define MP_BC_STORE_DEREF (0x23) // uint
pythontech 0:5868e8752d44 51 #define MP_BC_STORE_NAME (0x24) // qstr
pythontech 0:5868e8752d44 52 #define MP_BC_STORE_GLOBAL (0x25) // qstr
pythontech 0:5868e8752d44 53 #define MP_BC_STORE_ATTR (0x26) // qstr
pythontech 0:5868e8752d44 54 #define MP_BC_STORE_SUBSCR (0x27)
pythontech 0:5868e8752d44 55
pythontech 0:5868e8752d44 56 #define MP_BC_DELETE_FAST (0x28) // uint
pythontech 0:5868e8752d44 57 #define MP_BC_DELETE_DEREF (0x29) // uint
pythontech 0:5868e8752d44 58 #define MP_BC_DELETE_NAME (0x2a) // qstr
pythontech 0:5868e8752d44 59 #define MP_BC_DELETE_GLOBAL (0x2b) // qstr
pythontech 0:5868e8752d44 60
pythontech 0:5868e8752d44 61 #define MP_BC_DUP_TOP (0x30)
pythontech 0:5868e8752d44 62 #define MP_BC_DUP_TOP_TWO (0x31)
pythontech 0:5868e8752d44 63 #define MP_BC_POP_TOP (0x32)
pythontech 0:5868e8752d44 64 #define MP_BC_ROT_TWO (0x33)
pythontech 0:5868e8752d44 65 #define MP_BC_ROT_THREE (0x34)
pythontech 0:5868e8752d44 66
pythontech 0:5868e8752d44 67 #define MP_BC_JUMP (0x35) // rel byte code offset, 16-bit signed, in excess
pythontech 0:5868e8752d44 68 #define MP_BC_POP_JUMP_IF_TRUE (0x36) // rel byte code offset, 16-bit signed, in excess
pythontech 0:5868e8752d44 69 #define MP_BC_POP_JUMP_IF_FALSE (0x37) // rel byte code offset, 16-bit signed, in excess
pythontech 0:5868e8752d44 70 #define MP_BC_JUMP_IF_TRUE_OR_POP (0x38) // rel byte code offset, 16-bit signed, in excess
pythontech 0:5868e8752d44 71 #define MP_BC_JUMP_IF_FALSE_OR_POP (0x39) // rel byte code offset, 16-bit signed, in excess
pythontech 0:5868e8752d44 72 #define MP_BC_SETUP_WITH (0x3d) // rel byte code offset, 16-bit unsigned
pythontech 0:5868e8752d44 73 #define MP_BC_WITH_CLEANUP (0x3e)
pythontech 0:5868e8752d44 74 #define MP_BC_SETUP_EXCEPT (0x3f) // rel byte code offset, 16-bit unsigned
pythontech 0:5868e8752d44 75 #define MP_BC_SETUP_FINALLY (0x40) // rel byte code offset, 16-bit unsigned
pythontech 0:5868e8752d44 76 #define MP_BC_END_FINALLY (0x41)
pythontech 0:5868e8752d44 77 #define MP_BC_GET_ITER (0x42)
pythontech 0:5868e8752d44 78 #define MP_BC_FOR_ITER (0x43) // rel byte code offset, 16-bit unsigned
pythontech 0:5868e8752d44 79 #define MP_BC_POP_BLOCK (0x44)
pythontech 0:5868e8752d44 80 #define MP_BC_POP_EXCEPT (0x45)
pythontech 0:5868e8752d44 81 #define MP_BC_UNWIND_JUMP (0x46) // rel byte code offset, 16-bit signed, in excess; then a byte
pythontech 0:5868e8752d44 82
pythontech 0:5868e8752d44 83 #define MP_BC_BUILD_TUPLE (0x50) // uint
pythontech 0:5868e8752d44 84 #define MP_BC_BUILD_LIST (0x51) // uint
pythontech 0:5868e8752d44 85 #define MP_BC_LIST_APPEND (0x52) // uint
pythontech 0:5868e8752d44 86 #define MP_BC_BUILD_MAP (0x53) // uint
pythontech 0:5868e8752d44 87 #define MP_BC_STORE_MAP (0x54)
pythontech 0:5868e8752d44 88 #define MP_BC_MAP_ADD (0x55) // uint
pythontech 0:5868e8752d44 89 #define MP_BC_BUILD_SET (0x56) // uint
pythontech 0:5868e8752d44 90 #define MP_BC_SET_ADD (0x57) // uint
pythontech 0:5868e8752d44 91 #define MP_BC_BUILD_SLICE (0x58) // uint
pythontech 0:5868e8752d44 92 #define MP_BC_UNPACK_SEQUENCE (0x59) // uint
pythontech 0:5868e8752d44 93 #define MP_BC_UNPACK_EX (0x5a) // uint
pythontech 0:5868e8752d44 94
pythontech 0:5868e8752d44 95 #define MP_BC_RETURN_VALUE (0x5b)
pythontech 0:5868e8752d44 96 #define MP_BC_RAISE_VARARGS (0x5c) // byte
pythontech 0:5868e8752d44 97 #define MP_BC_YIELD_VALUE (0x5d)
pythontech 0:5868e8752d44 98 #define MP_BC_YIELD_FROM (0x5e)
pythontech 0:5868e8752d44 99
pythontech 0:5868e8752d44 100 #define MP_BC_MAKE_FUNCTION (0x60) // uint
pythontech 0:5868e8752d44 101 #define MP_BC_MAKE_FUNCTION_DEFARGS (0x61) // uint
pythontech 0:5868e8752d44 102 #define MP_BC_MAKE_CLOSURE (0x62) // uint
pythontech 0:5868e8752d44 103 #define MP_BC_MAKE_CLOSURE_DEFARGS (0x63) // uint
pythontech 0:5868e8752d44 104 #define MP_BC_CALL_FUNCTION (0x64) // uint
pythontech 0:5868e8752d44 105 #define MP_BC_CALL_FUNCTION_VAR_KW (0x65) // uint
pythontech 0:5868e8752d44 106 #define MP_BC_CALL_METHOD (0x66) // uint
pythontech 0:5868e8752d44 107 #define MP_BC_CALL_METHOD_VAR_KW (0x67) // uint
pythontech 0:5868e8752d44 108
pythontech 0:5868e8752d44 109 #define MP_BC_IMPORT_NAME (0x68) // qstr
pythontech 0:5868e8752d44 110 #define MP_BC_IMPORT_FROM (0x69) // qstr
pythontech 0:5868e8752d44 111 #define MP_BC_IMPORT_STAR (0x6a)
pythontech 0:5868e8752d44 112
pythontech 0:5868e8752d44 113 #define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64)
pythontech 0:5868e8752d44 114 #define MP_BC_LOAD_FAST_MULTI (0xb0) // + N(16)
pythontech 0:5868e8752d44 115 #define MP_BC_STORE_FAST_MULTI (0xc0) // + N(16)
pythontech 0:5868e8752d44 116 #define MP_BC_UNARY_OP_MULTI (0xd0) // + op(7)
pythontech 0:5868e8752d44 117 #define MP_BC_BINARY_OP_MULTI (0xd7) // + op(36)
pythontech 0:5868e8752d44 118
pythontech 0:5868e8752d44 119 #endif // __MICROPY_INCLUDED_PY_BC0_H__