Commit Graph

11671 Commits (26b0eec8af6d7db04192147f262e9ad17c7f28b1)

Author SHA1 Message Date
Daniel Thompson 26b0eec8af nrf: machine: Add mechanism to starve the watchdog
A soft reset doesn't reconfigure the watchdog which means if previous
software on the device has set a bad timeout then we are stuck without
until the battery runs flat or a watchdog reset takes place. Add a
mechanism to stop feeding the dog so that we can wait for it to trigger.

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
2020-11-11 20:40:00 +00:00
Daniel Thompson 5a9c74ac11 nrf: ubluepy: Provide visiblity of the BLE UART connect status
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
2020-11-11 20:40:00 +00:00
Daniel Thompson 4d03db0de9 readline: Allow linefeeds to be used to end lines
Currently readline ignores linefeeds which works well for \r\n (and \r)
data but has problems with linefeed seperations (which, amoung other
things, is used by Gadgetbridge's BangleJS driver.

Add support for executing commands on a linefeed whilst ensuring that
we continue to treat \r\n as a single line.

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
2020-11-11 20:40:00 +00:00
Fuji Pebri 0e65a6584d nrf: p8: add support for p8-watch
Signed-off-by: Fuji Pebri <pebri86@gmail.com>
[daniel@redfelineninja.org.uk: Updated to align with latest PineTime
changes]
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
2020-11-11 20:40:00 +00:00
Daniel Thompson 3dfcef3177 nrf: ble_uart: Add scheduler and power management support
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
2020-11-11 20:40:00 +00:00
Daniel Thompson 07789ed330 nrf: dsd6,pinetime,nitrogen: Disable micro:bit filesystem
Currently pinetime reserves 64k of FLASH for an unused file system. This
is pointless because we have a 4MB SPI flash that we can use as a
filesystem.

It is also pointless on dsd6 and nitrogen because we'd prefer to run
without a filesystem than to have something so stunted!

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
2020-11-11 20:40:00 +00:00
Daniel Thompson 7b85964f38 nrf: linker scripts: Reserve the first 32 bytes of RAM
These 32 bytes can be used as pseudo-NVRAM to allow communication between
the payload and the bootloader. The pseudo-NVRAM driver can be written in
pure python (using machine.mem32) so there no code changes beyond reserving
the memory are required.
2020-11-11 20:40:00 +00:00
Daniel Thompson 294a35ac31 nrf: modmachine: Enable direct memory access from python 2020-11-11 20:40:00 +00:00
Daniel Thompson f22b076fee nrf: utime: Add localtime and mktime calls
Currently the nrf port doesn't implement a proper RTC (it exposes
raw RTCounters instead) but it is still useful to implement
localtime() and mktime() (although the argument to localtime becomes
mandatory).
2020-11-11 20:40:00 +00:00
Daniel Thompson ef4d057a19 nrf: uos: Add support for LFS1 and LFS2 2020-11-11 20:40:00 +00:00
Daniel Thompson 0794c629e1 nrf: pinetime: Enable VFS
LFS2 will be handled by the Makefile...
2020-11-11 20:40:00 +00:00
Daniel Thompson c412daf8df nrf: Feed the watchdog from the RTC interrupt
Feeding a watchdog from a periodic interrupt isn't the smartest thing
to do (unless you have setup multi-channels) so we also allow us to
express to the WDT driver whether we've arrived from an ISR or not.
2020-11-11 20:40:00 +00:00
Daniel Thompson 44a5c4cdb2 nrf: Hide RTCounter(0) when Softdevice is enabled
On systems with a Softdevice then RTC0 is reserved and cannot
be used by the application.
2020-11-11 20:40:00 +00:00
Daniel Thompson 15d0a04366 nrf: Fix (frozen) native code generation 2020-11-11 20:40:00 +00:00
Daniel Thompson 542596b66f nrf: Add support for FROZEN_MANIFEST 2020-11-11 20:40:00 +00:00
Daniel Thompson 73864b0e82 nrf: modutime: Enable time.sleep() 2020-11-11 20:39:49 +00:00
Daniel Thompson 6b7ebe16cd nrf: pinetime: Add support for Pine64 PineTime 2020-11-11 20:37:17 +00:00
fanoush 523c0c80f2 nrf: dsd6: Add support for DS-D6 fitness tracker
From c4579ff251/micropython/micropython/DS-D6-micropython.diff

