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 /*
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) 2014 Fabian Vogt
pythontech 0:5868e8752d44 7 * Copyright (c) 2013, 2014 Damien P. George
pythontech 0:5868e8752d44 8 *
pythontech 0:5868e8752d44 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
pythontech 0:5868e8752d44 10 * of this software and associated documentation files (the "Software"), to deal
pythontech 0:5868e8752d44 11 * in the Software without restriction, including without limitation the rights
pythontech 0:5868e8752d44 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pythontech 0:5868e8752d44 13 * copies of the Software, and to permit persons to whom the Software is
pythontech 0:5868e8752d44 14 * furnished to do so, subject to the following conditions:
pythontech 0:5868e8752d44 15 *
pythontech 0:5868e8752d44 16 * The above copyright notice and this permission notice shall be included in
pythontech 0:5868e8752d44 17 * all copies or substantial portions of the Software.
pythontech 0:5868e8752d44 18 *
pythontech 0:5868e8752d44 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pythontech 0:5868e8752d44 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pythontech 0:5868e8752d44 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pythontech 0:5868e8752d44 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pythontech 0:5868e8752d44 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pythontech 0:5868e8752d44 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pythontech 0:5868e8752d44 25 * THE SOFTWARE.
pythontech 0:5868e8752d44 26 */
pythontech 0:5868e8752d44 27 #ifndef __MICROPY_INCLUDED_PY_ASMARM_H__
pythontech 0:5868e8752d44 28 #define __MICROPY_INCLUDED_PY_ASMARM_H__
pythontech 0:5868e8752d44 29
pythontech 0:5868e8752d44 30 #include "py/misc.h"
pythontech 0:5868e8752d44 31
pythontech 0:5868e8752d44 32 #define ASM_ARM_PASS_COMPUTE (1)
pythontech 0:5868e8752d44 33 #define ASM_ARM_PASS_EMIT (2)
pythontech 0:5868e8752d44 34
pythontech 0:5868e8752d44 35 #define ASM_ARM_REG_R0 (0)
pythontech 0:5868e8752d44 36 #define ASM_ARM_REG_R1 (1)
pythontech 0:5868e8752d44 37 #define ASM_ARM_REG_R2 (2)
pythontech 0:5868e8752d44 38 #define ASM_ARM_REG_R3 (3)
pythontech 0:5868e8752d44 39 #define ASM_ARM_REG_R4 (4)
pythontech 0:5868e8752d44 40 #define ASM_ARM_REG_R5 (5)
pythontech 0:5868e8752d44 41 #define ASM_ARM_REG_R6 (6)
pythontech 0:5868e8752d44 42 #define ASM_ARM_REG_R7 (7)
pythontech 0:5868e8752d44 43 #define ASM_ARM_REG_R8 (8)
pythontech 0:5868e8752d44 44 #define ASM_ARM_REG_R9 (9)
pythontech 0:5868e8752d44 45 #define ASM_ARM_REG_R10 (10)
pythontech 0:5868e8752d44 46 #define ASM_ARM_REG_R11 (11)
pythontech 0:5868e8752d44 47 #define ASM_ARM_REG_R12 (12)
pythontech 0:5868e8752d44 48 #define ASM_ARM_REG_R13 (13)
pythontech 0:5868e8752d44 49 #define ASM_ARM_REG_R14 (14)
pythontech 0:5868e8752d44 50 #define ASM_ARM_REG_R15 (15)
pythontech 0:5868e8752d44 51 #define ASM_ARM_REG_SP (ASM_ARM_REG_R13)
pythontech 0:5868e8752d44 52 #define ASM_ARM_REG_LR (ASM_ARM_REG_R14)
pythontech 0:5868e8752d44 53 #define ASM_ARM_REG_PC (ASM_ARM_REG_R15)
pythontech 0:5868e8752d44 54
pythontech 0:5868e8752d44 55 #define ASM_ARM_CC_EQ (0x0 << 28)
pythontech 0:5868e8752d44 56 #define ASM_ARM_CC_NE (0x1 << 28)
pythontech 0:5868e8752d44 57 #define ASM_ARM_CC_CS (0x2 << 28)
pythontech 0:5868e8752d44 58 #define ASM_ARM_CC_CC (0x3 << 28)
pythontech 0:5868e8752d44 59 #define ASM_ARM_CC_MI (0x4 << 28)
pythontech 0:5868e8752d44 60 #define ASM_ARM_CC_PL (0x5 << 28)
pythontech 0:5868e8752d44 61 #define ASM_ARM_CC_VS (0x6 << 28)
pythontech 0:5868e8752d44 62 #define ASM_ARM_CC_VC (0x7 << 28)
pythontech 0:5868e8752d44 63 #define ASM_ARM_CC_HI (0x8 << 28)
pythontech 0:5868e8752d44 64 #define ASM_ARM_CC_LS (0x9 << 28)
pythontech 0:5868e8752d44 65 #define ASM_ARM_CC_GE (0xa << 28)
pythontech 0:5868e8752d44 66 #define ASM_ARM_CC_LT (0xb << 28)
pythontech 0:5868e8752d44 67 #define ASM_ARM_CC_GT (0xc << 28)
pythontech 0:5868e8752d44 68 #define ASM_ARM_CC_LE (0xd << 28)
pythontech 0:5868e8752d44 69 #define ASM_ARM_CC_AL (0xe << 28)
pythontech 0:5868e8752d44 70
pythontech 0:5868e8752d44 71 typedef struct _asm_arm_t asm_arm_t;
pythontech 0:5868e8752d44 72
pythontech 0:5868e8752d44 73 asm_arm_t *asm_arm_new(uint max_num_labels);
pythontech 0:5868e8752d44 74 void asm_arm_free(asm_arm_t *as, bool free_code);
pythontech 0:5868e8752d44 75 void asm_arm_start_pass(asm_arm_t *as, uint pass);
pythontech 0:5868e8752d44 76 void asm_arm_end_pass(asm_arm_t *as);
pythontech 0:5868e8752d44 77 uint asm_arm_get_code_pos(asm_arm_t *as);
pythontech 0:5868e8752d44 78 uint asm_arm_get_code_size(asm_arm_t *as);
pythontech 0:5868e8752d44 79 void *asm_arm_get_code(asm_arm_t *as);
pythontech 0:5868e8752d44 80
pythontech 0:5868e8752d44 81 void asm_arm_entry(asm_arm_t *as, int num_locals);
pythontech 0:5868e8752d44 82 void asm_arm_exit(asm_arm_t *as);
pythontech 0:5868e8752d44 83 void asm_arm_label_assign(asm_arm_t *as, uint label);
pythontech 0:5868e8752d44 84
pythontech 0:5868e8752d44 85 void asm_arm_align(asm_arm_t* as, uint align);
pythontech 0:5868e8752d44 86 void asm_arm_data(asm_arm_t* as, uint bytesize, uint val);
pythontech 0:5868e8752d44 87
pythontech 0:5868e8752d44 88 void asm_arm_bkpt(asm_arm_t *as);
pythontech 0:5868e8752d44 89
pythontech 0:5868e8752d44 90 // mov
pythontech 0:5868e8752d44 91 void asm_arm_mov_reg_reg(asm_arm_t *as, uint reg_dest, uint reg_src);
pythontech 0:5868e8752d44 92 void asm_arm_mov_reg_i32(asm_arm_t *as, uint rd, int imm);
pythontech 0:5868e8752d44 93 void asm_arm_mov_local_reg(asm_arm_t *as, int local_num, uint rd);
pythontech 0:5868e8752d44 94 void asm_arm_mov_reg_local(asm_arm_t *as, uint rd, int local_num);
pythontech 0:5868e8752d44 95 void asm_arm_setcc_reg(asm_arm_t *as, uint rd, uint cond);
pythontech 0:5868e8752d44 96
pythontech 0:5868e8752d44 97 // compare
pythontech 0:5868e8752d44 98 void asm_arm_cmp_reg_i8(asm_arm_t *as, uint rd, int imm);
pythontech 0:5868e8752d44 99 void asm_arm_cmp_reg_reg(asm_arm_t *as, uint rd, uint rn);
pythontech 0:5868e8752d44 100
pythontech 0:5868e8752d44 101 // arithmetic
pythontech 0:5868e8752d44 102 void asm_arm_add_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
pythontech 0:5868e8752d44 103 void asm_arm_sub_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
pythontech 0:5868e8752d44 104 void asm_arm_mul_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
pythontech 0:5868e8752d44 105 void asm_arm_and_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
pythontech 0:5868e8752d44 106 void asm_arm_eor_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
pythontech 0:5868e8752d44 107 void asm_arm_orr_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm);
pythontech 0:5868e8752d44 108 void asm_arm_mov_reg_local_addr(asm_arm_t *as, uint rd, int local_num);
pythontech 0:5868e8752d44 109 void asm_arm_lsl_reg_reg(asm_arm_t *as, uint rd, uint rs);
pythontech 0:5868e8752d44 110 void asm_arm_asr_reg_reg(asm_arm_t *as, uint rd, uint rs);
pythontech 0:5868e8752d44 111
pythontech 0:5868e8752d44 112 // memory
pythontech 0:5868e8752d44 113 void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn, uint byte_offset);
pythontech 0:5868e8752d44 114 void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn);
pythontech 0:5868e8752d44 115 void asm_arm_ldrb_reg_reg(asm_arm_t *as, uint rd, uint rn);
pythontech 0:5868e8752d44 116 void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm, uint byte_offset);
pythontech 0:5868e8752d44 117 void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm);
pythontech 0:5868e8752d44 118 void asm_arm_strb_reg_reg(asm_arm_t *as, uint rd, uint rm);
pythontech 0:5868e8752d44 119 // store to array
pythontech 0:5868e8752d44 120 void asm_arm_str_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
pythontech 0:5868e8752d44 121 void asm_arm_strh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
pythontech 0:5868e8752d44 122 void asm_arm_strb_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
pythontech 0:5868e8752d44 123
pythontech 0:5868e8752d44 124 // stack
pythontech 0:5868e8752d44 125 void asm_arm_push(asm_arm_t *as, uint reglist);
pythontech 0:5868e8752d44 126 void asm_arm_pop(asm_arm_t *as, uint reglist);
pythontech 0:5868e8752d44 127
pythontech 0:5868e8752d44 128 // control flow
pythontech 0:5868e8752d44 129 void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label);
pythontech 0:5868e8752d44 130 void asm_arm_b_label(asm_arm_t *as, uint label);
pythontech 0:5868e8752d44 131 void asm_arm_bl_ind(asm_arm_t *as, void *fun_ptr, uint fun_id, uint reg_temp);
pythontech 0:5868e8752d44 132
pythontech 0:5868e8752d44 133 #endif // __MICROPY_INCLUDED_PY_ASMARM_H__