Commit Graph

9359 Commits

Author SHA1 Message Date
Damien George
a2ac7e4fc9 stm32/boards: Add .ld and af.csv files for STM32F722.
These files can also be used for F723, F732 and F733 MCUs.
2018-06-22 15:39:10 +10:00
Damien George
92667dc2e5 tools/pydfu.py: Add support for multiple memory segments.
Segments are separated by / and begin with the memory address.  This
follows how the ST DFU tool works.
2018-06-22 15:32:32 +10:00
Damien George
ec7982ec6d stm32/mboot: Add support for erase/read/write of external SPI flash.
This patch adds support to mboot for programming external SPI flash.  It
allows SPI flash to be programmed via a USB DFU utility in the same way
that internal MCU flash is programmed.
2018-06-22 15:30:34 +10:00
Damien George
7f41f73f0f stm32/qspi: Don't require data reads and writes to be a multiple of 4.
Prior to this patch the QSPI driver assumed that the length of all data
reads and writes was a multiple of 4.  This patch allows any length.  Reads
are optimised for speed by using 32-bit transfers when possible, but writes
always use a byte transfer because they only use a single data IO line and
are relatively slow.
2018-06-22 15:07:01 +10:00
Damien George
34344a413f py/stream: Remove stray empty line at start of file.
This was accidentally added in 6abede2ca9
2018-06-20 16:26:12 +10:00
Damien George
b92a8adbfa tests: Add tests using "file" argument in print and sys.print_exception. 2018-06-20 16:08:25 +10:00
Damien George
582b190764 py: Add checks for stream objects in print() and sys.print_exception(). 2018-06-20 15:57:10 +10:00
Damien George
2c8d130f70 py/stream: Update comment for mp_stream_write_adaptor. 2018-06-20 15:56:32 +10:00
Damien George
561ae9a91b stm32/boards/NUCLEO_F091RC: Fix TICK_INT_PRIORITY so it is highest prio.
Fixes issue #3880.
2018-06-20 12:24:18 +10:00
Damien George
5962c210c5 stm32/mboot: Define constants for reset mode cycling and timeout.
And fix timeout value so that it does actually finish with reset_mode=1.
2018-06-19 23:23:17 +10:00
Damien George
6d8816fe84 tests/import: Add test for importing invalid .mpy file. 2018-06-18 17:50:34 +10:00
Damien George
e49cd106b4 stm32/spi: Fix SPI driver so it can send/recv more than 65535 bytes.
The DMA peripheral is limited to transferring 65535 elements at a time so
in order to send more than that the SPI driver must split the transfers up.

The user must be aware of this limit if they are relying on precise timing
of the entire SPI transfer, because there might be a small delay between
the split transfers.

Fixes issue #3851, and thanks to @kwagyeman for the original fix.
2018-06-18 17:41:14 +10:00
Damien George
338af99a7f stm32/can: Use MP_OBJ_ARRAY_TYPECODE_FLAG_RW where appropriate. 2018-06-18 13:42:05 +10:00
Damien George
c00ee200ac py/objarray: Replace 0x80 with new MP_OBJ_ARRAY_TYPECODE_FLAG_RW macro. 2018-06-18 13:40:53 +10:00
rolandvs
ca2b1d6b36 stm32/boards/NUCLEO_F091RC: Add Arduino-named pins and rename CPU pins.
To match pin labels on other NUCLEO 64 boards.
2018-06-18 13:06:27 +10:00
rolandvs
0d3de68669 stm32/boards/stm32f091_af.csv: Split labels that are multiple funcs. 2018-06-18 13:05:24 +10:00
Damien George
48829cd3c6 tests/extmod: Add test for ujson.dump writing to a user IOBase object. 2018-06-18 12:35:56 +10:00
Damien George
0ecce77c66 tests/extmod/ujson_dump.py: Add test for dump to non-stream object. 2018-06-18 12:35:56 +10:00
Damien George
a5f5552a0a tests/unix/extra_coverage: Don't test stream objs with NULL write fun.
This behaviour of a NULL write C method on a stream that uses the write
adaptor objects is no longer supported.  It was only ever used by the
coverage build for testing the fail path of mp_get_stream_raise().
2018-06-18 12:35:56 +10:00
Damien George
e8398a5856 extmod: Update to use new mp_get_stream helper.
With this patch objects are only checked that they have the stream protocol
at the start of their use as a stream, and afterwards the efficient
mp_get_stream() helper is used to extract the stream protocol C methods.
2018-06-18 12:35:56 +10:00
Damien George
6abede2ca9 py/stream: Introduce and use efficient mp_get_stream to access stream_p.
The existing mp_get_stream_raise() helper does explicit checks that the
input object is a real pointer object, has a non-NULL stream protocol, and
has the desired stream C method (read/write/ioctl).  In most cases it is
not necessary to do these checks because it is guaranteed that the input
object has the stream protocol and desired C methods.  For example, native
objects that use the stream wrappers (eg mp_stream_readinto_obj) in their
locals dict always have the stream protocol (or else they shouldn't have
these wrappers in their locals dict).