[daniel@redfelineninja.org.uk: Split out feature patches, minor clean ups]
2020-11-11 20:37:17 +00:00
Daniel Thompson 5366bf05a8 nrf: nitrogen: Add support for 96Boards BLE Nitrogen 2020-11-11 20:37:17 +00:00
Daniel Thompson 570d64dc31 nrf: Initial WDT-in-C implementation
Currently it is difficult to deploy uPy on form factor devices without
a reset pin. Any mistake in the boot code risks the system getting
stuck (at least until the battery goes flat). A watchdog and user
button can be combined to give a long-press reset that gives the user
a better shot at recovering the device before the battery runs down!
2020-11-11 20:36:30 +00:00
Daniel Thompson f5d4f86b52 nrf: ble_uart: Allow boards to choose the advertised name 2020-11-10 20:36:40 +00:00
Daniel Thompson 77f0aa8eae nrf: Enable NUS by default 2020-11-10 20:36:07 +00:00
fanoush f535967d77 nrf: Add support for DFU bootloader
From https://github.com/fanoush/ds-d6/blob/c4579ff25166722566c1b9251a20f99027972
588/micropython/micropython/DS-D6-micropython.diff

[daniel@redfelineninja.org.uk: Seperated out from the rest of the DS-D6
support]
2020-11-10 20:36:06 +00:00
Damien George b0932fcf2e all: Bump version to 1.13.
Signed-off-by: Damien George <damien@micropython.org>
2020-09-02 12:01:26 +10:00
Damien George 0e6ef40359 tests/extmod: Add tests for verifying FAT and littlefs mtime values.
Verifies mtime timestamps on files match the value returned by time.time().

Also update vfs_fat_ramdisk.py so it doesn't check FAT timestamp of the
root, because that may change across runs/ports.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-02 00:19:38 +10:00
Damien George a909c21587 unix/fatfs_port: Fix month offset in timestamp calculation.
Signed-off-by: Damien George <damien@micropython.org>
2020-09-02 00:19:06 +10:00
Damien George 2a72e90ab8 extmod/vfs: Add option to use 1970 as Epoch.
By setting MICROPY_EPOCH_IS_1970 a port can opt to use 1970/1/1 as the
Epoch for timestamps returned by stat().  And this setting is enabled on
the unix and windows ports because that's what they use.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-01 12:36:28 +10:00
Damien George 0385b21597 unix/modos: Support larger integer range in uos.stat fields.
On 32-bit builds these stat fields will overflow a small-int, so use
mp_obj_new_int_from_uint to construct the int object.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-01 12:36:28 +10:00
Damien George c70e599659 extmod/vfs: Support larger integer range in VFS stat time fields.
On ports like unix where the Epoch is 1970/1/1 and atime/mtime/ctime are in
seconds since the Epoch, this value will overflow a small-int on 32-bit
systems.  So far this is only an issue on 32-bit unix builds that use the
VFS layer (eg dev and coverage unix variants) but the fix (using
mp_obj_new_int_from_uint instead of MP_OBJ_NEW_SMALL_INT) is there for all
ports so as to not complicate the code, and because they will need the
range one day.

