Wykres commitów

4071 Commity (master)

Autor SHA1 Wiadomość Data
Damien George b3f2f18f92 renesas-ra: Fix spelling mistakes found by codespell.
And enable codespell for this port in `pyproject.toml`.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-07 14:15:49 +11:00
Damien George 90e517862d webassembly/Makefile: Remove --memory-init-file from linker options.
It's no longer supported by Emscripten (at least at 3.1.55).  And it's not
needed when the output is WASM, which it is by default.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-04 11:33:07 +11:00
Damien George a30c29398a ports: Don't include mpthread.h in mpthreadport.h.
Because `mpthreadport.h` is included by `mpthread.h`.

Also remove unnecessary include of `mpthreadport.h` in esp32's `main.c`.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-29 13:35:36 +11:00
iabdalkader b5edaf68cd stm32/sdram: Support remapping FMC memory banks.
The patch enables SDRAM banks 1 and 2 to be accessible at 0xC0000000 and
0xD0000000 respectively (default mapping) or remapped to addresses
0x60000000 and 0x70000000.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-02-26 12:13:44 +11:00
Damien George 31e718a6ac stm32/mpbthciport: Allow building with MICROPY_PY_MACHINE_UART disabled.
Signed-off-by: Damien George <damien@micropython.org>
2024-02-21 11:57:17 +11:00
Trent Piepho 31e131bd71 esp32/machine_hw_spi: Combine argument parsing for constructor and init.
This combines the argument parsing and checking for the machine.SPI.init()
and machine.SPI() interfaces.

The only real difference was unspecified arguments in init() mean to keep
the same value, while in new they get default values.

Behavior has changed for passing the "id" argument to init().  On other
ports this isn't allowed.  But on esp32 it would change the SPI controller
of the static SPI instance to the new id.  This results in multiple static
spi objects for the same controller and they would fight over which one has
inconsistent mpy vs esp-idf state.  This has been changed to not allow "id"
with init(), like other ports.

In a few causes, a loop is used over arguments that are handled the same
way instead of cut & pasting the same stanza of code for each argument.

The init_internal function had a lot of arguments, which is not efficient
to pass.  Pass the args mp_arg_val_t array instead as a single argument.
This reduced both the number of C lines and the compiled code size.

Summary of code size change:  Two argument lists of 72 bytes are replaced
by a single shared 72 byte list.  New shared argument parsing code is small
enough to be inlined, but is still efficient enough to shrink the overall
code size by 349 bytes of the three argument handlering functions.

add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-349 (-349)
Function                                     old     new   delta
machine_hw_spi_make_new                      255     203     -52
machine_hw_spi_init                          122      67     -55
machine_hw_spi_init_internal                 698     456    -242
Total: Before=1227667, After=1227318, chg -0.03%
add/remove: 2/0 grow/shrink: 0/2 up/down: 92/-144 (-52)
Data                                         old     new   delta
spi_allowed_args                               -      72     +72
defaults$0                                     -      20     +20
allowed_args$1                               240     168     -72
allowed_args$0                              1080    1008     -72
Total: Before=165430, After=165378, chg -0.03%
add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0)

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-02-20 16:55:09 +11:00
IhorNehrutsa d9944983cb esp32/machine_i2c: Fix build warnings when I2C is disabled.
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
2024-02-20 16:38:49 +11:00
Damien George 802a88c3b1 stm32/mboot: Generate FLASH_LAYOUT_STR at runtime on H5 MCUs.
The size of the flash varies among MCU variants.  Instead of requiring a
build-time variable to configure this, compute it at runtime using the
special device information word accessible through the FLASH_SIZE macro.

This feature is currently only implemented for H5 MCUs, but can be extended
to others.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-20 12:32:45 +11:00
Damien George cae690d047 all: Use mp_obj_malloc_with_finaliser everywhere it's applicable.
Signed-off-by: Damien George <damien@micropython.org>
2024-02-20 10:32:55 +11:00
Damien George 2423493774 py/obj: Change sizeof to offsetof in mp_obj_malloc_var macro.
Following b6a9778484, to properly calculate
the size of the variable-length allocation.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-19 23:40:54 +11:00
Damien George 5a3dd8c791 tests/ports/unix: Add coverage test for frozen functions and generators.
Signed-off-by: Damien George <damien@micropython.org>
2024-02-16 14:17:01 +11:00
Damien George e2ff00e811 py/emitglue: Introduce mp_proto_fun_t as a more general mp_raw_code_t.
Allows bytecode itself to be used instead of an mp_raw_code_t in the simple
and common cases of a bytecode function without any children.

This can be used to further reduce frozen code size, and has the potential
to optimise other areas like importing.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-16 14:17:01 +11:00
Damien George cd66aa05cf esp32: Increase NimBLE task stack size and overflow detection headroom.
The Python BLE IRQ handler will most likely run on the NimBLE task, so its
C stack must be large enough to accommodate reasonably complicated Python
code (eg a few call depths).  So increase this stack size.

Also increase the headroom from 1024 to 2048 bytes.  This is needed because
(1) the esp32 architecture uses a fair amount of stack in general; and (2)
by the time execution gets to setting the Python stack top via
`mp_stack_set_top()` in this interlock code, about 600 bytes of stack are
already used, which reduces the amount available for Python.

Fixes issue #12349.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-16 10:19:26 +11:00
YAMAMOTO Takashi 809d113dbc unix: Don't include system headers when features are disabled.
Because the target system may not have these headers at all.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2024-02-15 16:54:17 +11:00
YAMAMOTO Takashi f9704ce36e unix/input: Flush the prompt after writing it to stdout.
Depending on your setup, stdout might be buffered/line-buffered.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2024-02-15 16:45:00 +11:00
YAMAMOTO Takashi 06cb6b1e9f minimal: Use printf instead of echo -e.
macOS's echo doesn't have -e option.  printf is in POSIX and more widely
available these days.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2024-02-15 16:36:22 +11:00
YAMAMOTO Takashi e3be70b5e8 minimal: Allow compiling on macOS.
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2024-02-15 16:35:10 +11:00
Damien George c27d304bed esp32/mpnimbleport: Release the GIL while doing NimBLE port deinit.
In case callbacks must run (eg a disconnect event happens during the
deinit) and the GIL must be obtained to run the callback.

Fixes part of issue #12349.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-15 16:05:41 +11:00
Trent Piepho 34097b776e esp32/network_ppp: Make PPP support optional.
PPP is not that commonly used, let it be turned off in the board config to
save space.  It is still on by default.

On an basic ESP32-S3 build, turning off PPP with LWIP still on saves ~35 kB
of codend 4 kB of data.

   text    data     bss     dec     hex filename