This patch introduces an efficient mp_get_stream() which doesn't do any
checks and just extracts the stream protocol struct.  This should be used
in all cases where the argument object is known to be a stream.  The
existing mp_get_stream_raise() should be used primarily to verify that an
object does have the correct stream protocol methods.

All uses of mp_get_stream_raise() in py/stream.c have been converted to use
mp_get_stream() because the argument is guaranteed to be a proper stream
object.

This patch improves efficiency of stream operations and reduces code size.
2018-06-18 12:35:56 +10:00
Damien George
31cf49c672 examples/embedding: Add code markup and fix typo in README.md. 2018-06-18 12:29:22 +10:00
Damien George
ceff433fcc stm32/mboot: Adjust user-reset-mode timeout so it ends with mode=1.
If the user button is held down indefinitely (eg unintenionally, or because
the GPIO signal of the user button is connected to some external device)
then it makes sense to end the reset mode cycle with the default mode of
1, which executes code as normal.
2018-06-18 12:23:27 +10:00
Damien George
564abb01a5 extmod/vfs_fat_diskio: Factor disk ioctl code to reduce code size.
Functionality is unchanged.
2018-06-16 18:21:42 +10:00
Damien George
1747d15c3a drivers/sdcard: Fix bug in computing number of sectors on SD Card.
This was a typo from the very first commit of this file.
2018-06-15 18:02:40 +10:00
Damien George
8b8c083625 drivers/sdcard: Change driver to use new block-device protocol. 2018-06-15 18:01:36 +10:00
Damien George
34b2f6b6fc esp32/modules: Include umqtt library in frozen modules. 2018-06-15 16:39:49 +10:00
Damien George
d61d119c94 esp32: Update to latest ESP IDF. 2018-06-15 16:23:53 +10:00
Damien George
7be4a23c0c stm32/i2cslave: Fix ordering of event callbacks in slave IRQ handler.
It's possible (at least on F4 MCU's) to have RXNE and STOPF set at the same
time during a call to the slave IRQ handler.  In such cases RXNE should be
handled before STOPF so that all bytes are processed before
i2c_slave_process_rx_end() is called.
2018-06-15 14:15:31 +10:00
Damien George
bc5e8a2cb6 stm32/i2c: Fix num_acks calculation in i2c_write for F0 and F7 MCU's.
Due to buffering of outgoing bytes on the I2C bus, detection of a NACK
using the ISR_NACKF flag needs to account for the case where ISR_NACKF
corresponds to the previous-to-previous byte.
2018-06-15 14:10:53 +10:00
Damien George
37a7257aff stm32/timer: Support TIM1 on F0 MCUs. 2018-06-15 10:50:08 +10:00
Damien George
b78ca32476 drivers/memory/spiflash: Add functions for direct erase/read/write.
These new API functions do not use the cache.
2018-06-14 16:52:56 +10:00
Damien George
cc5a94044a drivers/memory/spiflash: Rename functions to indicate they use cache.
This patch renames the existing SPI flash API functions to reflect the fact
that the go through the cache:

    mp_spiflash_flush -> mp_spiflash_cache_flush
    mp_spiflash_read  -> mp_spiflash_cached_read
    mp_spiflash_write -> mp_spiflash_cached_write
2018-06-14 16:52:56 +10:00
Damien George
335d26b27d stm32/boards/STM32L476DISC: Update SPI flash config for cache change. 2018-06-14 16:52:56 +10:00
Damien George
86fe73beb9 drivers/memory/spiflash: Move cache buffer to user-provided config.
This patch removes the global cache variables from the SPI flash driver and
now requires the user to provide the cache memory themselves, via the SPI
flash configuration struct.  This allows to either have a shared cache for
multiple SPI flash devices (by sharing a mp_spiflash_cache_t struct), or
have a single cache per device (or a mix of these options).

To configure the cache use:

    mp_spiflash_cache_t spi_bdev_cache;

    const mp_spiflash_config_t spiflash_config =
        // any bus options
        .cache = &spi_bdev_cache,
    };
