示例#1
0
def read_micropython():
    """Read the MicroPython runtime from the micro:bit flash.

    :return: String with Intel Hex format for the MicroPython runtime.
    """
    flash_data = programmer.read_flash(
        address=programmer.MICROPYTHON_START,
        count=programmer.MICROPYTHON_END - programmer.MICROPYTHON_START,
        decode_hex=False,
    )
    return _bytes_to_intel_hex(flash_data, offset=programmer.MICROPYTHON_START)
示例#2
0
def read_python_code():
    """Read the MicroPython user code from the micro:bit flash.

    :return: String with the MicroPython code.
    """
    flash_data = programmer.read_flash(
        address=programmer.PYTHON_CODE_START,
        count=(programmer.PYTHON_CODE_END - programmer.PYTHON_CODE_START),
    )
    py_code_hex = _bytes_to_intel_hex(flash_data,
                                      offset=programmer.PYTHON_CODE_START)
    try:
        python_code = extract_script(py_code_hex)
    except Exception as e:
        sys.stderr.write(format_exc(e))
        raise Exception("Could not decode the MicroPython code from flash")
    return python_code
示例#3
0
def read_flash_hex(decode_hex=False, **kwargs):
    """Read data from the flash memory and return as a hex string.

    Read as a number of bytes of the micro:bit flash from the given address.
    Can return it in Intel Hex format or a pretty formatted and decoded hex
    string.

    :param address: Integer indicating the start address to read.
    :param count: Integer indicating hoy many bytes to read.
    :param decode_hex: True selects nice decoded format, False selects Intel
            Hex format.
    :return: String with the hex formatted as indicated.
    """
    flash_data = programmer.read_flash(**kwargs)
    if decode_hex:
        return _bytes_to_pretty_hex(flash_data,
                                    offset=programmer.MICROBIT_FLASH_START)
    else:
        return _bytes_to_intel_hex(flash_data,
                                   offset=programmer.MICROBIT_FLASH_START)