1321257  304296 2941433 4566986  45afca before-ppp-off.elf
1285101  299920 2810305 4395326  43113e after-ppp-off.elf
-------------------------------
-36156    -4376     -56

Note that the BSS segment size includes all NOBITS sections in ELF file.
Some of these are aligned to 64kB chunk sized dummy blocks, I think for
alignment to MMU boundaries, and these went down by 1 block each, so 128
kiB of BSS is not really part of the binary size reduction.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-02-15 13:29:43 +11:00
Angus Gratton 00ba6aaae4 ports: On cold boot, enable USB after boot.py completes.
For mimxrt, nrf, renesas-ra, rp2 and samd ports, this commit implements
similar behaviour to the stm32 port, where USB is only brought up after
boot.py completes execution.

Currently this doesn't add any useful functionality (and may break
workflows that depend on USB-CDC being live in boot.py), however it's a
precondition for more usable workflows with USB devices defined in
Python (allows setting up USB interfaces in boot.py before the device
enumerates for the first time).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-15 12:31:26 +11:00
YAMAMOTO Takashi d2a3cd7ac4 embed: Improve stack top estimation.
Obtaining the stack-top via a few function calls may yield a pointer which
is too deep within the stack.  So require the user to obtain it from a
higher level (or via some other means).

Fixes issue #11781.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2024-02-15 10:07:32 +11:00
iabdalkader be8d660fc2 mimxrt: Fix header include guard names.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-02-15 09:45:14 +11:00
Damien George 8cbae12d0d unix/variants: Prefer unix-ffi packages when loading the manifest.
Signed-off-by: Damien George <damien@micropython.org>
2024-02-08 17:16:10 +11:00
Damien George b038d07011 stm32/Makefile: Ignore uninitialised variable warning in H5 HAL SD code.
This warning appears when using an MCU like H562 that only has one SDMMC.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-07 14:55:07 +11:00
Damien George 657faee7e5 stm32/main: Allow disabling MICROPY_PY_MACHINE.
Disabling this requires also disabling: MICROPY_PY_PYB and MICROPY_PY_STM.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-07 13:45:51 +11:00
Damien George 4e6436d4cf stm32/spi: Allow disabling MICROPY_PY_MACHINE_SPI.
This requires that MICROPY_PY_PYB is also disabled.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-07 13:45:51 +11:00
Damien George 2158da213e stm32/modos: Allow disabling MICROPY_PY_MACHINE_UART.
Signed-off-by: Damien George <damien@micropython.org>
2024-02-07 13:45:51 +11:00
Damien George 7d28789544 ports: Use vfs module instead of os.
Signed-off-by: Damien George <damien@micropython.org>
2024-02-07 13:25:09 +11:00
Damien George e7020463f1 extmod/modvfs: Add new "vfs" module with mount/umount and Vfs classes.
They have been moved from the "os" module.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-07 13:25:08 +11:00
Felix Dörre b802f0f8ab extmod/modtls: Move the native ssl module to tls.
The current `ssl` module has quite a few differences to the CPython
implementation.  This change moves the MicroPython variant to a new `tls`
module and provides a wrapper module for `ssl` (in micropython-lib).

Users who only rely on implemented comparible behavior can continue to use
`ssl`, while users that rely on non-compatible behavior should switch to
`tls`.  Then we can make the facade in `ssl` more strictly adhere to
CPython.

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-02-07 12:58:52 +11:00
David Lechner ed15b3c6c6 github/workflows: Move Windows CI from AppVeyor to GitHub Actions.
By moving to GitHub actions, all MicroPython CI builds are now on GitHub
actions.  This allows faster parallel builds and saves time by not building
when no relevant files changed.

This reveals a few failing tests, so those are temporarily disabled until
they can be fixed.

Signed-off-by: David Lechner <david@pybricks.com>
Signed-off-by: Damien George <damien@micropython.org>
2024-02-06 09:50:03 +11:00
David Lechner 23342eff90 windows/Makefile: Fix float exact int formatting on 32-bit mingw.
When compiler optimizations are enabled on the mingw version of gcc, we are
getting failing tests because of rounding issues, for example:

    print(float("1e24"))

would print

    9.999999999999999e+23

instead of

    1e+24

It turns out special compiler options are needed to get GCC to use the SSE
instruction set instead of the 387 coprocessor (which uses 80-bit precision
internall).

Signed-off-by: David Lechner <david@pybricks.com>
2024-02-05 14:04:15 +11:00
Jim Lipsey 0285cb2bf4 stm32/boards/ARDUINO_PORTENTA_H7: Add pin configuration for SPI1.
Currently, only the processor's SPI2 bus is enabled (though the related
pins are labeled SPI1 in the Portenta H7 documentation).  This commit
enables the processor's SPI1 bus, which is accessible via the board's
high-density connectors.

Signed-off-by: Jim Lipsey <github@lipsey.org>
2024-02-01 11:21:44 +11:00
Joey232 3e48d24576 esp32/boards/UM_FEATHERS3: Use read_uv() for accurate battery voltage.
Use read_uv() to get the battery voltage because it uses the on-chip
calibraton values.

Signed-off-by: Joey232 <Joey@jsconsulting.com>
2024-01-31 14:24:16 +11:00
Takeo Takahashi 81049edf7c renesas-ra/ra/ra_i2c: Fix 1 byte and 2 bytes read issue.
Tested on Portenta C33 with AT24256B (addrsize=16) and SSD1306.

Fixes issue #13280.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2024-01-31 14:16:36 +11:00
Damien George 807c25d05a rp2: Change machine.I2S and rp2.DMA to use shared DMA IRQ handlers.
These separate drivers must share the DMA resource with each other.

Fixes issue #13380.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-30 12:44:22 +11:00
Carlosgg f3d1495fd3 all: Update bindings, ports and tests for mbedtls v3.5.1.
Changes include:

- Some mbedtls source files renamed or deprecated.

- Our `mbedtls_config.h` files are renamed to `mbedtls_config_port.h`, so
  they don't clash with mbedtls's new default configuration file named
  `mbedtls_config.h`.

- MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE is deprecated.

- MBEDTLS_HAVE_TIME now requires an `mbedtls_ms_time` function to be
  defined but it's only used for TLSv1.3 (currently not enabled in
  MicroPython so there is a lazy implementation, i.e. seconds * 1000).

- `tests/multi_net/ssl_data.py` is removed (due to deprecation of
  MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE), there are the existing
  `ssl_cert_rsa.py` and `sslcontext_server_client.py` tests which do very
  similar, simple SSL data transfer.

