Wykres commitów

11866 Commity (f6fd46c4024c28c827ccffd13dbe02b9ea74cfb8)

Autor SHA1 Wiadomość Data
Jim Mussared f6fd46c402 examples/bluetooth: Add bonding/passkey demo.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:44:00 +11:00
Jim Mussared e4f27cbee7 extmod/modbluetooth: Add support for passkey authentication.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:43:32 +11:00
Jim Mussared 4bcbbfdb6c extmod/modbluetooth: Simplify synchronous invoke_irq_handler signature.
Rather than dealing with the different int types, just pass them all as a
single array of mp_int_t with n_unsigned (before addr) and n_signed (after
addr).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:43:01 +11:00
Jim Mussared b799fe1421 docs/library/ubluetooth.rst: Add bonding docs.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:42:46 +11:00
Jim Mussared c4d08aa4e3 extmod/modbluetooth: Add support for bonding (key persistence).
This adds `_IRQ_GET_SECRET` and `_IRQ_SET_SECRET` events to allow the BT
stack to request the Python code retrive/store/delete secret key data.  The
actual keys and values are opaque to Python and stack-specific.

Only NimBLE is implemented (pending moving btstack to sync events).  The
secret store is designed to be compatible with BlueKitchen's TLV store API.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:41:41 +11:00
Jim Mussared fff634e031 docs/library/ubluetooth.rst: Add gap_pair() docs.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:41:36 +11:00
Jim Mussared 801e8ffacf extmod/modbluetooth: Add gap_pair(conn_handle) func to intiate pairing.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:41:26 +11:00
Jim Mussared f822557cbb docs/library/ubluetooth.rst: Add pairing/bonding config docs.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:41:21 +11:00
Jim Mussared a1fcf30121 extmod/modbluetooth: Allow configuration of pairing/bonding parameters.
This allows setting the security and MITM-protection requirements.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:40:49 +11:00
Andrew Leech 05fef8c6a4 extmod/modbluetooth: Add _IRQ_ENCRYPTION_UPDATE event.
This allows the application to be notified if any of encrypted,
authenticated and bonded state change, as well as the encryption key size.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:40:15 +11:00
Jim Mussared ac89267fef extmod/modbluetooth: Add compile-config flag to enable pairing/bonding.
Enable it on STM32/Unix NimBLE only (pairing/bonding requires synchronous
events and full bindings).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:39:41 +11:00
Jim Mussared 5e20f689ad docs/library/ubluetooth.rst: Update read request IRQ docs.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:39:17 +11:00
Jim Mussared 60830bcba4 extmod/modbluetooth: Allow user-specified reason in read request IRQ.
Instead of returning None/bool from the IRQ, return None/int (where a zero
value means success).  This mirrors how the L2CAP_ACCEPT return value
works.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:37:55 +11:00
Jim Mussared 89553997b8 docs/library/ubluetooth.rst: Update char/desc flags.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:37:45 +11:00
Andrew Leech 1697ff335d extmod/modbluetooth: Allow setting char/desc enc/auth options.
This widens the characteristic/descriptor flags to 16-bit, to allow setting
encryption/authentication requirements.

Sets the required flags for NimBLE and btstack implementations.

The BLE.FLAG_* constants will eventually be deprecated in favour of copy
and paste Python constants (like the IRQs).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:36:50 +11:00
Jim Mussared 7a9aa49595 docs/library/ubluetooth.rst: Add _IRQ_CONNECTION_UDPATE docs.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:36:41 +11:00
Andrew Leech c70665fb0b extmod/modbluetooth: Add _IRQ_CONNECTION_UPDATE event.
This allows the application to be notified of changes to the connection
interval, connection latency and supervision timeout.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:35:39 +11:00
Jim Mussared f2a9a0ac41 extmod/nimble: Fail read if the characteristic is too big.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02 14:35:17 +11:00
Damien George b505971069 extmod/uasyncio: Fix cancellation handling of wait_for.
This commit switches the roles of the helper task from a cancellation task
to a runner task, to get the correct semantics for cancellation of
wait_for.

Some uasyncio tests are now disabled for the native emitter due to issues
with native code generation of generators and yield-from.

