Wykres commitów

9760 Commity (66ca8e9b2c3c2d833e01e8d62dfdfe4016a46ced)

Autor SHA1 Wiadomość Data
Damien George e814db592d tests: Remove pyboard.py symlink and instead import from ../tools.
To eliminate the need for symlinks which don't work on systems like
Windows.
2018-09-05 15:36:33 +10:00
Damien George a23719e0ad stm32/mboot/main: Use correct formula for DFU download address.
As per ST's DfuSe specification, and following their example code.
2018-09-05 15:22:05 +10:00
Damien George 5f3016c663 stm32/mboot/Makefile: Use -Wno-attributes for ll_usb.c HAL source file.
A recent version of arm-none-eabi-gcc (8.2.0) will warn about unused packed
attributes in USB_WritePacket and USB_ReadPacket.  This patch suppresses
such warnings for this file only.
2018-09-05 15:21:43 +10:00
Damien George 5630f277bd tests/float: Test -inf and some larger values for special math funcs. 2018-09-04 17:03:37 +10:00
Damien George a111ca25ea tests/float/cmath_fun.py: Fix truncation of small real part of complex. 2018-09-04 17:02:36 +10:00
Damien George b9a133e5ad lib/libm/wf_tgamma: Fix tgammaf handling of -inf, should return nan. 2018-09-04 17:00:35 +10:00
Damien George afc7ddca31 lib/libm/math: Make tanhf more efficient and handle large numbers.
Prior to this patch tanhf(large number) would return nan due to inf/inf.
2018-09-04 17:00:30 +10:00
Damien George 0b239d458c lib/libm_dbl/tanh: Make tanh more efficient and handle large numbers.
Prior to this patch tanh(large number) would return nan due to inf/inf.
2018-09-04 16:57:46 +10:00
Damien George 8014e7f15f py/compile: Factor code that compiles start/end of exception handler. 2018-09-04 16:06:22 +10:00
Damien George 4970e9bc8c tests/basics: Add test cases for context manager raising in enter/exit. 2018-09-04 14:37:30 +10:00
Damien George b14c705c18 tests/basics: Add more tests for return within try-finally. 2018-09-04 14:37:07 +10:00
Damien George 938daa4ff9 tests/run-tests: Enable native tests for unwinding jumps. 2018-09-04 14:33:43 +10:00
Damien George 4ae7111573 py/emitnative: Add support for return/break/continue in try and with.
This patch adds full support for unwinding jumps to the native emitter.
This means that return/break/continue can be used in try-except,
try-finally and with statements.  For code that doesn't use unwinding jumps
there is almost no overhead added to the generated code.
2018-09-04 14:31:28 +10:00
Damien George 3cd2c281d7 py/emitnative: Cancel caught exception once handled to prevent reraise.
The native emitter keeps the current exception in a slot in its C stack
(instead of on its Python value stack), so when it catches an exception it
must explicitly clear that slot so the same exception is not reraised later
on.
2018-09-03 17:41:02 +10:00
Damien George b735208403 py/vm: Fix handling of finally-return with complex nested finallys.
Back in 8047340d75 basic support was added in
the VM to handle return statements within a finally block.  But it didn't
cover all cases, in particular when some finally's were active and others
inactive when the "return" was executed.

This patch adds further support for return-within-finally by correctly
managing the currently_in_except_block flag, and should fix all cases.  The
main point is that finally handlers remain on the exception stack even if
they are active (currently being executed), and the unwind return code
should only execute those finally's which are inactive.