- Tests now use an EC key by default (they are smaller and faster), and the
  RSA key has been regenerated due to the old PKCS encoding used by openssl
  rsa command, see
  https://stackoverflow.com/questions/40822328/openssl-rsa-key-pem-and-der-conversion-does-not-match
  (and `tests/README.md` has been updated accordingly).

Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2024-01-30 11:08:46 +11:00
Damien George 46e833b071 qemu-arm/mpconfigport: Use MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES.
This simplifes the port configuration.  It enables quite a few new
features, including the `math` and `cmath` modules, adding about 20k to the
firmware size.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-29 13:07:31 +11:00
Damien George 7211bafb33 esp8266/boards/ESP8266_GENERIC: Disable MICROPY_DEBUG_PRINTERS.
This is not enabled on any other MCU port, and is essentially unused on
esp8266 because mp_verbose_flag is always 0.  Disabling saves ~7k of flash.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-29 12:19:06 +11:00
iabdalkader 4a2e510a87 ports: Add LED pin aliases for all Arduino boards.
The standard Arduino pinout uses LEDR/G/B and LED_BUILTIN (if available).
This patch adds aliases to match the standard pinout, while retaining
LED_RED/GREEN/BLUE for compatibility with existing scripts and examples.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-26 14:11:42 +11:00
iabdalkader 8d9d74b6df rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Increase flash storage space.
Fixes issue #13512.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-26 14:05:20 +11:00
Kwabena W. Agyeman bf6214505f mimxrt/modmachine: Fix deepsleep wakeup pin ifdef.
Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
2024-01-26 13:59:41 +11:00
Jim Mussared d4190815a3 py/mpconfig: Disable qstr hashing at minimum feature level.
This will apply to bare-arm and minimal, as well as the minimal unix
variant.

Change the default to MICROPY_QSTR_BYTES_IN_HASH=1 for the CORE,BASIC
levels, 2 for >=EXTRA.

Removes explicit setting of MICROPY_QSTR_BYTES_IN_HASH==1 in ports that
don't set the feature level (because 1 is implied by the default level,
CORE). Applies to cc3200, pic16bt, powerpc.

Removes explicit setting for nRF (which sets feature level). Also for samd,
which sets CORE for d21 and FULL for d51. This means that d21 is unchanged
with MICROPY_QSTR_BYTES_IN_HASH==1, but d51 now moves from 1 to 2 (roughly
adds 1kiB).

The only remaining port which explicitly set bytes-in-hash is rp2 because
it's high-flash (hence CORE level) but lowish-SRAM, so it's worthwhile
saving the RAM for runtime qstrs.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2024-01-25 16:38:17 +11:00
Jim Mussared 8486e28b17 stm32: Disable qstr hashing on small boards.
Sets MICROPY_QSTR_BYTES_IN_HASH==0 on stm32x0 boards.

This saves e.g. 2kiB on NUCLEO_F091.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2024-01-25 16:38:17 +11:00
Damien George 982ffdee7e stm32/mboot/Makefile: Revert change to BOARD_DIR that removed abspath.
This reverts the change from ce2058685b.

Without abspath, the build artefacts (object files) for boards with source
files are placed outside the build directory, because the BOARD_DIR
variable starts with "..".  For the list of source files added to SRC_C,
none of them can start with "..".  The usual fix for that would be to make
the files relative to the top of the MicroPython repo (because of the vpath
rule), eg ports/stm32/boards/$(BOARD).  But then the $(wildcard ...)
pattern won't find files in this directory.

So abspath is necessary, although it will prevent building when there is a
space in the path.  A better solution for spaces needs to be found.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-25 11:30:14 +11:00
Iksas ce2058685b ports: Fix handling of paths containing spaces in Makefiles.
Make can't handle paths with spaces, see https://savannah.gnu.org/bugs/?712

The following workarounds exist:

- When using make's built-in functions:
    - Use relative paths wherever possible to avoid spaces in the first
      place.
    - All spaces in paths can be escaped with backslashes; quotes don't
      work.
    - Some users use the shell to temporarily rename directories, or to
      create symlinks without spaces.

- When using make to pass commands to the system's shell, enclose paths in
  quotes.  While make will still interpret quoted strings with spaces as
  multiple words, the system's shell will correctly parse the resulting
  command.

This commit contains the following fixes:

- In ports/stm32/mboot/Makefile: Use relative paths to avoid spaces when
  using built-in functions.

- In all other files: Use quotes to enclose paths when make is used to call
  shell functions.

All changes have been tested with a directory containing spaces.

Signed-off-by: Iksas <iksas@mailbox.org>
2024-01-24 10:43:18 +11:00
Maarten van der Schrieck 057701a770 rp2/machine_uart: Fix potential race condition in interrupt handling.
The irq service routine cleared the RT interrupt bit on TX interrupt.  This
opens the possibility that an RT interrupt is missed.

Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
2024-01-23 13:11:53 +11:00
iabdalkader e111793d8d nrf: Fix _start() build issue with CMSIS 5.9.0.
The `_start` function prototype is now declared as no-return, so `main()`
can't return.

To fix this, `main()` is replaced with `_start`.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-22 12:40:16 +11:00
iabdalkader beb4459784 mimxrt/boards: Fix __VECTOR_TABLE link issue with CMSIS 5.9.0.
In CMSIS 5.9.0, the compiler headers define `__VECTOR_TABLE`, which will be
substituted with its corresponding value (e.g., `__Vectors` for gcc).
However, the linker script in this port can't include compiler headers when
it's processed, so `__VECTOR_TABLE` is used as the literal variable name,
which results in an undefined linker error.

To fix this, the two possible values of `__VECTOR_TABLE` are both defined
in the linker script.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-22 12:36:43 +11:00
iabdalkader 4fd7e456f0 renesas-ra/boards/ARDUINO_PORTENTA_C33: Fix the RTC clock source.
Switch the RTC clock source to Sub-clock (XCIN). This board has an
accurate LSE crystal, and it should be used for the RTC clock
source.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-21 00:19:20 +11:00
iabdalkader c6f6f345e6 renesas-ra/ra: Remove unnecessary min_delay() declaration.
This function is private to ra_adc.c.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-17 11:19:02 +11:00
iabdalkader 1f04808151 renesas-ra/ra: Fix SysTick clock source.
The SysTick_Config function must use the system/CPU clock to configure the
ticks.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-17 11:17:59 +11:00
Angus Gratton a75ca8a1c0 esp32/modsocket: Use all supplied arguments to socket.getaddrinfo().
- Completes a longstanding TODO in the code, to not ignore
  the optional family, type, proto and flags arguments to
  socket.getaddrinfo().

- Note that passing family=socket.AF_INET6 will now cause queries
  to fail (OSError -202). Previously this argument was ignored so
  IPV4 results were returned instead.

- Optional 'type' argument is now always copied into the result. If not
  set, results have type SOCK_STREAM.

