File: README.rst

package info (click to toggle)
python-uflash 1.2.4+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 316 kB
  • sloc: python: 773; makefile: 218; sh: 79
file content (150 lines) | stat: -rw-r--r-- 5,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
uFlash
======

**THIS MODULE ONLY WORKS WITH PYTHON 2.7 or 3.3+.**

A utility for flashing the BBC micro:bit with Python scripts and the
MicroPython runtime. You pronounce the name of this utility "micro-flash". ;-)

It provides two services:

1. A library of functions to programatically create a hex file and flash it onto a BBC micro:bit.
2. A command line utility called `uflash` that will flash Python scripts onto a BBC micro:bit.

Several essential operations are implemented:

* Encode Python into the hex format.
* Embed the resulting hexified Python into the MicroPython runtime hex.
* Extract an encoded Python script from a MicroPython hex file.
* Discover the connected micro:bit.
* Copy the resulting hex onto the micro:bit, thus flashing the device.
* Specify the MicroPython runtime hex in which to embed your Python code.

Installation
------------

To install simply type::

    $ pip install uflash

...and the package will download from PyPI. If you wish to upgrade to the
latest version, use the following command::

    $ pip install --no-cache --upgrade uflash

**NB:** You must use a USB *data* cable to connect the micro:bit to your
computer (some cables are power only). You're in good shape if, when plugged
in, the micro:bit appears as a USB storage device on your file system.

Linux users: For uflash to work you must ensure the micro:bit is mounted as a
USB storage device. Usually this is done automatically. If not you've probably
configured automounting to be off. If that's the case, we assume you
have the technical knowledge to mount the device yourself or to install the
required kernel modules if they're missing. Default installs of popular Linux
distros "should just work" (tm) out of the box given a default install.

Command Usage
-------------

To read help simply type::

    $ uflash --help

or::

    $ uflash -h

To discover the version information type::

    $ uflash --version

If you type the command on its own then uflash will attempt to find a connected
BBC micro:bit and flash an unmodified default version of the MicroPython
runtime onto it::

    $ uflash
    Flashing Python to: /media/ntoll/MICROBIT/micropython.hex

To flash a version of the MicroPython runtime with a specified script embedded
within it (so that script is run when the BBC micro:bit boots up) then pass
the path to the Python script in as the first argument to the command::

    $ uflash my_script.py
    Flashing Python to: /media/ntoll/MICROBIT/micropython.hex

You can let uflash watch for changes of your script. It will be flashed
automatically every time you save it::

    $ uflash -w my_script.py

or::

    $ uflash --watch my_script.py

At this point uflash will try to automatically detect the path to the device.
However, if you have several devices plugged in and/or know what the path on
the filesystem to the BBC micro:bit already is, you can specify this as a
second argument to the command::

    $ uflash myscript.py /media/ntoll/MICROBIT
    Flashing Python to: /media/ntoll/MICROBIT/micropython.hex

You can even flash multiple devices at once::

    $ uflash myscript.py /media/ntoll/MICROBIT /media/ntoll/MICROBIT1
    Flashing Python to: /media/ntoll/MICROBIT/micropython.hex
    Flashing Python to: /media/ntoll/MICROBIT1/micropython.hex

To extract a Python script from a hex file use the "-e" flag like this::

    $ uflash -e something.hex myscript.py

This will save the Python script recovered from "something.hex" into the file
"myscript.py". If you don't supply a target the recovered script will emit to
stdout.

If you're developing MicroPython and have a custom runtime hex file you can
specify that uflash use it instead of the built-in version of MicroPython in
the following way::

    $ uflash -r firmware.hex

or::

    $ uflash --runtime=firmware.hex

Development
-----------

The source code is hosted in GitHub. Please feel free to fork the repository.
Assuming you have Git installed you can download the code from the canonical
repository with the following command::

    $ git clone https://github.com/ntoll/uflash.git

Ensure you have the correct dependencies for development installed by creating
a virtualenv and running::

    $ pip install -r requirements.txt

To locally install your development version of the module into a virtualenv,
run the following command::

    $ python setup.py develop

There is a Makefile that helps with most of the common workflows associated
with development. Typing ``make`` on its own will list the options thus::

    $ make

    There is no default Makefile target right now. Try:

    make clean - reset the project and remove auto-generated assets.
    make pyflakes - run the PyFlakes code checker.
    make pep8 - run the PEP8 style checker.
    make test - run the test suite.
    make coverage - view a report on test coverage.
    make check - run all the checkers and tests.
    make package - create a deployable package for the project.
    make publish - publish the project to PyPI.
    make docs - run sphinx to create project documentation.