1. 26 Jul, 2024 4 commits
  2. 25 Jul, 2024 10 commits
  3. 24 Jul, 2024 1 commit
    • Felix Dörre's avatar
      rp2/lwip_inc: Enable IPv6 per default on rp2 port. · 7fe8f030
      Felix Dörre authored
      Having IPv6 support is important, especially for IoT-Devices which might be
      many, requiring individual IP-addresses. In particular direct access via
      link-local addresses and having deterministic SLAAC-addresses can be quite
      convenient. Also in IPv6-only networks or for connecting to IPv6-only
      services, this is very useful.
      
      For the Pico W, there is enough flash and RAM that enabling IPv6 by default
      is the right choice.
      
      Should IPv6 support in a network exist (i.e. there are Router
      Advertisements), but not provide connectivity, connecting by domain name
      should not be a problem as DNS will default to return the IPv4-address (if
      that exists), unless reconfigured at runtime to prefer IPv6.
      
      In any case a user can disable obtaining SLAAC-addresses with:
      
          <nic>.ipconfig(autoconf6=False)
      Signed-off-by: default avatarFelix Dörre <felix@dogcraft.de>
      7fe8f030
  4. 23 Jul, 2024 11 commits
    • Angus Gratton's avatar
      rp2: Stop machine.idle() blocking indefinitely. · ba985334
      Angus Gratton authored
      Updates rp2 port to always resume from idle within 1ms max.
      
      When rp2 port went tickless the behaviour of machine.idle() changed as
      there is no longer a tick interrupt to wake it up every millisecond. On a
      quiet system it would now block indefinitely. No other port does this.
      
      See parent commit for justification of why this change is useful.
      
      Also adds a test case that fails without this change.
      
      This work was funded through GitHub Sponsors.
      Signed-off-by: default avatarAngus Gratton <angus@redyak.com.au>
      ba985334
    • Angus Gratton's avatar
      docs: Specify that machine.idle() returns at least every 1ms. · 81daba31
      Angus Gratton authored
      A lot of existing code (i.e. micropython-lib lps22h, lcd160cr sensor
      drivers, lora sync_modem driver, usb-device-hid) calls machine.idle()
      inside a tight loop that is polling some condition. This reduces the power
      usage compared to constantly looping, but can be faster than calling a
      sleep function. However on a tickless port there's not always an interrupt
      before the condition they are polling for, so it's difficult to restructure
      this code if machine.idle() doesn't have any upper limit on execution time.
      
      This commit specifies an upper limit of 1ms before machine.idle() resumes
      execution. This is already the case for all ports except rp2.
      
      This work was funded through GitHub Sponsors.
      Signed-off-by: default avatarAngus Gratton <angus@redyak.com.au>
      81daba31
    • Phil Howard's avatar
      rp2/rp2_pio: Disable correct IRQ for PIO1. · e1ecc232
      Phil Howard authored
      Fix a typo that was disabling PIO0_IRQ_1 instead of PIO1_IRQ_0.
      Signed-off-by: default avatarPhil Howard <phil@gadgetoid.com>
      e1ecc232
    • Angus Gratton's avatar
      rp2: Fix wakeup from WFE on core1. · 9db16cfe
      Angus Gratton authored
      If core1 executes `mp_wfe_or_timeout()` then it needs to receive an
      interrupt or a SEV to resume execution, but the soft timer interrupt only
      fires on core 0.  This fix adds a SEV to the soft timer interrupt handler.
      
      This issue was masked by the issue fixed in the previous commit, as WFE
      previously wasn't suspending properly.
      
      Verified via the existing thread_sleep2 test.
      
      This work was funded through GitHub Sponsors.
      Signed-off-by: default avatarAngus Gratton <angus@redyak.com.au>
      9db16cfe
    • Angus Gratton's avatar
      rp2: Fix power consumption when sleeping with a timeout. · eced9d86
      Angus Gratton authored
      Fixes a regression introduced in 3af006ef
      where WFE never blocked in `mp_wfe_or_timeout()` function and would
      busy-wait instead.  This increases power consumption measurably.
      
      Root cause is that `mp_wfe_or_timeout()` calls soft timer functions that
      (after the regression) call `recursive_mutex_enter()` and
      `recursive_mutex_exit()`.  The exit calls
      `lock_internal_spin_unlock_with_notify()` and the default pico-sdk
      implementation of this macro issues a SEV which negates the WFE that
      follows it, meaning the CPU never suspends.
      
      See https://forums.raspberrypi.com/viewtopic.php?p=2233908 for more
      details.
      
      The fix in this comment adds a custom "nowait" variant mutex that doesn't
      do WFE/SEV, and uses this one for PendSV.  This will use more power when
      there's contention for the PendSV mutex as the other core will spin, but
      this shouldn't happen very often.
      
      This work was funded through GitHub Sponsors.
      Signed-off-by: default avatarAngus Gratton <angus@redyak.com.au>
      eced9d86
    • Alessandro Gatti's avatar
      unix/main: Fix GCC builds for RISC-V 64 bits. · 44527ada
      Alessandro Gatti authored
      This contains a workaround to silence a possibly incorrect warning when
      building the Unix port with GCC targeting RISC-V 64 bits.
      
      Fixes issue #12838.
      Signed-off-by: default avatarAlessandro Gatti <a.gatti@frob.it>
      44527ada
    • robert-hh's avatar
      esp32/machine_timer: Limit timer numbers for ESP32C3. · 594c4229
      robert-hh authored
      The ESP32C3 has only two timers in one group.  In the code this is
      reflected as two groups with one timer.
      Signed-off-by: default avatarrobert-hh <robert@hammelrath.com>
      594c4229
    • Angus Gratton's avatar
      tests/run-tests.py: Enable thread tests on esp32. · 46c3df02
      Angus Gratton authored
      Before the fix in parent commit, some of these tests hung indefinitely.
      
      After, they seem to consistently pass.
      
      This work was funded through GitHub Sponsors.
      Signed-off-by: default avatarAngus Gratton <angus@redyak.com.au>
      46c3df02
    • Angus Gratton's avatar
      esp32/mpthreadport: Fix uneven GIL allocation between Python threads. · 337742f6
      Angus Gratton authored
      Explicitly yield each time a thread mutex is unlocked.
      
      Key to understanding this bug is that Python threads run at equal RTOS
      priority, and although ESP-IDF FreeRTOS (and I think vanilla FreeRTOS)
      scheduler will round-robin equal priority tasks in the ready state it does
      not make a similar guarantee for tasks moving between ready and waiting.
      
      The pathological case of this bug is when one Python thread task is busy
      (i.e. never blocks) it will hog the CPU more than expected, sometimes for
      an unbounded amount of time. This happens even though it periodically
      unlocks the GIL to allow another task to run.
      
      Assume T1 is busy and T2 is blocked waiting for the GIL. T1 is executing
      and hits a condition to yield execution:
      
      1. T1 calls MP_THREAD_GIL_EXIT
      2. FreeRTOS sees T2 is waiting for the GIL and moves it to the Ready list
         (but does not preempt, as T2 is same priority, so T1 keeps running).
      3. T1 immediately calls MP_THREAD_GIL_ENTER and re-takes the GIL.
      4. Pre-emptive context switch happens, T2 wakes up, sees GIL is not
         available, and goes on the waiting list for the GIL again.
      
      To break this cycle step 4 must happen before step 3, but this may be a
      very narrow window of time so it may not happen regularly - and
      quantisation of the timing of the tick interrupt to trigger a context
      switch may mean it never happens.
      
      Yielding at the end of step 2 maximises the chance for another task to run.
      
      Adds a test that fails on esp32 before this fix and passes afterwards.
      
      Fixes issue #15423.
      
      This work was funded through GitHub Sponsors.
      Signed-off-by: default avatarAngus Gratton <angus@redyak.com.au>
      337742f6
    • Junwha's avatar
      extmod/vfs: Fix buffer overflow of string comparison in umount. · 29943546
      Junwha authored
      The comparison between the given unmount string and existing mount strings
      were made by the given string, which leads to buffer overflow.
      
      Fixes issue #13006.
      Signed-off-by: default avatarJunwha <qbit@unist.ac.kr>
      29943546
    • Terence Stenvold's avatar
      extmod/vfs_fat: Set default volume label on mkfs if it's defined. · 390390ec
      Terence Stenvold authored
      Using mkfs doesn't set a volume label for FAT filesystems.  This commit
      will set the volume label if `MICROPY_HW_FLASH_FS_LABEL` is defined.
      390390ec
  5. 22 Jul, 2024 2 commits
    • stijn's avatar
      extmod/moductypes: Validate the descriptor tuple. · 444d7bac
      stijn authored
      Fixes various null dereferencing, out-of-bounds memory accesses and
      `assert(0)` failures in the case of an invalid `uctypes` descriptor.
      
      By design `uctypes` can crash because it accesses arbitrary memory, but at
      least describing the descriptor layout should be forced to be correct and
      not crash.
      
      Fixes issue #12702.
      Signed-off-by: default avatarstijn <stijn@ignitron.net>
      444d7bac
    • Michael Vornovitsky's avatar
      extmod/modbtree: Add checks for already-closed database. · 6db91dfe
      Michael Vornovitsky authored
      Fixes use-after-free when accessing the database after it is closed with
      `btree_close`.  `btree_close` always succeeds when called with an
      already-closed database.
      
      The new test checks that operations that access the underlying database
      (get, set, flush, seq) fail with a `ValueError` when the btree is already
      closed.  It also checks that closing and printing the btree succeed when
      the btree is already closed.
      
      Fixes issue #12543.
      Signed-off-by: default avatarMichael Vornovitsky <michaelvornovitskiy@outlook.com>
      6db91dfe
  6. 20 Jul, 2024 3 commits
    • Damien George's avatar
      extmod/modos: Include os.sep entry if MICROPY_VFS is enabled. · 8159dcc2
      Damien George authored
      This simplifies configuration by removing the `MICROPY_PY_OS_SEP` option
      and instead including `os.sep` if `MICROPY_VFS` is enabled.  That matches
      the configuration of all existing ports that enabled `os.sep` (they also
      had `MICROPY_VFS` enabled), and brings consistency to other ports.
      
      Fixes issue #15116.
      Signed-off-by: default avatarDamien George <damien@micropython.org>
      8159dcc2
    • Damien George's avatar
      extmod/modmachine: Use sys.exit as implementation of machine.soft_reset. · 5f3ecc29
      Damien George authored
      It does the same thing, raising `SystemExit`.
      Signed-off-by: default avatarDamien George <damien@micropython.org>
      5f3ecc29
    • Damien George's avatar
      shared/runtime/pyexec: Make a raised SystemExit always do a forced exit. · 69c25ea8
      Damien George authored
      The current situation with SystemExit and soft reset is the following:
      - `sys.exit()` follows CPython and just raises `SystemExit`.
      - On the unix port, raising `SystemExit` quits the application/MicroPython,
        whether at the REPL or in code (this follows CPython behaviour).
      - On bare-metal ports, raising `SystemExit` at the REPL does nothing,
        raising it in code will stop the code and drop into the REPL.
      - `machine.soft_reset()` raises `SystemExit` but with a special flag set,
        and bare-metal targets check this flag when it propagates to the
        top-level and do a soft reset when they receive it.
      
      The original idea here was that a bare-metal target can't "quit" like the
      unix port can, and so dropping to the REPL was considered the same as
      "quit".  But this bare-metal behaviour is arguably inconsistent with unix,
      and "quit" should mean terminate everything, including REPL access.
      
      This commit changes the behaviour to the following, which is more
      consistent:
      - Raising `SystemExit` on a bare-metal port will do a soft reset (unless
        the exception is caught by the application).
      - `machine.soft_reset()` is now equivalent to `sys.exit()`.
      - unix port behaviour remains unchanged.
      
      Tested running the test suite on an stm32 board and everything still
      passes, in particular tests that skip by raising `SystemExit` still
      correctly skip.
      Signed-off-by: default avatarDamien George <damien@micropython.org>
      69c25ea8
  7. 19 Jul, 2024 4 commits
  8. 18 Jul, 2024 4 commits
  9. 17 Jul, 2024 1 commit