- Fixes inconsistency where previously querying mDNS local suffix (.local)
  hostnames returned results with socket type 0 (invalid), but all other
  queries returned results with socket type SOCK_STREAM (regardless of
  'type' argument).

- Optional proto argument is now returned in the result tuple, if supplied.

- Optional flags argument is now passed through to lwIP. lwIP has handling
  for AI_NUMERICHOST, AI_V4MAPPED, AI_PASSIVE (untested, constants for
  these are not currently exposed in the esp32 socket module).

- Also fixes a possible memory leak in an obscure code path
  (lwip_getaddrinfo apparently sometimes returns a result structure with
  address "0.0.0.0" instead of failing, and this structure would have been
  leaked.)

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-01-17 11:00:58 +11:00
Angus Gratton bdaea866b7 rp2/mpthreadport: Make result of thread.get_ident() a non-zero integer.
CPython says thread identifier is a "nonzero integer", so rp2 should use a
1-indexed core number rather than 0-indexed.  This fixes the
thread/thread_ident1 test failure on rp2 port.

Unfortunately this may be a breaking change for rp2 code which makes a
hard-coded comparison of thread identifier to 0 or 1.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-01-17 08:02:16 +11:00
Damien George efa54c27b9 rp2/mpconfigport: Allow MICROPY_PY_THREAD to be disabled by a board.
Signed-off-by: Damien George <damien@micropython.org>
2024-01-16 11:42:47 +11:00
Damien George a70367e293 nrf/modules/os/microbitfs: Sweep the filesystem if any free chunk found.
If there are any free chunks found then it's better to sweep the filesystem
and use the available chunks, rather than error out with ENOSPC when there
is in fact a bit of space remaining.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-16 11:42:47 +11:00
robert-hh 07472d05db rp2/machine_uart: Fix event wait in uart.flush() and uart.read().
Do not wait in the worst case up to the timeout.

Fixes issue #13377.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-01-16 08:53:34 +11:00
Damien George 2ed976f140 samd/mcu/samd21: Enable MICROPY_STACK_CHECK on SAMD21.
Increases firmware size by +140 bytes and uses +4 extra bytes of RAM, but
allows the test suite to run without crashing.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 23:24:39 +11:00
Damien George e456ee40e0 samd/mpconfigport: Simplify and consolidate config options.
This is a no-op in terms of firmware functionality.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 23:24:39 +11:00
Damien George 7ecff515d7 stm32/flash: Fix sector and bank calculation for H5 and H7 MCUs.
Flash sectors should start counting at 0 for each bank.  This commit makes
sure that is the case on all H5 and H7 MCUs, by using `get_page()` instead
of `flash_get_sector_info()`.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:35:48 +11:00
Damien George 5cb93f63fb stm32/flash: Factor and simplify erase code.
Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:35:22 +11:00
Damien George cd6e0e1022 stm32/flashbdev: Don't rely on flash sector id.
This commit removes the need for a separate `flash_cache_sector_id`
variable, instead using `flash_cache_sector_start` to indicate which sector
is curretly cached (and -1 indicates no sector).

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:34:18 +11:00
Damien George b6ab9e420b stm32/flash: Change flash_erase to only erase a single sector at a time.
An erase sector sits in a given flash bank and some MCUs have two flash
banks.  If trying to erase a range of sectors and that range crosses from
one flash bank into the next, the original implementation of
`flash_erase()` would not handle this case and would do the wrong thing.