Fixes #5797.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-02 12:31:37 +11:00
Damien George 309dfe39e0 extmod/uasyncio: Add Task.done() method.
This is added because task.coro==None is no longer the way to detect if a
task is finished.  Providing a (CPython compatible) function for this
allows the implementation to be abstracted away.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-02 12:07:06 +11:00
Damien George ca40eb0fda extmod/uasyncio: Delay calling Loop.call_exception_handler by 1 loop.
When a tasks raises an exception which is uncaught, and no other task
await's on that task, then an error message is printed (or a user function
called) via a call to Loop.call_exception_handler.  In CPython this call is
made when the Task object is freed (eg via reference counting) because it's
at that point that it is known that the exception that was raised will
never be handled.

MicroPython does not have reference counting and the current behaviour is
to deal with uncaught exceptions as early as possible, ie as soon as they
terminate the task.  But this can be undesirable because in certain cases
a task can start and raise an exception immediately (before any await is
executed in that task's coro) and before any other task gets a chance to
await on it to catch the exception.

This commit changes the behaviour so that tasks which end due to an
uncaught exception are scheduled one more time for execution, and if they
are not await'ed on by the next scheduling loop, then the exception handler
is called (eg the exception is printed out).

Signed-off-by: Damien George <damien@micropython.org>
2020-12-02 12:07:06 +11:00
Damien George a14ca31e85 docs/reference/repl.rst: Add information about new raw-paste mode.
Signed-off-by: Damien George <damien@micropython.org>
2020-12-01 22:35:13 +11:00
Damien George a59282b9bf tools/pyboard.py: Add fast raw-paste mode.
This commit adds support to pyboard.py for the new raw REPL paste mode.

Note that this new pyboard.py is fully backwards compatible with old
devices (it detects if the device supports the new raw REPL paste mode).

Signed-off-by: Damien George <damien@micropython.org>
2020-12-01 22:35:13 +11:00
Damien George bb24c69b90 lib/utils/pyexec: Add stdin-reader on raw REPL with flow control.
Background: the friendly/normal REPL is intended for human use whereas the
raw REPL is for computer use/automation.  Raw REPL is used for things like
pyboard.py script_to_run.py.  The normal REPL has built-in flow control
because it echos back the characters.  That's not so with raw REPL and flow
control is just implemented by rate limiting the amount of data that goes
in.  Currently it's fixed at 256 byte chunks every 10ms.  This is sometimes
too fast for slow MCUs or systems with small stdin buffers.  It's also too
slow for a lot of higher-end MCUs, ie it could be a lot faster.

This commit adds a new raw REPL mode which includes flow control: the
device will echo back a character after a certain number of bytes are sent
to the host, and the host can use this to regulate the data going out to
the device.  The amount of characters is controlled by the device and sent
to the host before communication starts.  This flow control allows getting
the maximum speed out of a serial link, regardless of the link or the
device at the other end.

Also, this new raw REPL mode parses and compiles the incoming data as it
comes in.  It does this by creating a "stdin reader" object which is then
passed to the lexer.  The lexer requests bytes from this "stdin reader"
which retrieves bytes from the host, and does flow control.  What this
means is that no memory is used to store the script (in the existing raw
REPL mode the device needs a big buffer to read in the script before it can
pass it on to the lexer/parser/compiler).  The only memory needed on the
device is enough to parse and compile.

Finally, it would be possible to extend this new raw REPL to allow bytecode
(.mpy files) to be sent as well as text mode scripts (but that's not done
in this commit).

Some results follow. The test was to send a large 33k script that contains
mostly comments and then prints out the heap, run via pyboard.py large.py.

On PYBD-SF6, prior to this PR:

$ ./pyboard.py large.py
stack: 524 out of 23552
GC: total: 392192, used: 34464, free: 357728
 No. of 1-blocks: 12, 2-blocks: 2, max blk sz: 2075, max free sz: 22345
GC memory layout; from 2001a3f0:
00000: h=hhhh=======================================hhBShShh==h=======h
00400: =====hh=B........h==h===========================================
00800: ================================================================
00c00: ================================================================
01000: ================================================================
01400: ================================================================
01800: ================================================================
01c00: ================================================================
02000: ================================================================
02400: ================================================================
02800: ================================================================
02c00: ================================================================
03000: ================================================================
03400: ================================================================
03800: ================================================================
03c00: ================================================================
04000: ================================================================
04400: ================================================================
04800: ================================================================
04c00: ================================================================
05000: ================================================================
05400: ================================================================
05800: ================================================================
05c00: ================================================================
06000: ================================================================
06400: ================================================================
06800: ================================================================
06c00: ================================================================
07000: ================================================================
07400: ================================================================
07800: ================================================================
07c00: ================================================================
08000: ================================================================
08400: ===============================================.....h==.........
       (349 lines all free)

(the big blob of used memory is the large script).

Same but with this PR:

$ ./pyboard.py large.py
stack: 524 out of 23552
GC: total: 392192, used: 1296, free: 390896
 No. of 1-blocks: 12, 2-blocks: 3, max blk sz: 40, max free sz: 24420
GC memory layout; from 2001a3f0:
00000: h=hhhh=======================================hhBShShh==h=======h
00400: =====hh=h=B......h==.....h==....................................
       (381 lines all free)

The only thing in RAM is the compiled script (and some other unrelated
items).

Time to download before this PR: 1438ms, data rate: 230,799 bits/sec.

Time to download with this PR: 119ms, data rate: 2,788,991 bits/sec.

So it's more than 10 times faster, and uses significantly less RAM.

Results are similar on other boards. On an stm32 board that connects via
UART only at 115200 baud, the data rate goes from 80kbit/sec to
113kbit/sec, so gets close to saturating the UART link without loss of
data.

The new raw REPL mode also supports a single ctrl-C to break out of this
flow-control mode, so that a ctrl-C can always get back to a known state.
It's also backwards compatible with the original raw REPL mode, which is
still supported with the same sequence of commands.  The new raw REPL
mode is activated by ctrl-E, which gives an error on devices that do not
support the new mode.

Signed-off-by: Damien George <damien@micropython.org>
2020-11-30 11:37:44 +11:00
Damien George f7225d1c95 github/workflows: Run unix and qemu-arm workflows when tests change.
Signed-off-by: Damien George <damien@micropython.org>
2020-11-30 10:48:41 +11:00
Damien George 2f723d83c0 README: Update badges for new GitHub Actions workflows.
Signed-off-by: Damien George <damien@micropython.org>
2020-11-30 10:48:41 +11:00
Damien George 02b44a0154 tests/run-tests: Update skipped tests on CI for GitHub Actions.
Signed-off-by: Damien George <damien@micropython.org>
2020-11-30 10:48:41 +11:00
Damien George ee3706f4bd travis: Stop using Travis for CI.
Travis now limits the amount of free minutes for open-source projects, and
it does not provide enough for this project.  So stop using it and instead
use on GitHub Actions.

Signed-off-by: Damien George <damien@micropython.org>
2020-11-29 22:21:28 +11:00
Damien George a598ae5b4d github/workflows: Add workflows for all CI tasks, builds and tests.
Signed-off-by: Damien George <damien@micropython.org>
2020-11-29 22:21:28 +11:00
Damien George 547e8a9fe7 tools/ci.sh: Add helper script to run CI tasks.
The aim is for this script to be used on any CI platform, as well as run
locally.

Signed-off-by: Damien George <damien@micropython.org>
2020-11-29 22:21:28 +11:00
Damien George be24e6a53f py/mpprint: Prevent case fall-through when assert is disabled.
Signed-off-by: Damien George <damien@micropython.org>
2020-11-29 17:31:24 +11:00
Damien George 6a3d70db96 tests/extmod: Add vfs_posix.py test for uos.VfsPosix class.
Signed-off-by: Damien George <damien@micropython.org>
2020-11-29 17:31:24 +11:00
Jim Mussared 5a7027915c extmod/nimble/modbluetooth_nimble: Fix build when l2cap unavailable.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-24 11:57:29 +11:00
Jim Mussared 23fad2526d tests/multi_bluetooth: Add L2CAP channels multi-test.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-24 01:07:17 +11:00
Jim Mussared 3795c71271 docs/library/ubluetooth.rst: Add docs for L2CAP channels.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-24 01:07:17 +11:00
Jim Mussared 0e8af2b370 extmod/modbluetooth: Add API for L2CAP channels.
Also known as L2CAP "connection oriented channels". This provides a
socket-like data transfer mechanism for BLE.

Currently only implemented for NimBLE on STM32 / Unix.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-24 01:07:17 +11:00
Damien George 64180f0742 extmod/machine_i2c: Add init protocol method for generic I2C bindings.
Hardware I2C implementations must provide a .init() protocol method if they
want to support reconfiguration.  Otherwise the default is that i2c.init()
raises an OSError (currently the case for all ports).

mp_machine_soft_i2c_locals_dict is renamed to mp_machine_i2c_locals_dict to
match the generic SPI bindings.

Fixes issue #6623 (where calling .init() on a HW I2C would crash).

Signed-off-by: Damien George <damien@micropython.org>
2020-11-23 19:45:04 +11:00
JPFrancoia 3dcb551d89 nrf/README: Describe Pin numbering scheme for nRF52840.
Clarify that the nRF52840's GPIO 1.00 to 1.15 maps to Pin(32-47) in
MicroPython.
2020-11-22 21:01:49 +01:00
robert 5af3c046c7 esp32,esp8266: Remove "FAT" from warning message in inisetup.py.
Because FAT is not any more the only filesystem used.
2020-11-18 16:26:19 +11:00
Jim Mussared 240b3de8bc stm32/rfcore: Depend on NimBLE only when BLE enabled.
This fixes the build for non-STM32WB based boards when the NimBLE submodule
has not been fetched, and also allows STM32WB boards to build with BLE
disabled.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-18 14:45:51 +11:00
Jim Mussared 21c293fbcd stm32/rfcore: Don't send HCI ACL cmds while another is pending.
And, for TX, the next/prev entries ane unused so set them to NULL to
indicate this.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-16 17:09:12 +11:00
Jim Mussared 119c88ef17 stm32/flash: Implement WB55 flash locking.
This is needed to moderate concurrent access to the internal flash, as
while an erase/write is in progress execution will stall on the wireless
core due to the bus being locked.

This implements Figure 10 from AN5289 Rev 3.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-16 17:08:30 +11:00
Jim Mussared a64121b0d4 stm32/rfcore: Make RX IRQ schedule the NimBLE handler.
This commit switches the STM32WB HCI interface (between the two CPUs) to
require the use of MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS, and as a
consequence to require NimBLE.  IPCC RX IRQs now schedule the NimBLE
handler to run via mp_sched_schedule.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-16 17:04:27 +11:00
Jim Mussared efc0800132 tests/multi_bluetooth: Add a test for WB55 concurrent flash access.
This test currently passes on Unix/PYBD, but fails on WB55 because it lacks
synchronisation of the internal flash.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-16 17:04:02 +11:00
Jim Mussared 7e75245d54 tests/multi_bluetooth: Change dict index-and-del to pop, to clear event.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-16 17:03:27 +11:00
Jim Mussared 61d1e4b01b extmod/nimble: Make stm32 and unix NimBLE ports use synchronous events.
This changes stm32 from using PENDSV to run NimBLE to use the MicroPython
scheduler instead.  This allows Python BLE callbacks to be invoked directly
(and therefore synchronously) rather than via the ringbuffer.

The NimBLE UART HCI and event processing now happens in a scheduled task
every 128ms.  When RX IRQ idle events arrive, it will also schedule this
task to improve latency.

There is a similar change for the unix port where the background thread now
queues the scheduled task.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00
Jim Mussared 81e92d3d6e extmod/modbluetooth: Re-instate optional no-ringbuf modbluetooth.
This requires that the event handlers are called from non-interrupt context
(i.e. the MicroPython scheduler).

This will allow the BLE stack (e.g. NimBLE) to run from the scheduler
rather than an IRQ like PENDSV, and therefore be able to invoke Python
callbacks directly/synchronously.  This allows writing Python BLE handlers
for events that require immediate response such as _IRQ_READ_REQUEST (which
was previous a hard IRQ) and future events relating to pairing/bonding.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00
Jim Mussared 6d9fdff8d0 extmod/nimble: Poll startup directly rather than using NimBLE sem.
Using a semaphore (the previous approach) will only run the UART, whereas
for startup we need to also run the event queue.

This change makes it run the full scheduler hook.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00
Jim Mussared c398e46b29 extmod/modbluetooth: Combine gattc-data-available callbacks into one.
Instead of having the stack indicate a "start", "data"..., "end", pass
through the data in one callback as an array of chunks of data.

This is because the upcoming non-ringbuffer modbluetooth implementation
cannot buffer the data in the ringbuffer and requires instead a single
callback with all the data, to pass to the Python callback.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00
Jim Mussared 4559bcb467 unix: Make mp_hal_delay_ms run MICROPY_EVENT_POLL_HOOK.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00