New tests are added for the cases which now pass.
2018-09-03 13:08:16 +10:00
Damien George 828f771e32 tests/basics: Provide .exp files for generator tests that fail PEP479.
PEP479 (see https://www.python.org/dev/peps/pep-0479/) prohibited raising
StopIteration from within a generator (it is turned into a RuntimeError).
This behaviour was introduced in Python 3.5 and in 3.7 was made compulsory.
Until uPy implements PEP479, this patch adds .py.exp files for the relevant
tests so they can be run under Python 3.7.
2018-08-17 15:50:21 +10:00
Damien George 8979ce1671 tests: Modify tests that print repr of an exception with 1 arg.
In Python 3.7 the behaviour of repr() of an exception with one argument
changed: it no longer prints a trailing comma in the argument list.  See
https://bugs.python.org/issue30399

This patch modifies tests that rely on this behaviour to not rely on it.
And the python34.py test is updated to include a test for this behaviour
with a .exp file.
2018-08-17 15:46:04 +10:00
Damien George 0988b14cd6 tests/basics/int_big_error.py: Use bytearray to test for int overflow.
In Python 3.7 "1 >> (big int)" is now allowed, it no longer raises an
OverflowError.  So use bytearray to test big-int conversion overflow.
2018-08-17 15:43:47 +10:00
Damien George 96e1fd480d tests/basics/set_pop.py: Sort set before printing for consistent output. 2018-08-17 15:42:51 +10:00
Damien George 4f9842ad80 py/emitnx86: Fix number of args passed to mp_setup_code_state, 4 not 5. 2018-08-17 15:03:51 +10:00
Damien George 794c32102e py/asmxtensa: Use narrow version of add instr to reduce native code size 2018-08-17 14:53:58 +10:00
Damien George a0a29724c8 py/emitnative: Fix bug with store of 16 and 32 values in viper ARM mode. 2018-08-17 14:11:37 +10:00
Damien George 1ad44acb15 py/asmxtensa: Optimise loading local addr and support larger offsets. 2018-08-17 14:11:37 +10:00
Damien George fd10a11c6b py/asmxtensa: Fix bug with order of regs in addi encoding. 2018-08-17 14:11:37 +10:00
Damien George f774614110 tests/micropython: Add tests for try and with blocks under native/viper. 2018-08-17 14:11:36 +10:00
Damien George a3de776486 py/emitnative: Optimise and improve exception handling in native code.
Prior to this patch, native code would use a full nlr_buf_t for each
exception handler (try-except, try-finally, with).  For nested exception
handlers this would use a lot of C stack and be rather inefficient.

This patch changes how exceptions are handled in native code by setting up
only a single nlr_buf_t context for the entire function, and then manages a
state machine (using the PC) to work out which exception handler to run
when an exception is raised by an nlr_jump.  This keeps the C stack usage
at a constant level regardless of the depth of Python exception blocks.

The patch also fixes an existing bug when local variables are written to
within an exception handler, then their value was incorrectly restored if
an exception was raised (since the nlr_jump would restore register values,
back to the point of the nlr_push).

And it also gets nested try-finally+with working with the viper emitter.

Broadly speaking, efficiency of executing native code that doesn't use
any exception blocks is unchanged, and emitted code size is only slightly
increased for such function.  C stack usage of all native functions is
either equal or less than before.  Emitted code size for native functions
that use exception blocks is increased by roughly 10% (due in part to
fixing of above-mentioned bugs).

But, most importantly, this patch allows to implement more Python features
in native code, like unwind jumps and yielding from within nested exception
blocks.
2018-08-16 13:56:36 +10:00
Damien George 2964b41c28 py/asm*: Support assembling code to jump to a register, and get PC+off.
Useful for position independent code, and implementing state machines.
2018-08-16 13:45:24 +10:00
Damien George f7d6108d1a py/asmxtensa: Handle function entry/exit when stack use larger than 127. 2018-08-16 13:43:36 +10:00
Damien George 8c49995398 py/emitnative: Use small tables to simplify handling of local regs. 2018-08-15 10:55:11 +10:00
Damien George 056e0b6293 stm32/spi: Add implementation of low-level SPI protocol.
Can be used, for example, to configure external SPI flash using a hardware
SPI interface (code to be put in a board's bdev.c file):

    STATIC const spi_proto_cfg_t hard_spi_bus = {
        .spi = &spi_obj[5],
        .baudrate = 10000000,
        .polarity = 0,
        .phase = 0,
        .bits = 8,
        .firstbit = SPI_FIRSTBIT_MSB,
    };

    STATIC mp_spiflash_cache_t spi_bdev_cache;

    const mp_spiflash_config_t spiflash_config = {
        .bus_kind = MP_SPIFLASH_BUS_SPI,
        .bus.u_spi.cs = pin_A0,
        .bus.u_spi.data = (void*)&hard_spi_bus,
        .bus.u_spi.proto = &spi_proto,
        .cache = &spi_bdev_cache,
    };

    spi_bdev_t spi_bdev;
2018-08-14 22:10:43 +10:00
Damien George 01ce2e1682 unix/Makefile: Enable ussl module with nanbox build. 2018-08-14 21:53:06 +10:00
Damien George 206c65f22c extmod/modussl_axtls: Use MP_ROM_PTR for objects in allowed args array. 2018-08-14 21:47:07 +10:00
Damien George b8b2525576 extmod/modbtree: Update to work with new mp_stream_posix_XXX signatures. 2018-08-14 17:41:23 +10:00
Damien George 9ab816d676 py/stream: Adjust mp_stream_posix_XXX to take void*, not mp_obj_t.
These POSIX wrappers are assumed to be passed a concrete stream object so
it is more efficient (eg on nan-boxing builds) to pass in the pointer
rather than mp_obj_t, because then the users of these functions only need
to store a void* (and mp_obj_t may be wider than a pointer).  And things
would be further improved if the stream protocol functions eventually took
a pointer as their first argument (instead of an mp_obj_t).

This patch is a step to getting ussl/axtls compiling on nan-boxing builds.

See issue #3085.
2018-08-14 17:36:08 +10:00
Paul Sokolovsky ab78fe0eb9 mpy-cross/Makefile: Also undefine MICROPY_FORCE_32BIT and CROSS_COMPILE.
mpy-cross is a host, not target binary. It should not be build with the
target compiler, compiler options and other settings. For example,

If someone currently tries to build from pristine checkout the unix port
with the following command:

    make CROSS_COMPILE=arm-linux-gnueabihf-

then mpy-cross will be built with arm-linux-gnueabihf-gcc and of course
won't run on the host, leading to overall build failure.

This situation was worked around for some options in 1d8c3f4cff, so add
MICROPY_FORCE_32BIT and CROSS_COMPILE to that set too.
2018-08-14 17:20:18 +10:00
Damien George 8300be6d0f stm32/spi: Split out pyb.SPI and machine.SPI bindings to their own files
The aim here is to have spi.c contain the low-level SPI driver which is
independent (not fully but close) of MicroPython objects and methods, and
the higher-level bindings are separated out to pyb_spi.c and machine_spi.c.
2018-08-14 17:11:07 +10:00
Damien George 48d736f491 esp32: Update to latest ESP IDF.
Among other things, this requires putting bootloader object files in to
their relevant .a archive, so that they can be correctly referenced by the
ESP IDF's linker script.
2018-08-14 16:45:37 +10:00
Damien George a785a3dbfb py/objarray: Allow to build again when bytearray is disabled. 2018-08-14 16:23:21 +10:00
Damien George 91041945c9 py/gc: In gc_alloc, reset n_free var right before search for free mem.
Otherwise there is the possibility that n_free starts out non-zero from the
previous iteration, which may have found a few (but not enough) free blocks
at the end of the heap.  If this is the case, and if the very first blocks
that are scanned the second time around (starting at
gc_last_free_atb_index) are found to give enough memory (including the
blocks at the end of the heap from the previous iteration that left n_free
non-zero) then memory will be allocated starting before the location that
gc_last_free_atb_index points to, most likely leading to corruption.

This serious bug did not manifest itself in the past because a gc_collect
always resets gc_last_free_atb_index to point to the start of the GC heap,
and the first block there is almost always allocated to a long-lived
object (eg entries from sys.path, or mounted filesystem objects), which
means that n_free would be reset at the start of the search loop.

But with threading enabled with the GIL disabled it is possible to trigger
the bug via the following sequence of events:

1. Thread A runs gc_alloc, fails to find enough memory, and has a non-zero
   n_free at the end of the search.
2. Thread A calls gc_collect and frees a bunch of blocks on the GC heap.
3. Just after gc_collect finishes in thread A, thread B takes gc_mutex and
   does an allocation, moving gc_last_free_atb_index to point to the
   interior of the heap, to a place where there is most likely a run of
   available blocks.
4. Thread A regains gc_mutex and does its second search for free memory,
   starting with a non-zero n_free.  Since it's likely that the first block
   it searches is available it will allocate memory which overlaps with the
   memory before gc_last_free_atb_index.
2018-08-14 16:11:21 +10:00
forester3 02fbb0a455 stm32/boards/STM32F7DISC: Enable onboard SDRAM.
The default SYSCLK frequency is reduced to 192MHz because SDRAM requires it
to be 200MHz or less.
2018-08-14 16:04:10 +10:00
forester3 502c410214 stm32/boards/STM32F429DISC: Add burst len and autorefresh to SDRAM cfg.
To align with recent changes to sdram.c.
2018-08-14 16:03:13 +10:00
forester3 e562f99263 stm32/sdram: Allow additional config by a board, and tune MPU settings.
- Allow configuration by a board of autorefresh number and burst length.
- Increase MPU region size to 8MiB.
- Make SDRAM region cacheable and executable.
2018-08-14 16:00:14 +10:00
Damien George b18fa1e606 docs/library/machine.UART.rst: Specify optional txbuf and rxbuf args.
If a port would like to expose the configuration of transmit and/or receive
buffers then it can use these arguments.
2018-08-14 15:21:54 +10:00
Paul Sokolovsky fe1ef507ef unix/Makefile: coverage: Explicitly build "axtls" too.
"coverage" build uses different BUILD directory comparing to the normal
build. Previously, any build picked up libaxtls.a from normal build's
directory, but that was fixed recently. So, for each build, we must
build axtls explicitly.

This fixes Travis build in particular.
2018-08-14 15:10:52 +10:00
Paul Sokolovsky bb28fe7b7b py/py.mk: Don't hardcode path to libaxtls.a.
Use -L$(BUILD), not -Lbuild. Otherwise, builds for different archs/subarchs
using different values of BUILD may fail.
2018-08-14 15:10:52 +10:00
stijn 3f9d3e120b windows/msvc: Support custom compiler for header generation.
Use overrideable properties instead of hardcoding the use of the
default cl executable used by msvc toolsets. This allows using
arbitrary compiler commands for qstr header generation.
The CLToolExe and CLToolPath properties are used because they are,
even though absent from any official documentation, the de-facto
standard as used by the msvc toolsets themselves.
2018-08-14 15:07:19 +10:00
Damien George cbec17f2cd py/compile: For dynamic compiler, widen literal 1 to get correct shift.
Without this patch, on 64-bit architectures the "1 << (small_int_bits - 1)"
is computed using only 32-bit values (since small_int_bits is a uint8_t)
and so will overflow (and give the wrong result) if small_int_bits is
larger than 32.
2018-08-13 23:34:47 +10:00
Damien George 86e0b25532 stm32/spi: Round up prescaler calc to never exceed requested baudrate.
Requesting a baudrate of X should never configure the peripheral to have a
baudrate greater than X because connected hardware may not be able to
handle higher speeds.  This patch makes sure to round the prescaler up so
that the actual baudrate is rounded down.
2018-08-10 16:39:47 +10:00
stijn ca0d78cebb run-tests: Make .exp and .out file names unique by prefixing with dir.
Input files like basics/string_format.py and float/string_format.py have
the same basename so using that name for writing the output (.exp and .out
files) when both tests fail, results in the output of the first one being
overwritten.

Avoid this by using unique names for the output, replacing path characters
with underscores.
2018-08-10 16:33:42 +10:00
David Lechner 3fccd78aca stm32/dma: Fix spelling of "corresponding" in two locations. 2018-08-10 16:26:25 +10:00