This commit changes `flash_erase()` to only erase a single sector, which
sidesteps the need to handle flash-bank-crossing.  Most callers of this
function only need to erase a single sector anyway.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:33:34 +11:00
Damien George cf115918e6 stm32/flash: Simplify sector calculation for homogeneous flash layout.
Newer STM32 parts have homogeneous flash layout, and in this case the MCU
configuration and page/sector calculation can be simplified.  The affected
functions are `flash_is_valid_addr()` and `flash_get_sector_info()`, which
are now simpler for homogeneous flash.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:31:10 +11:00
Damien George cd0f75069c stm32/flash: Remove commented-out flash functions.
Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:31:03 +11:00
Damien George 7002a19be2 stm32/mboot: Improve mass erase to erase all non-protected pages.
Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:29:19 +11:00
Damien George b7b99522e4 stm32/mboot: Improve detection of invalid flash erase/write.
This commit replaces the linker symbol `_mboot_writable_flash_start` with
`_mboot_protected_flash_start` and `_mboot_protected_flash_end_exclusive`,
to provide better configuration of the protected flash area.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:22:55 +11:00
Nicko van Someren 1da45e887a rp2: Provide direct memory access to PIO and SPI FIFOs via proxy arrays.
Signed-off-by: Nicko van Someren <nicko@nicko.org>
2024-01-07 18:27:01 +11:00
Nicko van Someren f8cabe82f7 rp2/rp2_dma: Fix fetching 'write' buffers for writing not reading.
Signed-off-by: Nicko van Someren <nicko@nicko.org>
2024-01-07 18:25:52 +11:00
darc 80fd575c8c embed: Fix alloca include for FreeBSD and NetBSD.
Signed-off-by: darc <darcagn@protonmail.com>
2024-01-05 01:03:25 -06:00
Damien George 42eab32a36 windows/windows_mphal: Fix mp_hal_delay_ms() so it runs events.
This changed behaviour in c393f5c123 when the
MICROPY_EVENT_POLL_HOOK macro was removed.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-05 15:56:34 +11:00
Damien George 0640ff3b97 ports: Move MICROPY_INTERNAL_WFE definition to mphalport.h.
It belongs here because the default value is defined in py/mphal.h.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-05 15:49:42 +11:00
Damien George d45176fc27 ports: Move MICROPY_PY_LWIP_ENTER/REENTER/EXIT defns to mphalport.h.
Following ad806df857 where the
MICROPY_PY_PENDSV_ENTER/REENTER/EXIT macro definitions were moved to
mphalport.h.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-05 15:40:06 +11:00
Damien George dc2a4e3cbd rp2/mpthreadport: Fix race with IRQ when entering atomic section.
Prior to this commit there is a potential deadlock in
mp_thread_begin_atomic_section(), when obtaining the atomic_mutex, in the
following situation:
- main thread calls mp_thread_begin_atomic_section() (for whatever reason,
  doesn't matter)
- the second core is running so the main thread grabs the mutex via the
  call mp_thread_mutex_lock(&atomic_mutex, 1), and this succeeds
- before the main thread has a chance to run save_and_disable_interrupts()
  a USB IRQ comes in and the main thread jumps off to process this IRQ
- that USB processing triggers a call to the dcd_event_handler() wrapper
  from commit bcbdee2357
- that then calls mp_sched_schedule_node()
- that then attempts to obtain the atomic section, calling
  mp_thread_begin_atomic_section()
- that call then blocks trying to obtain atomic_mutex
- core0 is now deadlocked on itself, because the main thread has the mutex
  but the IRQ handler (which preempted the main thread) is blocked waiting
  for the mutex, which will never be free

The solution in this commit is to use mutex enter/exit functions that also
atomically disable/restore interrupts.

Fixes issues #12980 and #13288.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-03 15:59:11 +11:00
Damien George 8438c8790c rp2/mutex_extra: Implement additional mutex functions.
These allow entering/exiting a mutex and also disabling/restoring
interrupts, in an atomic way.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-03 15:59:02 +11:00
Damien George c3989e398f rp2/rp2_flash: Lockout second core only when doing flash erase/write.
Using the multicore lockout feature in the general atomic section makes it
much more difficult to get correct.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-03 15:58:39 +11:00
robert-hh 3d0b6276f3 samd/mcu: Fix wrong EIC table entries in pin-af-table.csv.
Fixes:
- SAMD21: PB16
- SAMD51: PB03, PB22 and PB00.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-01-02 18:48:17 +11:00
robert-hh aea93a88f8 samd/mcu/samd21: Reorganize and enable more firmware features.
This commit enables additional features for SAMD21 with external flash:
- Viper and native code support.  On a relatively slow devices, viper and
  native code can be helpful.
- Freeze the asyncio scripts and add the select module.
- Enable Framebuffer support.
- Enable UART flow control.
- Enable a few more features from the extra features set.

Drop onewire and asyncio support from SAMD21 firmware without external
flash, leaving a little bit more room for future extensions.  Asyncio was
anyhow incomplete.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-01-02 18:46:33 +11:00
robert-hh 36d9e98fc6 samd: Remove the MICROPY_PY_MACHINE_RTC config option.
RTC is enabled on all boards.  Therefore the conditional compile is not
needed.  Removing it simplifies the source code a little bit.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-01-02 18:46:11 +11:00
iabdalkader f34e27f178 mimxrt/mpbthciport: Add missing extmod/modmachine.h header.
Include extmod/modmachine.h for machine_uart_type declaration.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-02 18:24:19 +11:00
iabdalkader 87d3f8b367 mimxrt/mphalport: Remove redundant NVIC/IRQ defines.
These are already defined in `irq.h`.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-02 18:19:58 +11:00
Daniël van de Giessen d014c82826 extmod/nimble: Do not set GAP device name after sync.
Instead, configure the default once at compile-time. This means the GAP
name will no longer be set to default after re-initializing Bluetooth.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-12-22 16:07:02 +11:00
Nicko van Someren cfc212b108 rp2/rp2_dma: Introduce a new rp2.DMA class for control over DMA xfers.
This commit implements fairly complete support for the DMA controller in
the rp2 series of microcontrollers.  It provides a class for accessing the
DMA channels through a high-level, Pythonic interface, and functions for
setting and manipulating the DMA channel configurations.

Creating an instance of the rp2.DMA class claims one of the processor's DMA
channels.  A sensible, per-channel default value for the ctrl register can
be fetched from the DMA.pack_ctrl() function, and the components of this
register can be set via keyword arguments to pack_ctrl().

The read, write, count and ctrl attributes of the DMA class provide
read/write access to the respective registers of the DMA controller.  The
config() method allows any or all of these values to be set simultaneously
and adds a trigger keyword argument to allow the setup to immediately be
triggered.  The read and write attributes (or keywords in config()) accept
either actual addresses or any object that supports the buffer interface.
The active() method provides read/write control of the channel's activity,
allowing the user to start and stop the channel and test if it is running.

Standard MicroPython interrupt handlers are supported through the irq()
method and the channel can be released either by deleting it and allowing
it to be garbage-collected or with the explicit close() method.

Direct, unfettered access to the DMA controllers registers is provided
through a proxy memoryview() object returned by the DMA.registers attribute
that maps directly onto the memory-mapped registers.  This is necessary for
more fine-grained control and is helpful for allowing chaining of DMA
channels.

As a simple example, using DMA to do a fast memory copy just needs:

    src = bytearray(32*1024)
    dest = bytearray(32*1024)
    dma = rp2.DMA()
    dma.config(read=src, write=dest, count=len(src) // 4,
        ctrl=dma.pack_ctrl(), trigger=True)

    # Wait for completion
    while dma.active():
        pass

This API aims to strike a balance between simplicity and comprehensiveness.

Signed-off-by: Nicko van Someren <nicko@nicko.org>
Signed-off-by: Damien George <damien@micropython.org>
2023-12-22 13:04:51 +11:00
Sebastian Romero e4d3ab3304 nrf/main: Add /flash and /flash/lib to sys.path.
This allows to follow good practice and have libraries live in the lib
folder which means they will be found by the runtime without adding this
path manually at runtime.

Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
2023-12-22 11:15:19 +11:00
Maarten van der Schrieck 3bca93b2d0 ports: Fix sys.stdout.buffer.write() return value.
MicroPython code may rely on the return value of sys.stdout.buffer.write()
to reflect the number of bytes actually written. While in most scenarios a
write() operation is successful, there are cases where it fails, leading to
data loss. This problem arises because, currently, write() merely returns
the number of bytes it was supposed to write, without indication of
failure.

One scenario where write() might fail, is where USB is used and the
receiving end doesn't read quickly enough to empty the receive buffer. In
that case, write() on the MicroPython side can timeout, resulting in the
loss of data without any indication, a behavior observed notably in
communication between a Pi Pico as a client and a Linux host using the ACM
driver.

A complex issue arises with mp_hal_stdout_tx_strn() when it involves
multiple outputs, such as USB, dupterm and hardware UART. The challenge is
in handling cases where writing to one output is successful, but another
fails, either fully or partially. This patch implements the following
solution:

mp_hal_stdout_tx_strn() attempts to write len bytes to all of the possible
destinations for that data, and returns the minimum successful write
length.

The implementation of this is complicated by several factors:
- multiple outputs may be enabled or disabled at compiled time
- multiple outputs may be enabled or disabled at runtime
- mp_os_dupterm_tx_strn() is one such output, optionally containing
  multiple additional outputs
- each of these outputs may or may not be able to report success
- each of these outputs may or may not be able to report partial writes

As a result, there's no single strategy that fits all ports, necessitating
unique logic for each instance of mp_hal_stdout_tx_strn().

Note that addressing sys.stdout.write() is more complex due to its data
modification process ("cooked" output), and it remains unchanged in this
patch. Developers who are concerned about accurate return values from
write operations should use sys.stdout.buffer.write().

This patch might disrupt some existing code, but it's also expected to
resolve issues, considering that the peculiar return value behavior of
sys.stdout.buffer.write() is not well-documented and likely not widely
known. Therefore, it's improbable that much existing code relies on the
previous behavior.

Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
2023-12-22 10:32:46 +11:00
IhorNehrutsa 5552896ca8 esp32/mpconfigport: Enable MICROPY_PY_HASHLIB_MD5.
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
2023-12-21 11:33:05 +11:00
Damien George e9bcd49b3e stm32/mboot: Add support for Microsoft WCID.
This adds support to stm32's mboot for the Microsoft WCID USB 0xee string
and Compatible ID Feature Descriptor.  This allows the USB device to
automatically set the default USB driver, so that when the device is
plugged in Windows will assign the winusb driver to it.  This means that
USB DFU mode can be used without installing any drivers.

For example this page will work (allow the board to be updated over DFU)
with zero install: https://devanlai.github.io/webdfu/dfu-util/

Tested on Windows 10, Windows can read the 0xee string correctly, and
requests the second special descriptor, which then configures the USB
device to use the winusb driver.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-20 19:40:03 +11:00
Damien George 49d0c22b11 stm32/mboot: Expand device descriptor to make it easier to understand.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-20 19:31:15 +11:00
Damien George 859f219690 stm32/mboot: Guard use of tx_pending with USE_USB_POLLING option.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-20 17:25:57 +11:00
Damien George 7cf1118831 stm32/usbdev: Optionally pass through vendor requests to Setup function.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-20 17:25:10 +11:00
Damien George f6d630877c esp32: Add MICROPY_GC_INITIAL_HEAP_SIZE option and tune it.
This gets back the old heap-size behaviour on ESP32, before auto-split-heap
was introduced: after the heap is grown one time the size is 111936 bytes,
with about 40k left for the IDF.  That's enough to start WiFi and do a
HTTPS request.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-19 18:34:23 +11:00
Patrick Van Oosterwijck 3270d856fd rp2/boards: Add SIL_RP2040_SHIM board by Silicognition LLC.
Add new board Silicognition RP2040-Shim, RP2040 with 4 MB of flash
and W5500 drivers included and configured by default for use with
the Silicognition PoE-FeatherWing.

Co-authored-by: Matt Trentini <matt.trentini@gmail.com>

Signed-off-by: Patrick Van Oosterwijck <patrick@silicognition.com>
2023-12-18 16:32:20 +11:00
Paul Grayson c51081c604 rp2/boards: Add support for Pololu 3pi+ and Zumo robots.
Signed-off-by: Paul Grayson <paul@pololu.com>
2023-12-18 14:08:04 +11:00
Paul Grayson fbf079d773 rp2: Add new NO_DEFAULT_PINS config options for i2c, spi, and uart.
Some boards have multiple options for these pins, and they don't want to
allow users to initialize a port without explicitly specifying pin numbers.

Signed-off-by: Paul Grayson <paul@pololu.com>
2023-12-18 14:07:03 +11:00
Damien George a78ec4ef7b rp2/mpconfigport: Enable MICROPY_PY_OS_DUPTERM_NOTIFY.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-18 12:20:47 +11:00
Damien George 395886caa3 extmod/modos: Factor os.dupterm_notify() function to common extmod code.
esp8266 doesn't need ets task because the notify is now scheduled (see
commits 7d57037906 and
c60caf1995 for relevant history).

