Commit Graph

8757 Commits (7b2a9b059a4c60252b37f61cdbc2a28e375438a5)

Author SHA1 Message Date
Damien George 7b2a9b059a py/pystack: Use "pystack exhausted" as error msg for out of pystack mem.
Using the message "maximum recursion depth exceeded" for when the pystack
runs out of memory can be misleading because the pystack can run out for
reasons other than deep recursion (although in most cases pystack
exhaustion is probably indirectly related to deep recursion).  And it's
important to give the user more precise feedback as to the reason for the
error: if they know precisely that the pystack was exhausted then they have
a chance to increase the amount of memory available to the pystack (as
opposed to not knowing if it was the C stack or pystack that ran out).

Also, C stack exhaustion is more serious than pystack exhaustion because it
could have been that the C stack overflowed and overwrote/corrupted some
data and so the system must be restarted.  The pystack can never corrupt
data in this way so pystack exhaustion does not require a system restart.
Knowing the difference between these two cases is therefore important.

The actual exception type for pystack exhaustion remains as RuntimeError so
that programatically it behaves the same as a C stack exhaustion.
2018-02-19 00:26:14 +11:00
Damien George 3759aa2cc9 drivers/sdcard: Update SD mounting example code for ESP8266. 2018-02-18 23:40:54 +11:00
Ayke van Laethem 5591bd237a py/nlrthumb: Do not mark nlr_push as not returning anything.
By adding __builtin_unreachable() at the end of nlr_push, we're
essentially telling the compiler that this function will never return.
When GCC LTO is in use, this means that any time nlr_push() is called
(which is often), the compiler thinks this function will never return
and thus eliminates all code following the call.

Note: I've added a 'return 0' for older GCC versions like 4.6 which
complain about not returning anything (which doesn't make sense in a
naked function). Newer GCC versions (tested 4.8, 5.4 and some others)
don't complain about this.
2018-02-18 01:35:27 +01:00
Damien George 60c6b880fa esp32/machine_rtc: Move export declaration from .c to common .h file. 2018-02-17 00:52:55 +11:00
Eric Poulsen abec47a1cd esp32/modesp32: Add new module "esp32" to support extra wake features.
The machine.Pin class is also updated to support these wake-on-pin
features.
2018-02-17 00:49:05 +11:00
Eric Poulsen 44033a1d27 esp32/machine_rtc: Add RTC class to machine module with sleep impl.
The machine.RTC class is added and the machine module is updated with the
implementation of sleep, deepsleep, reset_cause and wake_reason.
2018-02-17 00:47:17 +11:00
Damien George 73d1d20b46 py/objexcept: Remove long-obsolete mp_const_MemoryError_obj.
This constant exception instance was once used by m_malloc_fail() to raise
a MemoryError without allocating memory, but it was made obsolete long ago
by 3556e45711.  The functionality is now
replaced by the use of mp_emergency_exception_obj which lives in the global
uPy state, and which can handle any exception type, not just MemoryError.
2018-02-15 16:50:02 +11:00
Damien George d966a33486 stm32: Change header include guards from STMHAL to STM32 to match dir. 2018-02-15 15:47:04 +11:00
Damien George e05fca4ef3 docs/library/ujson: Document dump() and load() functions. 2018-02-15 11:37:48 +11:00
Damien George d9bca1f7bd extmod/modujson: Implement ujson.dump() function. 2018-02-15 11:35:42 +11:00
Damien George 9e8b7b1b63 docs/library/ujson: Update to conform with docs conventions.
The formatting of exception objects is done as per CPython conventions, eg:

    :exc:`TypeError`
2018-02-15 11:31:34 +11:00
Olivier Ortigues 298b325f3e docs/esp8266: Add a note concerning GPIO16 pull capabilities. 2018-02-15 11:15:12 +11:00
Olivier Ortigues 359d2bdf84 esp8266/README.md: Update build instruction to reflect new ports dir. 2018-02-15 11:14:52 +11:00
Olivier Ortigues d072573226 docs/esp8266: Update PWM doc regarding clipping of min/max values. 2018-02-15 11:14:34 +11:00
Olivier Ortigues 5c83d05b49 esp8266/esppwm: Clip negative duty numbers to 0.
Prior to this patch a negative duty would lead to full PWM.
2018-02-15 11:12:41 +11:00
Damien George ab7819c314 unix/mpconfigport_coverage: Enable range (in)equality comparison. 2018-02-14 23:22:02 +11:00
Damien George d77da83d55 py/objrange: Implement (in)equality comparison between range objects.
This feature is not often used so is guarded by the config option
MICROPY_PY_BUILTINS_RANGE_BINOP which is disabled by default.  With this
option disabled MicroPython will always return false when comparing two
range objects for equality (unless they are exactly the same object
instance).  This does not match CPython so if (in)equality between range
objects is needed then this option should be enabled.

