summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2021-06-24py/mperrno: Add MP_ECANCELED error code.David Lechner
This is useful when binding asynchronous functions in C. Signed-off-by: David Lechner <david@pybricks.com>
2021-06-24unix/modffi: Add option to lock GC in callback, and cfun access.Amir Gonnen
Add an optional 'lock' kwarg to callback that locks GC and scheduler. This allows the callback to be invoked asynchronously in 'interrupt context', for example as a signal handler. Also add the 'cfun' member function to callback, that allows retrieving the C callback function address. This is needed when the callback should be set to a struct field. See related #7373. Signed-off-by: Amir Gonnen <amirgonnen@gmail.com>
2021-06-24all: Fix signed shifts and NULL access errors from -fsanitize=undefined.Jeff Epler
Fixes the following (the line numbers match commit 0e87459e2bfd07): ../../extmod/crypto-algorithms/sha256.c:49:19: runtime error: left shif... ../../extmod/moduasyncio.c:106:35: runtime error: member access within ... ../../py/binary.c:210:13: runtime error: left shift of negative value -... ../../py/mpz.c:744:16: runtime error: negation of -9223372036854775808 ... ../../py/objint.c:109:22: runtime error: left shift of 1 by 31 places c... ../../py/objint_mpz.c:374:9: runtime error: left shift of 4611686018427... ../../py/objint_mpz.c:374:9: runtime error: left shift of negative valu... ../../py/parsenum.c:106:14: runtime error: left shift of 46116860184273... ../../py/runtime.c:395:33: runtime error: left shift of negative value ... ../../py/showbc.c:177:28: runtime error: left shift of negative value -... ../../py/vm.c:321:36: runtime error: left shift of negative value -1``` Testing was done on an amd64 Debian Buster system using gcc-8.3 and these settings: CFLAGS += -g3 -Og -fsanitize=undefined LDFLAGS += -fsanitize=undefined The introduced TASK_PAIRHEAP macro's conditional (x ? &x->i : NULL) assembles (under amd64 gcc 8.3 -Os) to the same as &x->i, since i is the initial field of the struct. However, for the purposes of undefined behavior analysis the conditional is needed. Signed-off-by: Jeff Epler <jepler@gmail.com>
2021-06-24esp32/main: Allow MICROPY_DIR to be overridden.Damien George
This is necessary when building a custom out-of-tree board. Signed-off-by: Damien George <damien@micropython.org>
2021-06-23tools: Remove obsolete build-stm-latest.sh script.Damien George
The tools/autobuild/ scripts replace this. Signed-off-by: Damien George <damien@micropython.org>
2021-06-23tools/autobuild: Add scripts to build release firmware.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-23stm32/usb: Make irq's default trigger enable all events.Damien George
Following how other .irq() methods work on other objects. Signed-off-by: Damien George <damien@micropython.org>
2021-06-23extmod/btstack: Check that BLE is active before performing operations.Damien George
Otherwise it can easily lead to a hard crash. Signed-off-by: Damien George <damien@micropython.org>
2021-06-23extmod/btstack: Add missing call to mp_bluetooth_hci_uart_deinit.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-23stm32: Provide a custom BTstack runloop that integrates with soft timer.Damien George
It reschedules the BT HCI poll soft timer so that it is called exactly when the next timer expires. Signed-off-by: Damien George <damien@micropython.org>
2021-06-23stm32/mpbthciport: Change from systick to soft-timer for BT scheduling.Damien George
Instead of using systick the BT subsystem is now scheduled using a soft timer. This means it is scheduled only when it is enabled. Signed-off-by: Damien George <damien@micropython.org>
2021-06-23stm32/softtimer: Add soft_timer_reinsert() helper function.Damien George
And call mp_pairheap_init_node() in soft_timer_static_init() so that reinsert can be called after static_init. Signed-off-by: Damien George <damien@micropython.org>
2021-06-22esp32,esp8266: Add __len__ to NeoPixel driver to support iterating.Michael Weiss
Signed-off-by: mishafarms <github@mishafarms.us>
2021-06-22LICENSE: Reference third-party licenses.Jim Mussared
This is to provide a summary of the licenses used by MicroPython. - Add SPDX identifier for every directory that includes non-MIT-licensed content. - Add brief summary. - Update docs license to be more explicit. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-06-20esp32/boards/sdkconfig.base: Disable MEMPROT_FEATURE to alloc from IRAM.Damien George
Dynamically generate/loaded native code (eg from @micropython.native or native .mpy files) needs to be able allocate from IRAM, and the memory protection feature must be disabled for that to work. Disabling it is needed to get native code working on ESP32-S2 and -C3. Signed-off-by: Damien George <damien@micropython.org>
2021-06-19py/mpstate: Schedule KeyboardInterrupt on main thread.David Lechner
This introduces a new macro to get the main thread and uses it to ensure that asynchronous exceptions such as KeyboardInterrupt (CTRL+C) are only scheduled on the main thread. This is more deterministic than being scheduled on a random thread and is more in line with CPython that only allow signal handlers to run on the main thread. Fixes issue #7026. Signed-off-by: David Lechner <david@pybricks.com>
2021-06-19py/mpstate: Make exceptions thread-local.David Lechner
This moves mp_pending_exception from mp_state_vm_t to mp_state_thread_t. This allows exceptions to be scheduled on a specific thread. Signed-off-by: David Lechner <david@pybricks.com>
2021-06-18all: Bump version to 1.16.v1.16Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-18tests/float: Make bytes/bytearray construct tests work with obj repr C.Damien George
2.5 can be represented correctly in object representation C, but 2.3 cannot (it is slightly truncated). Signed-off-by: Damien George <damien@micropython.org>
2021-06-18py/gc: Only use no_sanitize_address attribute for GCC 4.8 and above.Damien George
It's not supported on older GCC versions. Signed-off-by: Damien George <damien@micropython.org>
2021-06-18esp8266/boards/GENERIC_512K: Add custom minimal _boot.py.Damien George
Commit 0abf6f830cd390e2e5dbd4a2c68f611f5c9507dc removed _boot.py from the manifest for the GENERIC_512K board because the build does not include a filesystem. But the main code expects _boot.py to be there and prints an error if it's not. So add a custom _boot.py, which just sets the gc.threshold(). Signed-off-by: Damien George <damien@micropython.org>
2021-06-18esp32/machine_sdcard: Use deinit_p to deinit SD bus in SPI mode.Damien George
Fixes issue #7352. Signed-off-by: Damien George <damien@micropython.org>
2021-06-17drivers/display/ssd1306.py: Add support for 72x40 displays.Mike Causer
The 72x40 OLED requires selecting the internal IREF, as opposed to the default external IREF. This is an undocumented feature in the SSD1306 datasheet, but is present in the SSD1315 datasheet. It's possible the 72x40 OLED is actually using the newer SSD1315 controller. Sending the IREF select command to SSD1306 displays has no effect on them, so it's added to the init_display() instead of wrapping in an "if width = 72". Also tested on a 128x64 OLED using the SSD1315 controller (smaller ribbon cable) and the proposed change has no effect on the display, as the module comes with the correct current limiting resistor. Internal and external IREF work the same. Fixes issue #7281.
2021-06-17esp32/machine_hw_spi: Allow None for unused pins in initializer.Jonathan Hogg
Make the hardware SPI initializer method match the `init()` method by allowing `None` to be given for `sck`/`mosi`/`miso` to specify an unused signal.
2021-06-17docs/esp32: Document WLAN "reconnects" config option.Thomas Wenrich
2021-06-17esp32/modnetwork: Add "reconnects" option to WLAN STA interface.Thomas Wenrich
This adds a wlan.config(reconnects=N) option to set the number of reconnect attempts that will be made if the WLAN connection goes down. The default is N=-1 (infinite retries, current behavior). Setting wlan.config(reconnects=0) will disable the reconnect attempts. A nice side effect of reconnects=0 is that wlan.status() will report the disconnect reason now. See related issue #5326.
2021-06-17esp32/network_lan: Add Ethernet support for IDF v4.1 and above.Tobias Eydam
Ethernet-PHYs from ESP-IDF (LAN8720, IP101, RTL8201, DP83848) are now supported in IDF v4.1 and above. PHY_KSZ8041 is only for ESP-IDF 4.3 and above. ESP32S2 is not supported. Signed-off-by: Tobias Eydam <eydam-prototyping@outlook.com>
2021-06-17extmod/nimble: Remove TODO comment about notify_custom freeing om.Damien George
The comments in NimBLE for ble_gattc_notify_custom() state that "This function consumes the supplied mbuf regardless of the outcome.". And inspection of NimBLE code shows that this is the case. So the comment can be removed. Signed-off-by: Damien George <damien@micropython.org>
2021-06-16extmod/uasyncio: Fix race with cancelled task waiting on finished task.Damien George
This commit fixes a problem with a race between cancellation of task A and completion of task B, when A waits on B. If task B completes just before task A is cancelled then the cancellation of A does not work. Instead, the CancelledError meant to cancel A gets passed through to B (that's expected behaviour) but B handles it as a "Task exception wasn't retrieved" scenario, printing out such a message (this is because finished tasks point their "coro" attribute to themselves to indicate they are done, and implement the throw() method, but that method inadvertently catches the CancelledError). The correct behaviour is for B to bounce that CancelledError back out. This bug is mainly seen when wait_for() is used, and in that context the symptoms are: - occurs when using wait_for(T, S), if the task T being waited on finishes at exactly the same time as the wait-for timeout S expires - task T will have run to completion - the "Task exception wasn't retrieved message" is printed with "<class 'CancelledError'>" as the error (ie no traceback) - the wait_for(T, S) call never returns (it's never put back on the uasyncio run queue) and all tasks waiting on this are blocked forever from running - uasyncio otherwise continues to function and other tasks continue to be scheduled as normal The fix here reworks the "waiting" attribute of Task to be called "state" and uses it to indicate whether a task is: running and not awaited on, running and awaited on, finished and not awaited on, or finished and awaited on. This means the task does not need to point "coro" to itself to indicate finished, and also allows removal of the throw() method. A benefit of this is that "Task exception wasn't retrieved" messages can go back to being able to print the name of the coroutine function. Fixes issue #7386. Signed-off-by: Damien George <damien@micropython.org>
2021-06-16mimxrt/modutime: Extend the time module.robert-hh
Methods added: - time.time() - time.time_ns() - time.gmtime() - time.localtime() - time.mktime() The rp2 port was uses as the template for the change.
2021-06-16mimxrt/machine_pin: Implement pin.irq() functionality.robert-hh
2021-06-16mimxrt/machine_uart: Add the UART class to the machine module.robert-hh
The implementation uses the LPUARTx devices. Up to 8 UARTs can be used, given that the pins are accessible. E.g. 8 on Teensy 4.1, 5 on MIMXRT1020_EVK. For Tennsy 4.0 and 4.1 the UART numbers are as printed on the pinout 1..N. The MIMXRT10xx-EVK boards have only one UART named, which gets the number 1. All other UART are assigned to different Pins: MIMXRT1010-EVK: D0/D1 UART 1 D6/D7 UART 2 A0/D4 UART 3 MIMXRT1020-EVK: D0/D1 UART 1 D6/D9 UART 2 D10/D12 UART 3 D14/D15 UART 4 A0/A1 UART 5 MIMXRT1050-EVK, MIMXRT1060-EVK, MIMXRT1064-EVK: D0/D1 UART 1 D7/D6 UART 2 D8/D9 UART 3 A1/A0 UART 4
2021-06-15tools/mpremote: Use signal to capture and handle ctrl-C on Windows.Damien George
Now a ctrl-C will not stop mpremote, rather this character will be passed through to the attached device. The mpremote version is also increased to 0.0.5. Signed-off-by: Damien George <damien@micropython.org>
2021-06-15tools/mpremote: Use available ports instead of auto-connect list.Damien George
Using just the list of available ports, instead of a hard-coded list of possible ports, means that all ports will be available for auto connection. And the order that they will be attempted in will match what's printed by "mpremote connect list" (and will be the same as before, trying ACMx before USBx). Auto-connect will also now work on Mac, and will allow all COM ports on Windows. Signed-off-by: Damien George <damien@micropython.org>
2021-06-15extmod/uasyncio: Add readinto() method to Stream class.Mike Teachman
With docs and a multi-test using TCP server/client. This method is a MicroPython extension, although there is discussion of adding it to CPython: https://bugs.python.org/issue41305 Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
2021-06-15unix: Fix build on arm64-darwin due to integer cast.Pavol Rusnak
This fixes error: cast to smaller integer type 'int' from 'pthread_t'. pthread_t is defined as long, not as int. Signed-off-by: Pavol Rusnak <pavol@rusnak.io>
2021-06-15rp2/machine_rtc: Check return value from rtc_set_datetime.Krzysztof Adamski
The rtc_set_datetime() from pico-sdk will validate the values in the datetime_t structure and refuse to set the time if they aren't valid. It makes sense to raise an exception if this happens instead of failing silently which might be confusing (as an example, see: https://github.com/micropython/micropython/pull/6928#issuecomment-860166044 ).
2021-06-13stm32/eth: Fix eth_link_status function to use correct BSR bit.iabdalkader
Fixes #7346.
2021-06-13stm32/eth: Add low-power mode configuration option.iabdalkader
Add low power functionality configurable with: lan.config(low_power=True/False)
2021-06-13tests/cpydiff: Add test for array constructor with overflowing value.Zoltán Vörös
2021-06-12mimxrt/machine_rtc: Maintain microsecond offset.robert-hh
The supplied value for microseconds in datetime() will be treated as a starting value for the reported microseconds. Due to internal processing in setting the time, there is an offset about 1 ms.
2021-06-12mimxrt/machine_rtc: Change RTC.datetime() tuple to match other ports.robert-hh
This change moves the datetime tuple format back to the one used by all the other ports: (year, month, day, weekday, hour, minute, second, microsecond) Weekday is a number between 0 and 6, with 0 assigned to Monday. It has to be provided when setting the RTC with datetime(), but will be ignored on entry and calculated when needed. The weekday() method was removed, since that is now again a part of the datetime tuple. The now() method was updated so it continues to return a tuple that matches CPython's datetime module.
2021-06-12rp2/machine_rtc: Add initial support for RTC.Krzysztof Adamski
Initial support for machine.RTC on rp2 port. It only supports datetime() method and nothing else. The method gets/returns a tuple of 8 items, just like esp32 port, for example, but the usec parameter is ignored as the RP2 RTC only works up to seconds precision. The Pico RTC isn't very useful as the time is lost during reset and there seems to be no way to easily power up just the RTC clock with a low current voltage, but still there seems to be use-cases for that, see issues #6831, and a Thonny issue #1592. It was also requested for inclusion on v1.15 roadmap on #6832. Signed-off-by: Krzysztof Adamski <k@japko.eu>
2021-06-12docs/library/machine.RTC.rst: Document datetime method and fix ex code.Peter Hinch
This is the minimum change to fix the example code so it actually runs on the majority of ports.
2021-06-11esp32/README: Describe how to select compatible version of existing IDF.IhorNehrutsa
2021-06-11esp32/partitions-2MiB.csv: Update table so firmware fits.noslaver
The current MicroPython app size is larger than the size allocated in the partitions table.
2021-06-11esp32/makeimg.py: Load sizes from partition table and verify data fits.Damien George
Changes introduced are: - the application offset is now loaded from the partition table instead of being hard-coded to 0x10000 - maximum size of all sections is computed using the partition table - an error is generated if any section overflows its allocated space - remaining bytes are printed for each section Signed-off-by: Damien George <damien@micropython.org>
2021-06-10stm32/sdram: Prevent array-bounds warnings with GCC 11.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-10stm32/boards: Enable MICROPY_HW_SPIFLASH_ENABLE_CACHE on VCC_GND boards.Damien George
Because these boards use the SPI flash cache in their bdev.c configuration. Signed-off-by: Damien George <damien@micropython.org>
2021-06-10stm32/usb: Add USB_VCP.irq method, to set a callback on USB data RX.Damien George
Usage: usb = pyb.USB_VCP() usb.irq(lambda u:print(u, u.read()), usb.IRQ_RX) Signed-off-by: Damien George <damien@micropython.org>