2018-06-14 16:52:56 +10:00
Damien George
cf1509c911 esp32/fatfs_port: Implement get_fattime so FAT files have a timestamp.
Fixes issue #3859.
2018-06-13 14:13:34 +10:00
Damien George
d11fb09333 extmod/modussl_axtls: Fix __del__ to point to mp_stream_close_obj. 2018-06-13 13:16:21 +10:00
Damien George
035906419d extmod/uos_dupterm: Use native C stream methods on dupterm object.
This patch changes dupterm to call the native C stream methods on the
connected stream objects, instead of calling the Python readinto/write
methods.  This is much more efficient for native stream objects like UART
and webrepl and doesn't require allocating a special dupterm array.

This change is a minor breaking change from the user's perspective because
dupterm no longer accepts pure user stream objects to duplicate on.  But
with the recent addition of uio.IOBase it is possible to still create such
classes just by inheriting from uio.IOBase, for example:

    import uio, uos

    class MyStream(uio.IOBase):
        def write(self, buf):
            # existing write implementation
        def readinto(self, buf):
            # existing readinto implementation

    uos.dupterm(MyStream())
2018-06-12 15:06:11 +10:00
Damien George
5042d98514 stm32/Makefile: Rebuild all qstrs when any board configuration changes. 2018-06-12 13:53:43 +10:00
Damien George
7ad04d17da py/mkrules.mk: Regenerate all qstrs when config files change.
A port can define QSTR_GLOBAL_DEPENDENCIES to add extra files.
2018-06-12 13:53:43 +10:00
Damien George
0501427907 esp32: Remove port-specific uhashlib implementation and use common one.
Now that the common module has mbedtls support for both SHA1 and SHA256 it
can now be used on this port.
2018-06-12 13:50:11 +10:00
Yonatan Goldschmidt
c2fb725e72 extmod/moduhashlib: Make function objects STATIC.
These are not exported to anyone anyway.
2018-06-12 13:50:11 +10:00
Yonatan Goldschmidt
6963ee9075 extmod/moduhashlib: Allow using the sha256 implementation of mbedTLS. 2018-06-12 13:50:11 +10:00
Yonatan Goldschmidt
6630354ffe extmod/moduhashlib: Allow to disable the sha256 class.
Via the config value MICROPY_PY_UHASHLIB_SHA256.  Default to enabled to
keep backwards compatibility.

Also add default value for the sha1 class, to at least document its
existence.
2018-06-12 13:50:11 +10:00
Yonatan Goldschmidt
38682d4629 extmod/moduhashlib: Reorder funcs so that they are grouped by hash type.
Makes the code much more readable by reducing the number of #ifdefs and
keeping related functions close.
2018-06-12 13:47:20 +10:00
Yonatan Goldschmidt
b045ebd354 extmod/moduhashlib: Prefix all Python methods and objects with uhashlib.
For consistency with other modules, and to help avoid clashes with the
actual underlying functions that do the hashing (eg
crypto-algorithms/sha256.c:sha256_update).
2018-06-12 13:44:09 +10:00
Damien George
c901cc6862 tests/extmod: Add test for VFS and user-defined filesystem and files. 2018-06-12 12:29:26 +10:00
Damien George
9144b1f10c tests/io: Add simple IOBase test. 2018-06-12 12:29:26 +10:00
Damien George
565f590586 ports: Enable IOBase on unix, stm32, esp8266 and esp32.
It's a core feature, in particular required for user-streams with uasyncio.
2018-06-12 12:29:26 +10:00
Damien George
af0932a779 py/modio: Add uio.IOBase class to allow to define user streams.
A user class derived from IOBase and implementing readinto/write/ioctl can
now be used anywhere a native stream object is accepted.

The mapping from C to Python is:

    stream_p->read  --> readinto(buf)
    stream_p->write --> write(buf)
    stream_p->ioctl --> ioctl(request, arg)

Among other things it allows the user to:

- create an object which can be passed as the file argument to print:
  print(..., file=myobj), and then print will pass all the data to the
  object via the objects write method (same as CPython)
- pass a user object to uio.BufferedWriter to buffer the writes (same as
  CPython)
- use select.select on a user object
- register user objects with select.poll, in particular so user objects can
  be used with uasyncio
- create user files that can be returned from user filesystems, and import
  can import scripts from these user files

For example:

    class MyOut(io.IOBase):
        def write(self, buf):
            print('write', repr(buf))
            return len(buf)

    print('hello', file=MyOut())

The feature is enabled via MICROPY_PY_IO_IOBASE which is disabled by
default.
2018-06-12 12:29:26 +10:00