Ejemplo n.º 1
0
def write_flash(port, start_address, data, retry=2, is_wireless=False):
    data = bytearray(data)
    if len(data) > 256:
        click.echo('Tried writing too much data at once! ({} bytes)'.format(
            len(data)))
        return False
    port.read_all()
    c_addr = compute_address_commandable(start_address)
    debug('Writing {} bytes to {}'.format(len(data), adr_to_str(c_addr)))
    response = send_bootloader_command(port, 0x31)
    if response is None or len(response) < 1 or response[0] != ACK:
        if retry > 0:
            debug('RETRYING PACKET AT COMMAND')
            return write_flash(port, start_address, data, retry=retry - 1)
        else:
            click.echo('failed (write command not accepted)')
            return False
    port.write(c_addr)
    port.flush()
    time.sleep(0.005 if is_wireless else 0.002)
    response = port.read(1)
    debug_response(adr_to_str(c_addr), response)
    if response is None or len(response) < 1 or response[0] != ACK:
        if retry > 0:
            debug('RETRYING PACKET AT ADDRESS')
            return write_flash(port, start_address, data, retry=retry - 1)
        else:
            click.echo('failed (address not accepted)')
            return False
    checksum = len(data) - 1
    for x in data:
        checksum ^= x
    send_data = data[:]
    send_data.insert(0, len(send_data) - 1)
    send_data.append(checksum)
    port.write(send_data)
    port.flush()
    time.sleep(0.007 if is_wireless else 0.002)
    response = port.read(1)
    debug('STM BL RESPONSE TO WRITE: {}'.format(response))
    if response is None or len(response) < 1 or response[0] != ACK:
        if retry > 0:
            debug('RETRYING PACKET AT WRITE')
            return write_flash(port, start_address, data, retry=retry - 1)
        else:
            click.echo('failed (could not complete upload)')
            return False
    port.flush()
    port.reset_input_buffer()
    return True
Ejemplo n.º 2
0
def send_go_command(port, address):
    click.echo("Executing binary...", nl=False)
    address = compute_address_commandable(address)
    debug("Executing binary at {}".format(adr_to_str(address)))

    response = send_bootloader_command(port, 0x21, 1)
    if response is None or response[0] != ACK:
        click.echo("failed (execute command not accepted)")
        return False
    port.write(address)
    port.flush()
    click.echo("complete")
    return True
Ejemplo n.º 3
0
def send_go_command(port, address, retry=3):
    click.echo('Executing user code... ', nl=False)
    c_addr = compute_address_commandable(address)
    debug('Executing binary at {}'.format(adr_to_str(c_addr)))

    response = send_bootloader_command(port, 0x21, 1)
    debug_response(0x21, response)
    if response is None or len(response) < 1 or response[0] != ACK:
        click.echo('failed (execute command not accepted)')
        return False
    time.sleep(0.01)
    port.write(c_addr)
    time.sleep(0.01)
    response = port.read(1)
    debug_response(adr_to_str(c_addr), response)
    if response is None or len(response) < 1 or response[0] != ACK:
        click.echo(
            'user code might not have started properly. May need to restart Cortex'
        )
    else:
        click.echo('complete')
    return True
Ejemplo n.º 4
0
def send_go_command(port, address):
    click.echo('Executing binary...', nl=False)
    address = compute_address_commandable(address)
    debug('Executing binary at {}'.format(adr_to_str(address)))

    response = send_bootloader_command(port, 0x21, 1)
    if response is None or response[0] != ACK:
        click.echo('failed (execute command not accepted)')
        return False
    port.write(address)
    port.flush()
    click.echo('complete')
    return True
Ejemplo n.º 5
0
def write_flash(port, start_address, data):
    data = bytearray(data)
    if len(data) > 256:
        click.echo('Tried writing too much data at once! ({} bytes)'.format(
            len(data)))
        return False
    port.read_all()
    start_address = compute_address_commandable(start_address)
    debug('Writing {} bytes to {}'.format(len(data),
                                          adr_to_str(start_address)))
    response = send_bootloader_command(port, 0x31)
    if response is None or response[0] != ACK:
        click.echo('failed (write command not accepted)')
        return False
    port.write(start_address)
    port.flush()
    response = port.read(1)
    debug_response(adr_to_str(start_address), response)
    if response is None or response[0] != ACK:
        click.echo('failed (address not accepted)')
        return False
    checksum = len(data) - 1
    for x in data:
        checksum ^= x
    data.insert(0, len(data) - 1)
    data.append(checksum)
    port.write(data)
    time.sleep(0.005)
    response = port.read(1)
    if response is None or response[0] != ACK:
        port.write(data)
        time.sleep(20)
        response = port.read(1)
        if response is None or response[0] != ACK:
            click.echo('failed (could not complete upload)')
            return False
    port.flush()
    port.reset_input_buffer()
    return True
Ejemplo n.º 6
0
def write_flash(port, start_address, data):
    data = bytearray(data)
    if len(data) > 256:
        click.echo("Tried writing too much data at once! ({} bytes)".format(len(data)))
        return False
    port.read_all()
    start_address = compute_address_commandable(start_address)
    debug("Writing {} bytes to {}".format(len(data), adr_to_str(start_address)))
    response = send_bootloader_command(port, 0x31)
    if response is None or response[0] != ACK:
        click.echo("failed (write command not accepted)")
        return False
    port.write(start_address)
    port.flush()
    response = port.read(1)
    debug_response(adr_to_str(start_address), response)
    if response is None or response[0] != ACK:
        click.echo("failed (address not accepted)")
        return False
    checksum = len(data) - 1
    for x in data:
        checksum ^= x
    data.insert(0, len(data) - 1)
    data.append(checksum)
    port.write(data)
    time.sleep(0.005)
    response = port.read(1)
    if response is None or response[0] != ACK:
        port.write(data)
        time.sleep(20)
        response = port.read(1)
        if response is None or response[0] != ACK:
            click.echo("failed (could not complete upload)")
            return False
    port.flush()
    port.reset_input_buffer()
    return True