Signed-off-by: Damien George <damien@micropython.org>
2023-12-18 12:20:47 +11:00
Damien George c9eb6bc601 esp32: Re-enable custom mbedtls error string tables.
To match other ports that use mbedtls.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-12 16:25:07 +11:00
IhorNehrutsa 4365edb810 esp32: Change minimum supported IDF version to v5.0.4.
Also, IDF v5.1.2 is now supported, just not used by default.

IDF v5.0.2 still builds but we cannot guarantee continued support for this
version moving forward.

Signed-off-by: IhorNehrutsa <IhorNehrutsa@gmail.com>
2023-12-11 13:00:09 +11:00
Damien George d0758d8a33 esp32/boards/ESP32_GENERIC: Disable network.LAN and VM-opt on D2WD.
To reduce firmware size, because IDF v5.0.4 has increased in size.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-11 13:00:06 +11:00
Damien George b4b77c17b5 esp32/mpconfigport: Keep some funcs out of IRAM for ESP32-SPIRAM builds.
To make sure the build fits.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-11 12:59:51 +11:00
Ihor Nehrutsa 3069fee386 esp32/machine_i2s: Fix deprecated fields and constants.
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
2023-12-11 12:59:29 +11:00
Ihor Nehrutsa a427117d03 esp32/modmachine: Fix deprecated esp_pm_config_XXX_t.
Co-Authored-By: Trent Piepho <35062987+xyzzy42@users.noreply.github.com>

Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
2023-12-11 12:59:14 +11:00
IhorNehrutsa 495be71d56 esp32/machine_dac: Support one-shot mode of driver.
And simplify board configuration of DAC by using SOC_DAC_SUPPORTED.

Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
2023-12-11 12:57:43 +11:00
IhorNehrutsa 3106ee4885 esp32/modnetwork: Add WiFi AUTH_WPA3_ENT_192 authenticate mode.
Available in newer versions of the IDF.

Signed-off-by: IhorNehrutsa <IhorNehrutsa@gmail.com>
2023-12-11 12:57:05 +11:00
IhorNehrutsa 88778be73a esp32/machine_i2c: Use APB_CLK_FREQ instead of I2C_APB_CLK_FREQ.
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
2023-12-11 12:56:38 +11:00
Carlosgg c393cd7e48 esp32/boards/sdkconfig.base: Disable unused mbedtls options.
Disable unused EC curves and default certificate bundle which is not
implemented in MicroPython.  This reduces the firmware size significantly.

This follows commit 68f166dae9.

Signed-off-by: Carlos Gil Gonzalez <carlosgilglez@gmail.com>
2023-12-11 12:06:35 +11:00
Damien George e1a7aa23fd ports: Switch build to use common lib/libm list of source files.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-08 15:42:41 +11:00
Angus Gratton 2c828a8815 unix: Update port to use the new event functions.
Necessary to get coverage of the new event functions.

Deletes the case that called usleep(delay) for mp_hal_delay_ms(), it seems
like this wouldn't have ever happened anyhow (MICROPY_EVENT_POOL_HOOK is
always defined for the unix port).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 13:17:15 +11:00
Angus Gratton 73879734d9 esp8266: Update port to use new event functions.
This is necessary to avoid watchdog timeout in long i2c.scan(), as
previously machine_i2c.c would call MICROPY_EVENT_POLL_HOOK if
MICROPY_EVENT_POLL_HOOK_FAST was not available.

Compared to previous implementation, this implementation removes the
ets_event_poll() function and calls the SDK function ets_loop_iter() from
MICROPY_INTERNAL_EVENT_HOOK instead.  This allows using the port-agnostic
functions in more places.