Enabling this option costs between 100 and 200 bytes of code space
depending on the machine architecture.
2018-02-14 23:17:06 +11:00
Damien George 5604b710c2 py/emitglue: When assigning bytecode only pass bytecode len if needed.
Most embedded targets will have this bit of the code disabled, saving a
small amount of code space.
2018-02-14 18:41:17 +11:00
Damien George e98ff40604 py/modbuiltins: Simplify casts from char to byte ptr in builtin ord. 2018-02-14 18:27:14 +11:00
Damien George 19aee9438a py/unicode: Clean up utf8 funcs and provide non-utf8 inline versions.
This patch provides inline versions of the utf8 helper functions for the
case when unicode is disabled (MICROPY_PY_BUILTINS_STR_UNICODE set to 0).
This saves code size.

The unichar_charlen function is also renamed to utf8_charlen to match the
other utf8 helper functions, and the signature of this function is adjusted
for consistency (const char* -> const byte*, mp_uint_t -> size_t).
2018-02-14 18:19:22 +11:00
Damien George 49e0dd54e6 tests/run-tests: Capture any output from a crashed uPy execution.
Instead of putting just 'CRASH' in the .py.out file, this patch makes it so
any output from uPy that led to the crash is stored in the .py.out file, as
well as the 'CRASH' message at the end.
2018-02-14 17:24:59 +11:00
Damien George 04c55f5828 tests: Rewrite some tests so they can run without needing eval/exec.
For builds without the compiler enabled (and hence without eval/exec) it is
useful to still be able to run as many tests as possible.
2018-02-14 16:50:20 +11:00
Damien George 6031957473 tests: Automatically skip tests that require eval, exec or frozenset. 2018-02-14 16:46:44 +11:00
Damien George 24c513cbc3 unix/Makefile,embedding/Makefile: Remove obsolete use of STMHAL_SRC_C. 2018-02-14 15:24:21 +11:00
Damien George e6235fe647 teensy: Update GPIO speed consts to align with changes in stm32 port. 2018-02-14 10:52:45 +11:00
Damien George fa13e0d35b stm32: Factor out flash and SPI block-device code to separate files.
Prior to this patch, storage.c was a combination of code that handled
either internal flash or external SPI flash and exposed one of them as a
block device for the local storage.  It was also exposed to the USB MSC.

This patch splits out the flash and SPI code to separate files, which each
provide a general block-device interface (at the C level).  Then storage.c
just picks one of them to use as the local storage medium.  The aim of this
factoring is to allow to add new block devices in the future and allow for
easier configurability.
2018-02-13 22:21:46 +11:00
Damien George 34911f1a57 stm32/boards: Update all boards to work with new USB configuration. 2018-02-13 18:57:01 +11:00
Damien George d9b9fbc41a lib/utils/pyexec: Update to work with new MICROPY_HW_ENABLE_USB option. 2018-02-13 18:56:12 +11:00
Damien George 5c320bd0b0 stm32: Introduce MICROPY_HW_ENABLE_USB and clean up USB config.
This patch allows to completely compile-out support for USB, and no-USB is
now the default.  If a board wants to enable USB it should define:

    #define MICROPY_HW_ENABLE_USB (1)

And then one or more of the following to select the USB PHY:

    #define MICROPY_HW_USB_FS (1)
    #define MICROPY_HW_USB_HS (1)
    #define MICROPY_HW_USB_HS_IN_FS (1)
2018-02-13 18:51:08 +11:00
Damien George 8aad22fdca stm32/timer: Support MCUs that don't have TIM4 and/or TIM5. 2018-02-13 15:53:39 +11:00
Damien George 6e91ab5806 stm32/spi: Further updates to use newer versions of HAL names. 2018-02-13 15:53:08 +11:00
Damien George 3eb0694b97 stm32: Update HAL macro and constant names to use newer versions.
Newer versions of the HAL use names which are cleaner and more
self-consistent amongst the HAL itself.  This patch switches to use those
names in most places so it is easier to update the HAL in the future.
2018-02-13 15:37:35 +11:00
Damien George 8e1cb58a23 stm32/usbdev: Fix USBD setup request handler to use correct recipient.
Prior to this patch the USBD driver did not handle the recipient correctly
for setup requests.  It was not interpreting the req->wIndex field in the
right way: in some cases this field indicates the endpoint number but the
code was assuming it always indicated the interface number.

