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_ASMX64_H__
pythontech 0:5868e8752d44 27 #define __MICROPY_INCLUDED_PY_ASMX64_H__
pythontech 0:5868e8752d44 28
pythontech 0:5868e8752d44 29 #include "py/mpconfig.h"
pythontech 0:5868e8752d44 30 #include "py/misc.h"
pythontech 0:5868e8752d44 31
pythontech 0:5868e8752d44 32 // AMD64 calling convention is:
pythontech 0:5868e8752d44 33 // - args pass in: RDI, RSI, RDX, RCX, R08, R09
pythontech 0:5868e8752d44 34 // - return value in RAX
pythontech 0:5868e8752d44 35 // - stack must be aligned on a 16-byte boundary before all calls
pythontech 0:5868e8752d44 36 // - RAX, RCX, RDX, RSI, RDI, R08, R09, R10, R11 are caller-save
pythontech 0:5868e8752d44 37 // - RBX, RBP, R12, R13, R14, R15 are callee-save
pythontech 0:5868e8752d44 38
pythontech 0:5868e8752d44 39 // In the functions below, argument order follows x86 docs and generally
pythontech 0:5868e8752d44 40 // the destination is the first argument.
pythontech 0:5868e8752d44 41 // NOTE: this is a change from the old convention used in this file and
pythontech 0:5868e8752d44 42 // some functions still use the old (reverse) convention.
pythontech 0:5868e8752d44 43
pythontech 0:5868e8752d44 44 #define ASM_X64_PASS_COMPUTE (1)
pythontech 0:5868e8752d44 45 #define ASM_X64_PASS_EMIT (2)
pythontech 0:5868e8752d44 46
pythontech 0:5868e8752d44 47 #define ASM_X64_REG_RAX (0)
pythontech 0:5868e8752d44 48 #define ASM_X64_REG_RCX (1)
pythontech 0:5868e8752d44 49 #define ASM_X64_REG_RDX (2)
pythontech 0:5868e8752d44 50 #define ASM_X64_REG_RBX (3)
pythontech 0:5868e8752d44 51 #define ASM_X64_REG_RSP (4)
pythontech 0:5868e8752d44 52 #define ASM_X64_REG_RBP (5)
pythontech 0:5868e8752d44 53 #define ASM_X64_REG_RSI (6)
pythontech 0:5868e8752d44 54 #define ASM_X64_REG_RDI (7)
pythontech 0:5868e8752d44 55 #define ASM_X64_REG_R08 (8)
pythontech 0:5868e8752d44 56 #define ASM_X64_REG_R09 (9)
pythontech 0:5868e8752d44 57 #define ASM_X64_REG_R10 (10)
pythontech 0:5868e8752d44 58 #define ASM_X64_REG_R11 (11)
pythontech 0:5868e8752d44 59 #define ASM_X64_REG_R12 (12)
pythontech 0:5868e8752d44 60 #define ASM_X64_REG_R13 (13)
pythontech 0:5868e8752d44 61 #define ASM_X64_REG_R14 (14)
pythontech 0:5868e8752d44 62 #define ASM_X64_REG_R15 (15)
pythontech 0:5868e8752d44 63
pythontech 0:5868e8752d44 64 // condition codes, used for jcc and setcc (despite their j-name!)
pythontech 0:5868e8752d44 65 #define ASM_X64_CC_JB (0x2) // below, unsigned
pythontech 0:5868e8752d44 66 #define ASM_X64_CC_JZ (0x4)
pythontech 0:5868e8752d44 67 #define ASM_X64_CC_JE (0x4)
pythontech 0:5868e8752d44 68 #define ASM_X64_CC_JNZ (0x5)
pythontech 0:5868e8752d44 69 #define ASM_X64_CC_JNE (0x5)
pythontech 0:5868e8752d44 70 #define ASM_X64_CC_JL (0xc) // less, signed
pythontech 0:5868e8752d44 71 #define ASM_X64_CC_JGE (0xd) // greater or equal, signed
pythontech 0:5868e8752d44 72 #define ASM_X64_CC_JLE (0xe) // less or equal, signed
pythontech 0:5868e8752d44 73 #define ASM_X64_CC_JG (0xf) // greater, signed
pythontech 0:5868e8752d44 74
pythontech 0:5868e8752d44 75 typedef struct _asm_x64_t asm_x64_t;
pythontech 0:5868e8752d44 76
pythontech 0:5868e8752d44 77 asm_x64_t* asm_x64_new(mp_uint_t max_num_labels);
pythontech 0:5868e8752d44 78 void asm_x64_free(asm_x64_t* as, bool free_code);
pythontech 0:5868e8752d44 79 void asm_x64_start_pass(asm_x64_t *as, uint pass);
pythontech 0:5868e8752d44 80 void asm_x64_end_pass(asm_x64_t *as);
pythontech 0:5868e8752d44 81 mp_uint_t asm_x64_get_code_pos(asm_x64_t *as);
pythontech 0:5868e8752d44 82 mp_uint_t asm_x64_get_code_size(asm_x64_t* as);
pythontech 0:5868e8752d44 83 void* asm_x64_get_code(asm_x64_t* as);
pythontech 0:5868e8752d44 84
pythontech 0:5868e8752d44 85 void asm_x64_align(asm_x64_t *as, mp_uint_t align);
pythontech 0:5868e8752d44 86 void asm_x64_data(asm_x64_t *as, mp_uint_t bytesize, mp_uint_t val);
pythontech 0:5868e8752d44 87
pythontech 0:5868e8752d44 88 void asm_x64_nop(asm_x64_t* as);
pythontech 0:5868e8752d44 89 void asm_x64_push_r64(asm_x64_t* as, int src_r64);
pythontech 0:5868e8752d44 90 void asm_x64_pop_r64(asm_x64_t* as, int dest_r64);
pythontech 0:5868e8752d44 91 void asm_x64_mov_r64_r64(asm_x64_t* as, int dest_r64, int src_r64);
pythontech 0:5868e8752d44 92 void asm_x64_mov_i64_to_r64(asm_x64_t* as, int64_t src_i64, int dest_r64);
pythontech 0:5868e8752d44 93 void asm_x64_mov_i64_to_r64_optimised(asm_x64_t *as, int64_t src_i64, int dest_r64);
pythontech 0:5868e8752d44 94 void asm_x64_mov_i64_to_r64_aligned(asm_x64_t *as, int64_t src_i64, int dest_r64);
pythontech 0:5868e8752d44 95 void asm_x64_mov_r8_to_mem8(asm_x64_t *as, int src_r64, int dest_r64, int dest_disp);
pythontech 0:5868e8752d44 96 void asm_x64_mov_r16_to_mem16(asm_x64_t *as, int src_r64, int dest_r64, int dest_disp);
pythontech 0:5868e8752d44 97 void asm_x64_mov_r32_to_mem32(asm_x64_t *as, int src_r64, int dest_r64, int dest_disp);
pythontech 0:5868e8752d44 98 void asm_x64_mov_r64_to_mem64(asm_x64_t *as, int src_r64, int dest_r64, int dest_disp);
pythontech 0:5868e8752d44 99 void asm_x64_mov_mem8_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int dest_r64);
pythontech 0:5868e8752d44 100 void asm_x64_mov_mem16_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int dest_r64);
pythontech 0:5868e8752d44 101 void asm_x64_mov_mem32_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int dest_r64);
pythontech 0:5868e8752d44 102 void asm_x64_mov_mem64_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest_r64);
pythontech 0:5868e8752d44 103 void asm_x64_and_r64_r64(asm_x64_t *as, int dest_r64, int src_r64);
pythontech 0:5868e8752d44 104 void asm_x64_or_r64_r64(asm_x64_t *as, int dest_r64, int src_r64);
pythontech 0:5868e8752d44 105 void asm_x64_xor_r64_r64(asm_x64_t *as, int dest_r64, int src_r64);
pythontech 0:5868e8752d44 106 void asm_x64_shl_r64_cl(asm_x64_t* as, int dest_r64);
pythontech 0:5868e8752d44 107 void asm_x64_sar_r64_cl(asm_x64_t* as, int dest_r64);
pythontech 0:5868e8752d44 108 void asm_x64_add_r64_r64(asm_x64_t* as, int dest_r64, int src_r64);
pythontech 0:5868e8752d44 109 void asm_x64_sub_r64_r64(asm_x64_t* as, int dest_r64, int src_r64);
pythontech 0:5868e8752d44 110 void asm_x64_mul_r64_r64(asm_x64_t* as, int dest_r64, int src_r64);
pythontech 0:5868e8752d44 111 void asm_x64_cmp_r64_with_r64(asm_x64_t* as, int src_r64_a, int src_r64_b);
pythontech 0:5868e8752d44 112 void asm_x64_test_r8_with_r8(asm_x64_t* as, int src_r64_a, int src_r64_b);
pythontech 0:5868e8752d44 113 void asm_x64_setcc_r8(asm_x64_t* as, int jcc_type, int dest_r8);
pythontech 0:5868e8752d44 114 void asm_x64_label_assign(asm_x64_t* as, mp_uint_t label);
pythontech 0:5868e8752d44 115 void asm_x64_jmp_label(asm_x64_t* as, mp_uint_t label);
pythontech 0:5868e8752d44 116 void asm_x64_jcc_label(asm_x64_t* as, int jcc_type, mp_uint_t label);
pythontech 0:5868e8752d44 117 void asm_x64_entry(asm_x64_t* as, int num_locals);
pythontech 0:5868e8752d44 118 void asm_x64_exit(asm_x64_t* as);
pythontech 0:5868e8752d44 119 void asm_x64_mov_local_to_r64(asm_x64_t* as, int src_local_num, int dest_r64);
pythontech 0:5868e8752d44 120 void asm_x64_mov_r64_to_local(asm_x64_t* as, int src_r64, int dest_local_num);
pythontech 0:5868e8752d44 121 void asm_x64_mov_local_addr_to_r64(asm_x64_t* as, int local_num, int dest_r64);
pythontech 0:5868e8752d44 122 void asm_x64_call_ind(asm_x64_t* as, void* ptr, int temp_r32);
pythontech 0:5868e8752d44 123
pythontech 0:5868e8752d44 124 #endif // __MICROPY_INCLUDED_PY_ASMX64_H__