There is a small behaviour change, which is that the event loop gets
iterated in a few more places (i.e. anywhere that mp_event_handle_nowait()
is called).  However, this looks like maybe only modselect.c - and is
probably good to process Wi-Fi events in that polling loop.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 12:50:38 +11:00
Angus Gratton c393f5c123 windows: Implement MICROPY_INTERNAL_WFE() macro.
This should be the equivalent of the previous event poll hook macro.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 12:49:54 +11:00
Angus Gratton 393938b3e6 rp2/main: Enable SEVONPEND CPU interrupt bit.
Previously this was not set, so potential for race conditions in interrupt
handlers this didn't issue SEV.  (Which is currently all of them, as far as
I can see.)

Eventually we might be able to augment the interrupt handlers that wake the
main thread to call SEV, and leave the others as-is to suspend the CPU
slightly faster, but this will solve the issue for now.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 12:49:49 +11:00
Angus Gratton 28529351ae rp2: Switch rp2 and drivers to use new event functions.
This commit changes all uses in the rp2 port, and drivers that are
optionally supported by that port.

The old MICROPY_EVENT_POLL_HOOK and MICROPY_EVENT_POLL_HOOK_FAST macros are
no longer used for rp2 builds and are removed (C user code will need to be
changed to suit).

Also take the opportunity to change some timeouts that used 64-bit
arithmetic to 32-bit, to hopefully claw back a little code size.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 12:49:43 +11:00
Angus Gratton 66be82da7c esp8266: Avoid including ep_mphal.h directly.
This header has no include guards and is apparently only supposed to be
included from py/mphal.h.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-07 14:07:21 +11:00
Damien George 3f2c423686 rp2: Switch to locally provided math library.
This commit fixes all known floating-point bugs with the pico-sdk.  There
are two things going on here:
- Use a custom pico float component so that the pico-sdk doesn't include
  its math functions, and then provide our own from lib/libm.
- Provide a wrapper for __aeabi_fadd to fix the infinity addition bug.

Prior to this commit, the following tests failed on the rp2 port: cmath_fun
float_parse math_domain math_domain_special math_fun_special.  With this
commit, all these tests pass.

Thanks to @projectgus for how to approach this fix.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-06 14:00:07 +11:00
Scott Zhao 1323a71823 esp32/boards/UM_TINYPICO: Fix typo in baudrate instructions.
The installation instructions for ESP32 TinyPICO board contained a typo
that used a non-standard baud rate 912600 instead of 921600.  This made the
upload command fail on some Windows computers.

Signed-off-by: Scott Zhao <zhaomh1998@outlook.com>
2023-12-06 13:46:04 +11:00
Thomas Wenrich 78b3fe5689 esp32/machine_rtc: Preserve RTC user memory over most reset causes.
The user memory area - accessible by machine.RTC.memory() -- will now
survive most reboot causes.  A power-on reset (also caused by the EN pin on
some boards) will clean the memory.  When this happens, the magic number
not found in the user memory will cause initialization.

After other resets (triggered by watchdogs, machine.reset(), ...), the user
is responsible to check and validate the contents of the user area.

This new behaviour can be changed by enabling
MICROPY_HW_RTC_MEM_INIT_ALWAYS: in that case the RTC memory is always
cleared on boot.

Signed-off-by: Thomas Wenrich <twenrich@gmail.com>
2023-12-06 13:31:13 +11:00
Damien George 69089a532e esp32/boards: Enable further IRAM saving opts to fit ESP32-SPIRAM fw.
The amount of free IRAM in ESP32 SPIRAM builds is very small and went over
the limit due to commit 30b0ee34d3.  This
commit enables further optimisations to reduce IRAM usage.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-06 12:35:45 +11:00
MikeTeachman 58112fc49a stm32/machine_i2s: Improve accuracy of SCK frequency.
Configures the I2S PLL to produce a frequency that the I2S clock generator
can use to create an optimal SCK frequency.  The I2S PLL configuration
table is automatically generated at build time.

Fixes issue #10280.

Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
2023-12-06 11:48:03 +11:00
Damien George f3889db265 stm32/usbd_cdc_interface: Include header to get machine_bootloader decl.
This was broken by commit 48b5a7b060.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-04 22:19:59 +11:00
Damien George 20af857f52 nrf/boards/ARDUINO_NANO_33_BLE_SENSE: Don't enable MICROPY_MBFS.
This board has MICROPY_VFS enabled, which should take precedence over
MICROPY_MBFS (and did prior to 22d9116c8c).

Signed-off-by: Damien George <damien@micropython.org>
2023-12-04 22:18:14 +11:00
Damien George d422b68d10 nrf/mpconfigport: Enable MICROPY_PY_MACHINE_BOOTLOADER.
This should have been enabled in 48b5a7b060
but was missed.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-04 22:17:18 +11:00
Carlosgg 30b0ee34d3 esp32: Enable mbedtls cert time validation.
Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-12-04 10:50:42 +11:00
Damien George b5449b0f09 extmod/mbedtls: Enable certificate time/date validation by default.
All ports using this common configuration already enable time/date
validation, so this commit is a no-op change.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-01 15:08:11 +11:00
Carlosgg 20ffbe1a41 unix/mbedtls: Enable mbedtls cert time validation.
To match other ports.

Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-12-01 15:08:11 +11:00
Damien George ad806df857 ports: Move definitions of ATOMIC_SECTION macros to mphalport.h.
Also move MICROPY_PY_PENDSV_ENTER/REENTER/EXIT to mphalport.h, for ports
where these are not already there.

This helps separate the hardware implementation of these macros from the
MicroPython configuration (eg for renesas-ra and stm32, the IRQ static
inline helper functions can now be moved to irq.h).

Signed-off-by: Damien George <damien@micropython.org>
2023-12-01 14:37:48 +11:00
Damien George 7d784e5385 cc3200/application.mk: Don't add stm32 to build include path.
Or this port may end up accidentally including unwanted headers from stm32.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-01 14:13:34 +11:00
Damien George 7a6489aaa5 cc3200: Eliminate dependency on stm32's irq.h.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-01 14:12:59 +11:00
Damien George 49fa3ce65d cc3200: Convert os module to use extmod version.
Changes:
- os.uname() is removed to save space; sys.version and sys.implementation
  can be used instead.