This patch fixes this.  The only noticeable change is to the MSC
interface, which should now correctly respond to the USB_REQ_CLEAR_FEATURE
request and hence unmount properly from the host when requested.
2018-02-12 17:22:59 +11:00
Damien George 02f88cb2df stm32/boards: Remove all config options that are set to defaults.
mpconfigboard_common.h now sets the defaults so there is no longer a need
to explicitly list all configuration options in a board's mpconfigboard.h
file.
2018-02-09 18:40:40 +11:00
Damien George 2d5bab46be stm32: Add mpconfigboard_common.h with common/default board settings.
This file mirrors py/mpconfig.h but for board-level config options.  It
provides a default configuration, to be overridden by a specific
mpconfigboard.h file, as well as setting up certain macros to automatically
configure a board.
2018-02-09 18:40:13 +11:00
Damien George bbb08431f3 py/objfloat: Fix case of raising 0 to -infinity.
It was raising an exception but it should return infinity.
2018-02-08 14:35:43 +11:00
Damien George b75cb8392b py/parsenum: Fix parsing of floats that are close to subnormal.
Prior to this patch, a float literal that was close to subnormal would
have a loss of precision when parsed.  The worst case was something like
float('10000000000000000000e-326') which returned 0.0.
2018-02-08 14:02:50 +11:00
Damien George 0c650d4276 py/vm: Simplify stack sentinel values for unwind return and jump.
This patch simplifies how sentinel values are stored on the stack when
doing an unwind return or jump.  Instead of storing two values on the stack
for an unwind jump it now stores only one: a negative small integer means
unwind-return and a non-negative small integer means unwind-jump with the
value being the number of exceptions to unwind.  The savings in code size
are:

   bare-arm:   -56
minimal x86:   -68
   unix x64:   -80
unix nanbox:    -4
      stm32:   -56
     cc3200:   -64
    esp8266:   -76
      esp32:  -156
2018-02-08 13:30:33 +11:00
Damien George 0b12cc8feb .travis.yml,ports/unix/Makefile: Add coverage test for script via stdin. 2018-02-08 11:30:19 +11:00
Damien George 923ebe767d tests/unix: Add coverage test for calling mp_obj_new_bytearray. 2018-02-08 11:14:30 +11:00
Damien George 771dfb0826 py/modbuiltins: For builtin_chr, use uint8_t instead of char for array.
The array should be of type unsigned byte because that is the type of the
values being stored.  And changing to uint8_t helps to prevent warnings
from some static analysers.
2018-02-07 16:13:02 +11:00
Damien George 1f53ff61ff tests/basics: Rename remaining tests that are for built-in functions.
For consistency with all of the other tests that are named builtin_XXX.py.
2018-02-07 15:55:52 +11:00
Damien George b45c8c17f0 py/objtype: Check and prevent delete/store on a fixed locals map.
Note that the check for elem!=NULL is removed for the
MP_MAP_LOOKUP_ADD_IF_NOT_FOUND case because mp_map_lookup will always
return non-NULL for such a case.
2018-02-07 15:44:29 +11:00
Damien George cc92c0572e stm32/main: Remove need for first_soft_reset variable. 2018-02-05 16:13:05 +11:00
Damien George 4607be3768 stm32/main: Reorder some init calls to put them before soft-reset loop.
The calls to rtc_init_start(), sdcard_init() and storage_init() are all
guarded by a check for first_soft_reset, so it's simpler to just put them
all before the soft-reset loop, without the check.

The call to machine_init() can also go before the soft-reset loop because
it is only needed to check the reset cause which can happen once at the
first boot.  To allow this to work, the reset cause must be set to SOFT
upon a soft-reset, which is the role of the new function machine_deinit().
2018-02-05 15:52:36 +11:00
Damien George 12464f1bd2 stm32/rtc: Add compile-time option to set RTC source as LSE bypass.
To use the LSE bypass feature (where an external source provides the RTC
clock) a board must set the config variable MICROPY_HW_RTC_USE_BYPASS.
2018-02-05 15:22:15 +11:00
Damien George 011d1555cb stm32/rtc: Fix RTC init to use LSI if LSI is already selected on boot.
Upon boot the RTC early-init function should detect if LSE or LSI is
already selected/running and, if so, use it.  When the LSI has previously
(in the previous reset cycle) been selected as the clock source the only
way to reliably tell is if the RTCSEL bits of the RCC_BDCR are set to the
correct LSI value.  In particular the RCC_CSR bits for LSI control do not
indicate if the LSI is ready even if it is selected.

This patch removes the check on the RCC_CSR bits for the LSI being on and
ready and only uses the check on the RCC_BDCR to see if the LSI should be
used straightaway.  This was tested on a PYBLITEv1.0 and with the patch the
LSI persists correctly as the RTC source as long as the backup domain
remains powered.
2018-02-05 15:12:22 +11:00
Damien George 5a62f0faa6 stm32/rtc: Fix rtc_info flags when LSE fails and falls back to LSI.
Previously, if LSE is selected but fails and the RTC falls back to LSI,
then the rtc_info flags would incorrectly state that LSE is used.  This
patch fixes that by setting the bit in rtc_info only after the clock is
ready.
2018-02-05 14:40:06 +11:00
Damien George 20f5de9b39 stm32/spi: Accept machine.SPI object in spi_from_mp_obj() function.
Also, change ValueError to TypeError if the argument to this function is
not of an SPI type.
2018-02-05 14:32:56 +11:00
Damien George 93d5c9e1c4 drivers/cc3200: Update to work with new stm32 SPI API. 2018-02-05 14:32:56 +11:00