Also apply a similar fix to other fields in VfsPosix.stat because they may
also be large.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-01 12:36:28 +10:00
Damien George 40153b800a esp32/mphalport: Fix mp_hal_time_ns offset.
gettimeofday returns seconds since 2000/1/1 so needs to be adjusted to
seconds since 1970/1/1 to give the correct return value of mp_hal_time_ns.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-31 00:49:58 +10:00
Damien George 836bca9956 unix/variants: Fix fast and freedos variants so they build again.
This regressed in bd2fff6687

Signed-off-by: Damien George <damien@micropython.org>
2020-08-30 13:48:26 +10:00
Damien George d1995e50eb extmod/modlwip: Fix error return for TCP recv when not connected.
This commit fixes the cases when a TCP socket is in STATE_NEW,
STATE_LISTENING or STATE_CONNECTING and recv() is called on it.  It now
raises ENOTCONN instead of a random error code due to it previously
indexing beyond the start of error_lookup_table[].

Signed-off-by: Damien George <damien@micropython.org>
2020-08-30 13:20:51 +10:00
Damien George 06659077a8 all: Update Python code to conform to latest black formatting.
Updating to Black v20.8b1 there are two changes that affect the code in
this repository:

- If there is a trailing comma in a list (eg [], () or function call) then
  that list is now written out with one line per element.  So remove such
  trailing commas where the list should stay on one line.