- os.sync() now uses the common extmod version and syncs by calling the FAT
  FS sync function, which eventually calls sflash_disk_flush().

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 17:35:26 +11:00
Damien George 1c0e4644c7 cc3200: Convert dupterm to use common extmod implementation.
Tested on a WIPY.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 17:35:06 +11:00
Damien George 22d9116c8c nrf: Convert os module to use extmod version.
The os.dupterm() function has changed on this port, it now matches the
semantics used by all other ports (except it's restricted to accept only
machine.UART objects).

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:33:56 +11:00
Damien George e3c4c32c64 nrf: Use dupterm_objs[0] instead of board_stdio_uart.
To make this a little more consistent with other ports.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:33:56 +11:00
Damien George cc8fc450a6 esp8266/modmachine: Use common implementation of disable/enable_irq.
Now that the MICROPY_BEGIN_ATOMIC_SECTION/MICROPY_END_ATOMIC_SECTION macros
act the same as disable_irq/enable_irq, it's possible to use the common
extmod implementation of these machine functions.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 39d4153a8d esp8266/esp_mphal: Make atomic section more atomic.
By disabling ets_loop_iter when the atomic section is active.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 4bf7987f0a cc3200/mods/modmachine: Use common implementation of disable/enable_irq.
This commit changes the cc3200 port to use the common machine
implementation of machine.disable_irq() and machine.enable_irq().  This
eliminates its dependency on the stm32 port's code.  The behaviour of
cc3200 for these functions is changed:
- disable_irq() now returns an (opaque) integer rather than a bool
- enable_irq(state) must be passed and argument, which is the return value
  of disable_irq() rather than a bool

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George f523b86541 extmod/modmachine: Provide common implementation of disable/enable_irq.
The ports esp32, mimxrt, rp2 and samd all shared exactly the same
implementation of machine.disable_irq() and machine.enable_irq(),
implemented in terms of MICROPY_{BEGIN,END}_ATOMIC_SECTION.  This commit
factors these implementations into extmod/modmachine.c.

The cc3200, esp8266, nrf, renesas-ra and stm32 ports do not yet use this
common implementation.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George e1ec6af654 extmod/modmachine: Provide common bindings for 6 bare-metal functions.
Minor changes for consistency are:
- nrf gains: unique_id(), freq() [they do nothing]
- samd: deepsleep() now resets after calling lightsleep()
- esp32: lightsleep()/deepsleep() no longer take kw arg "sleep", instead
  it's positional to match others.  also, passing 0 here will now do a 0ms
  sleep instead of acting like nothing was passed.
  reset_cause() no longer takes any args (before it would just ignore them)
- mimxrt: freq() with an argument and lightsleep() both raise
  NotImplementedError

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 48b5a7b060 extmod/modmachine: Provide common Python bindings for bootloader().
Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George e68aa40d2a extmod/modmachine: Add MICROPY_PY_MACHINE_PIN_BASE option.
And use it in qemu-arm, unix and windows ports to enable PinBase.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 30a63a204d extmod/modmachine: Provide common Python bindings for machine.idle().
And use it in all ports.  The ports are unchanged, except esp8266 which now
just returns None from this function instead of the time elapsed (to match
other ports), and qemu-arm which gains this function.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 7d39db2503 extmod/modmachine: Factor ports' machine module dict to common code.
This is a code factoring to have the dict for the machine module in one
location, and all the ports use that same dict.  The machine.soft_reset()
function implementation is also factored because it's the same for all
ports that did already implement it.  Eventually more functions/bindings
can be factored.

All ports remain functionally the same, except:
- cc3200 port: gains soft_reset, mem8, mem16, mem32, Signal; loses POWER_ON
  (which was a legacy constant, replaced long ago by PWRON_RESET)
- nrf port: gains Signal
- qemu-arm port: gains soft_reset
- unix port: gains soft_reset
- zephyr port: gains soft_reset, mem8, mem16, mem32

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 7b2f13fb69 renesas-ra: Consolidate MICROPY_PY_MACHINE_I2C option.
MICROPY_HW_ENABLE_HW_I2C and MICROPY_PY_MACHINE_I2C are equivalent, so
just use the latter.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George e120c00c95 stm32/modmachine: Only enable machine.I2C if hardware I2C is enabled.
Prior to this change, if a board did not define any hardware I2C pins, via
MICROPY_HW_I2Cx_SCL, then machine.I2C would alias to machine.SoftI2C.

That doesn't really make sense, and SoftI2C should always be used if there
is no hardware implementation.  So this commit makes it so that machine.I2C
is only available if at least one set of I2C hardware pins are defined via
the MICROPY_HW_I2Cx_SCL/SDA macros.

For all boards that define at least one set of I2C hardware pins (which is
most of them) this commit is a no-op.  The only boards that change are:
LEGO_HUB_NO6, LEGO_HUB_NO7, STM32H7B3I_DK.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George b4d288ae44 nrf: Use MICROPY_PY_MACHINE_SPI instead of MICROPY_PY_MACHINE_HW_SPI.
MICROPY_PY_MACHINE_SPI is defined in mpconfigport.h to be equal to
MICROPY_PY_MACHINE_HW_SPI, so they are equivalent options.  The former one
is preferred because it's used by all other ports.

The default in mpconfigport.h is to enable this option, and all boards that
enable SPI have this removed from their mpconfigboard.h file so they pick
up the default.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:10:10 +11:00
Damien George 911662cc10 esp8266/machine_spi: Rename machine_hspi to machine_spi.
This renames the type, functions and file to match other ports.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 15:58:56 +11:00
Damien George e182f3862e rp2/cyw43_configport: Implement cyw43_delay_ms as mp_hal_delay_ms.
They do the same thing.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-29 16:25:28 +11:00
Damien George 12ef8a5ba2 rp2/mphalport: Optimise exit of mp_hal_delay_ms loop.
best_effort_wfe_or_timeout() already calls time_reached() and returns the
result of it, so no need to call it again.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-29 16:25:28 +11:00
Damien George fc94399ffe rp2/mpnetworkport: Rework lwIP polling to use soft_timer.
Signed-off-by: Damien George <damien@micropython.org>
2023-11-29 16:25:20 +11:00
Damien George 633c604722 rp2/mpbthciport: Rework HCI polling timer to use soft_timer.
Signed-off-by: Damien George <damien@micropython.org>
2023-11-29 16:23:52 +11:00
Damien George c9a9b2e682 rp2: Integrate soft_timer using the alarm pool.
The alarm pool is used to schedule the callback to soft_timer_handler().

Signed-off-by: Damien George <damien@micropython.org>
2023-11-29 16:23:49 +11:00
Damien George 516cc280e0 shared/runtime/softtimer: Generalise soft_timer to work without SysTick.
If a port defines MICROPY_SOFT_TIMER_TICKS_MS then soft_timer assumes a
SysTick back end, and provides a soft_timer_next variable that sets when
the next call to soft_timer_handler() should occur.

Otherwise, a port should provide soft_timer_get_ms() and
soft_timer_schedule_at_ms() with appropriate semantics (see comments).

Existing users of soft_timer should continue to work as they did.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-29 16:17:12 +11:00