- Spaces at the start of """ doc strings are removed.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-29 15:18:01 +10:00
Damien George 0c7354afaf tests: Split out complex reverse-op tests to separate test file.
So they can be skipped if __rOP__'s are not supported on the target.  Also
fix the typo in the complex_special_methods.py filename.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-29 14:12:20 +10:00
Damien George 40d174ac7d stm32/powerctrl.h: Include stdbool.h to get definition of bool.
Signed-off-by: Damien George <damien@micropython.org>
2020-08-29 14:00:24 +10:00
Damien George 338b12d3c8 LICENSE,docs: Update copyright year range to include 2020.
Signed-off-by: Damien George <damien@micropython.org>
2020-08-29 13:58:20 +10:00
Damien George a93a378e93 zephyr/README: Update required Zephyr version and mention new features.
Signed-off-by: Damien George <damien@micropython.org>
2020-08-28 16:42:32 +10:00
Michael Buesch cef678b2db extmod/machine_i2c: Fix buffer overrun if 'addrsize' is bigger than 32.
The memory operation functions read_mem() and write_mem() create a
temporary buffer on the local C stack for the address bytes with the size
of 4 bytes.  This buffer is filled in a loop from the user supplied address
and address length.  If the user supplied 'addrsize' is bigger than 32, the
local buffer is overrun.

Fix this by raising an exception for invalid 'addrsize' values.

Signed-off-by: Michael Buesch <m@bues.ch>
2020-08-27 12:39:11 +10:00
stijn 0c3f9d58a5 tests/run-tests: Make test output directory configurable.
A configurable result directory is advantageous because it enables
using a dedicated location, eventually outside of the source tree,
instead of forcing the output files into a fixed directory which might
also contain other files already. For that reason the default output
directory also has been changed to tests/results/.
2020-08-27 11:12:08 +10:00
stijn 405893afc6 tests/run-tests: Use absolute paths where possible.
Replace some usages of paths relative to the current working directory
with absolute paths relative to the tests directory.

Fixes and resulting changes:
- default values of MICROPYTHON and MPYCROSS are absolute paths and
  always correct
- likewise, the correct full paths for tools and extmod directories
  are appended to sys.path
- printing/cleaning failures works properly since it expects the .exp
  and .out files in the tests directory which is also where they
  are written to now, plus no more need for changing directories

This fixes #5872 and allows running custom tests which use run-tests
without having to cd to the tests directory first, and the test output
still is in the tests/ directory instead of the current working directory.

Discovery of tests and all skip test logic based on paths relative to
the current working directory remains unchanged which essentially means
that for running most of MicroPython's own tests, run-tests must still
be ran from within it's directory, so document that.
2020-08-27 11:12:08 +10:00
Roberto Colistete Jr 91c5d168c0 nrf/Makefile: Improve user C modules support.
Add CFLAGS_EXTRA to CFLAGS. Include LDFLAGS_MOD to the compilation.
And, add SRC_MOD to SRC_QSTR.
2020-08-26 22:14:40 +02:00
Damien George 5fb276de33 tests/extmod: Make uasyncio_fair test more reliable by adjusting sleeps.
With sleep(0.2) a multiple of sleep(0.1), the order of task 2 and 3
execution is not well defined, and depends on the precision of the system
clock and how fast the rest of the code runs.  So change 0.2 to 0.18 to
make the test more reliable.

Also fix a typo of t3/t4, and cancel t4 at the end.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-26 17:05:52 +10:00
Andrew Leech a80a146858 extmod/bluetooth: Support active scanning in BLE.gap_scan().
This adds an additional optional parameter to gap_scan() to select active
scanning, where scan responses are returned as well as normal scan results.
This parameter is False by default which retains the existing behaviour.
2020-08-26 15:00:11 +10:00
Jim Mussared 0bc2c1c105 extmod/modbluetooth: Fix race between READ_REQUEST and other IRQs.
The READ_REQUEST callback is handled as a hard interrupt (because the BLE
stack needs an immediate response from it so it can continue) and so calls
to Python require extra protection:

- the caller-owned tuple passed into the callback must be separate from the
  tuple used by other callback events (which are soft interrupts);

- the GC and scheduler must be locked during callback execution.
2020-08-26 14:57:36 +10:00
Jim Mussared 3d9a7ed02f extmod/btstack: Implement GAP scan duration_ms parameter.
This commit makes scanning work when duration_ms is set to zero.  Prior to
this it would not work with duration_ms set to zero.
2020-08-26 14:55:52 +10:00
Damien George 2acc087880 extmod/vfs_lfs: Add mtime support to littlefs files.
This commit adds support for modification time of files on littlefs v2
filesystems, using file attributes.  For some background see issue #6114.

Features/properties of this implementation:
- Only supported on littlefs2 (not littlefs1).
- Uses littlefs2's general file attributes to store the timestamp.
- The timestamp is 64-bits and stores nanoseconds since 1970/1/1 (if the
  range to the year 2554 is not enough then additional bits can be added to
  this timestamp by adding another file attribute).
- mtime is enabled by default but can be disabled in the constructor, eg:
  uos.mount(uos.VfsLfs2(bdev, mtime=False), '/flash')
- It's fully backwards compatible, existing littlefs2 filesystems will work
  without reformatting and timestamps will be added transparently to
  existing files (once they are opened for writing).
- Files without timestamps will open correctly, and stat will just return 0
  for their timestamp.
- mtime can be disabled or enabled each mount time and timestamps will only
  be updated if mtime is enabled (otherwise they will be untouched).

Signed-off-by: Damien George <damien@micropython.org>
2020-08-25 17:35:19 +10:00
Damien George ee50a6effe py/mphal.h: Introduce mp_hal_time_ns and implement on various ports.
This should return a 64-bit value being the number of nanoseconds since
1970/1/1.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-22 16:13:44 +10:00
Damien George badd351150 lib/timeutils: Add helper functions to deal with nanosecs since 1970.
Signed-off-by: Damien George <damien@micropython.org>
2020-08-22 15:41:10 +10:00
Damien George 92899354d9 unix/fatfs_port: Implement get_fattime.
Signed-off-by: Damien George <damien@micropython.org>
2020-08-22 14:45:57 +10:00
Damien George 55c76eaac1 extmod/uasyncio: Truncate negative sleeps to 0.
Otherwise a task that continuously awaits on a large negative sleep can
monopolise the scheduler (because its wake time is always less than
everything else in the pairing heap).

Signed-off-by: Damien George <damien@micropython.org>
2020-08-22 12:17:06 +10:00