Wykres commitów

393 Commity (master)

Autor SHA1 Wiadomość Data
Sebastian Romero 6f0193335a ports: Fix incorrect identifiers on Arduino boards.
This commit changes the Arduino board identifiers to correspond to their
official names.  This helps to identify boards at runtime.  At the moment
the Arduino Portenta H7 is reported as PORTENTA which is unfortunate as now
there is another Portenta board (Portenta C33) supported in MicroPython.

Also made the other identifiers for flash and network name consistent,
removed the incorrectly used MICROPY_PY_SYS_PLATFORM identifiers, and added
missing MICROPY_PY_NETWORK_HOSTNAME_DEFAULT identifiers.

Boards affected:
- stm32: ARDUINO_PORTENTA_H7, ARDUINO_GIGA, ARDUINO_NICLA_VISION
- renesas-ra: ARDUINO_PORTENTA_C33
- esp32: ARDUINO_NANO_ESP32
- rp2: ARDUINO_NANO_RP2040_CONNECT

Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
2023-11-17 15:24:15 +11:00
Angus Gratton f567a9255a shared/tinyusb: Add a helper for hex string conversion.
Change the rp2 and renesas-ra ports to use the helper function.

Saves copy-pasta, at the small cost of one more function call in the
firmware (if not using LTO).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-11-16 14:59:48 +11:00
Damien George a00c9d56db rp2/mphalport: Run TinyUSB stack while waiting for CDC input/output.
The recent change in bcbdee2357 means that
TinyUSB can no longer be run from within a soft (or hard) IRQ handler, ie
when the scheduler is locked.  That means that Python code that calls
`print(...)` from within a scheduled function may block indefinitely if the
USB CDC buffers are full.

This commit fixes that problem by explicitly running the TinyUSB stack when
waiting within stdio tx/rx functions.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-09 17:56:58 +11:00
Angus Gratton bcbdee2357 rp2: Change to use TinyUSB dcd_event_handler hook.
This change:
- Has a small code size reduction.
- Should slightly improve overall performance.  The old hook code
  seemed to use between 0.1% and 1.6% of the total CPU time doing no-op
  calls even when no USB work was required.
- USB performance is mostly the same, there is a small increase in
  latency for some workloads that seems to because sometimes the hook
  usbd_task() is called at the right time to line up with the next USB host
  request.  This only happened semi-randomly due to the timing of the hook.
  Improving the wakeup latency by switching rp2 to tickless WFE allows the
  usbd_task() to run in time for the next USB host request almost always,
  improving performance and more than offsetting this impact.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-11-09 12:28:28 +11:00
Angus Gratton 8c432ea2d4 rp2: Remove 1ms timeout to make idle waiting tickless.
The main motivation for doing this was to reduce the latency when the
system is woken by a USB interrupt.  The best_effort_wfe_or_timeout()
function calls into the pico-sdk dynamic timer framework which sets up a
new dynamic timer instance each time, and then has to tear it down before
continuing after a WFE.

Testing Python interrupt latency, it seems to be improved by about 12us
(from average of 46us to 34us running a Pin IRQ).  C-based "scheduled
nodes" should see even lower latency.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-11-03 18:26:51 +11:00
iabdalkader b41055a5a3 rp2/machine_adc: Refactor channel/pin validation code.
This patch ensures that integer channel numbers passed to the ADC
constructor (including temperature sensor) are interpreted as raw
channel numbers, and not cause any GPIO pins to be initialized.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-11-03 18:20:31 +11:00
Maarten van der Schrieck d95f5aa011 rp2/machine_uart: Fix handling of serial break condition.
The FIFO reports not only the bytes read, but also 4 error bits. These were
not checked, leading to NUL value read in case of break and possible
garbage bytes being written on parity/framing error.

This patch addresses the issue that NUL bytes are incorrectly read on
break, and at least provides the boilerplate code and comments for error
handling, that may be implemented in the future.

Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
2023-11-03 17:33:28 +11:00
Jim Mussared 4bd6ec9ae4 tools/boardgen.py: Add initial implementation of a common make-pins.py.
For now, this implements the functionality required for esp32 and rp2,
including support for numeric pins, rp2 alternate functions, and rp2
extended pins.

This also updates the rp2 port to use the same structure for pins.h and
pins.csv as for esp32, and moves the pin definitions directly into the
table (rather than having a table of pointers), which is a small code size
improvement.

Support for "hidden" pins in pins.csv is added (matching the stm32
implementation).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 14:06:27 +11:00
Jim Mussared 9cabee8252 ports: Standardise arguments and output for make-pins.py script.
All ports now use `--board-csv`, `--prefix`, `--output-souce`,
`--output-header` and no longer write to stdout.  This matches the esp32
implementation.

Ports that have an AF input use `--af-csv` (to match `--board-csv`).

Any additional output files are now prefixed with `output-` (e.g.
`--output-af-const`).

Default arguments are removed (all makefiles should always specify all
arguments, using default values is likely an error).

Replaced the `af-defs-cmp-strings` and `hdr-obj-decls` args for stm32 with
just `mboot-mode`.  Previously they were set on the regular build, now the
logic is reversed so mboot sets it.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 14:04:35 +11:00
Jim Mussared 59f3c7facb examples/pins.py: Remove this pins printing example.
It's not supported on all ports, adds complexity to the build to generate
pins_af.py, and can mostly be replicated just by printing the pin objects.

Remove support for generating pins_af.py from all ports (nrf, stm32,
renesas-ra, mimxrt, rp2).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 14:03:28 +11:00
Jim Mussared c3c7c602da rp2/boards/make-pins.py: Don't generate qstrs.
Also remove af-const header, as this is left over from the STM32 version
and unused.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 13:58:07 +11:00
Jim Mussared bbd8760bd9 all: Update Python formatting to ruff-format.
This updates a small number of files that change with ruff-format's (vs
black's) rules.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 13:30:41 +11:00
Jim Mussared 3bf70f16e9 py/mkrules.mk: Add MICROPY_PREVIEW_VERSION_2.
This provides a way to enable features and changes slated for MicroPython
2.x, by running `make MICROPY_PREVIEW_VERSION_2=1`. Also supported for
the cmake ports (except Zephyr).

This is an alternative to having a 2.x development branch (or equivalently,
keeping a 1.x release branch). Any feature or change that needs to be
"hidden" until 2.x can use this flag (either in the Makefile or the
preprocessor).

A good example is changing function arguments or other public API features,
in particular to aid in improving consistency between ports.

When `MICROPY_PREVIEW_VERSION_2` is enabled, the REPL banner is amended to
say "MicroPython (with v2.0 preview) vX.Y.Z", and sys.implementation gets a
new field `_v2` set to `True`.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-27 15:28:46 +11:00
Damien George 3e2706a18d extmod/modmachine: Consolidate mem, i2c and spi headers to modmachine.h.
The contents of machine_mem.h, machine_i2c.h and machine_spi.h have been
moved into extmod/modmachine.h.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 17:40:22 +11:00
Damien George d336c1b79b extmod/modmachine: Consolidate simple machine headers into modmachine.h.
The contents of machine_bitstream.h, machine_pinbase.h, machine_pulse.h and
machine_signal.h have been moved into extmod/modmachine.h.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 16:49:27 +11:00
Damien George 90023b4dcf extmod/modmachine: Clean up decls of machine types to use common ones.
The machine_i2c_type, machine_spi_type and machine_timer_type symbols are
already declared in extmod/modmachine.h and should not be declared anywhere
else.

Also move declarations of machine_pin_type and machine_rtc_type to the
common header in extmod.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 16:20:53 +11:00
Damien George 5b4a2baff6 extmod/machine_uart: Factor ports' UART Python bindings to common code.
This is a code factoring to have the Python bindings in one location, and
all the ports use those same bindings.  For all ports except the two listed
below there is no functional change.

The nrf port has UART.sendbreak() removed, but this method previously did
nothing.

The zephyr port has the following methods added:
- UART.init(): supports setting timeout and timeout_char.
- UART.deinit(): does nothing, just returns None.
- UART.flush(): raises OSError(EINVAL) because it's not implemented.
- UART.any() and UART.txdone(): raise NotImplementedError.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 10:46:42 +11:00
Damien George 95d8b5fd55 extmod/machine_adc: Factor ports' ADC Python bindings to common code.
No functional change, just code factoring to have the Python bindings in
one location, and all the ports use those same bindings.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-23 17:16:45 +11:00
Damien George 91a3f18391 extmod/machine_i2s: Factor comments, some enums and macros.
Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:40:17 +11:00
Damien George 46ae3b5a34 extmod/machine_i2s: Factor init_helper argument parsing.
Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:40:17 +11:00
Damien George 676f9bb78c extmod/machine_i2s: Factor print function.
Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:40:17 +11:00
Damien George 1477986815 extmod/machine_i2s: Factor I2S.irq method.
Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:40:17 +11:00
Damien George cdd9ad8d62 extmod/machine_i2s: Factor I2S.shift method.
It's exactly the same for all four port implementations.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:40:17 +11:00
Damien George a2d7e0da0b extmod/machine_i2s: Factor stream and ring-buf code.
Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:40:17 +11:00
Damien George f2f3ef162d extmod/machine_i2s: Factor ports' I2S Python bindings to common code.
This factors the basic top-level I2S class code from the ports into
extmod/machine_i2s.c:
- I2S class definition and method table.
- The init and deinit method wrappers.
- The make_new code.

Further factoring will follow.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:39:57 +11:00
Damien George 7e7af71527 extmod/machine_pwm: Remove header file and move decls to .c file.
With public declarations moved to extmod/modmachine.h.  It's now mandatory
for a port to define MICROPY_PY_MACHINE_PWM_INCLUDEFILE if it enables
MICROPY_PY_MACHINE_PWM.  This follows how extmod/machine_wdt.c works.

All ports have been updated to work with this modified scheme.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 16:24:46 +11:00
Damien George 60929ec7e2 extmod/machine_wdt: Factor ports' WDT Python bindings to common code.
There are currently 7 ports that implement machine.WDT and a lot of code is
duplicated across these implementations.  This commit factors the common
parts of all these implementations to a single location in
extmod/machine_wdt.c.  This common code provides the top-level Python
bindings (class and method wrappers), and then each port implements the
back end specific to that port.

With this refactor the ports remain functionally the same except for:

- The esp8266 WDT constructor now takes keyword arguments, and accepts the
  "timeout" argument but raises an exception if it's not the default value
  (this port doesn't support changing the timeout).

- The mimxrt and samd ports now interpret the argument to WDT.timeout_ms()
  as signed and if it's negative truncate it to the minimum timeout (rather
  than it being unsigned and a negative value truncating to the maximum
  timeout).

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 15:36:09 +11:00
iabdalkader 2590a34ed7 rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Add external analog pins.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-10-20 12:18:41 +11:00
iabdalkader 5e52389f99 rp2/machine_adc: Add support for external ADC channels.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-10-20 12:18:33 +11:00
robert-hh f84b4617cb rp2/cyw43_configport: Use m_tracked_calloc and m_tracked_free.
When using malloc and free there were out-of-memory situations depending on
the arm-none-eabi package version.  This commit changes malloc/free to use
the MicroPython GC heap instead.

Signed-off-by: robert-hh <robert@hammelrath.com>
Signed-off-by: Damien George <damien@micropython.org>
2023-10-16 23:36:54 +11:00
robert-hh 480659b1ac ports: Make all ports skip execution of main.py if boot.py fails.
That can be caused e.g. by an exception.  This feature is implemented in
some way already for the stm32, renesas-ra, mimxrt and samd ports.  This
commit adds it for the rp2, esp8266, esp32 and nrf ports.  No change for
the cc3200 and teensy ports.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-10-12 11:53:29 +11:00
Damien George 6f76d1c7fa rp2: Implement time.time_ns with time_us_64 so it has us resolution.
Currently on rp2 the time.time_ns() function has only seconds resolution.
This commit makes it have microsecond resolution, by using the output of
time_us_64() instead of the RTC.

Tested that it does not drift from the RTC over long periods of time.

Signed-off-by: Damien George <damien.p.george@gmail.com>
2023-10-05 21:24:47 +11:00
Angus Gratton d81cf0b9e3 rp2/CMakeLists: Enable debug symbols in all builds.
Allows using gdb, addr2line, etc. on a "release" ELF file.

No impact to .bin or .uf2 size, only the .elf will get bigger.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-10-05 14:08:17 +11:00
Jim Mussared 65a3ce39a3 extmod/modnetwork: Forward if.config(hostname) to network.hostname.
This removes the duplicate code in cyw43, esp32, esp8266 that implements
the same logic as network.hostname.

Renames the `mod_network_hostname` (where we store the hostname value in
`.data`) to `mod_network_hostname_data` to make way for calling the shared
function `mod_network_hostname`.

And uses memcpy for mod_network_hostname_data, because the length of source
is already known and removes reliance on string data being null-terminated.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-04 12:39:51 +11:00
iabdalkader da193c42f6 ports: Rename Arduino board LED pins to be consistent.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-10-02 11:57:46 +11:00
Wanlin Wang 2772b88f6a rp2/README: Fix name of RPI_PICO_W board.
Signed-off-by: Wanlin Wang <dgideas@outlook.com>
2023-10-02 11:46:38 +11:00
Jim Mussared da6f1e1d1e rp2/msc_disk: Allow configuring the USB MSC inquiry response.
This was previously hard-coded to "Micropy" / "Mass Storage" / "1.0".

Now allow it to be overridden by a board.

Also change "Micropy" to "MicroPy" and "1.0" to "1.00" to match stm32.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-29 16:36:45 +10:00
Felix Dörre 3c2b2f7a4d rp2/modmachine: Fix lightsleep while wifi is powered off.
While cyw43 is deinitialized, an interrupt occurs.  That is handled with
these lines: ports/rp2/mpnetworkport.c#L59-L61 and as pendsv is disabled
while in network code, the poll function then just waits there.

When deinit has finished, the poll func is executed, but skipped:
src/cyw43_ctrl.c#L222-L225 this skips the `CYW43_POST_POLL_HOOK` which
would re-enable interrupts, but also reset `cyw43_has_pending`.

And in that state, the lightsleep code, will skip sleeping as it thinks
there is a network packet pending to be handled.

With this change applied, lightsleep works as expected when the wifi chip
is enabled, and when it's powered off.
2023-09-29 15:15:42 +10:00
iabdalkader 5473200aab rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Use standard HCI UART baudrate.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-15 16:48:20 +10:00
iabdalkader 9ea9e04ef6 rp2/mpconfigport: Disable BLE locking when MICROPY_PY_BLUETOOTH enabled.
Bluetooth code runs in the scheduler, so no locking/mutex is required.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-15 16:44:07 +10:00
iabdalkader 1976781d33 rp2/mpbthciport: Fix HCI UART config.
Fixes are:
- The baudrate argument is a keyword arg, it was passed before as a
  positional arg.
- Use the port and baudrate arguments passed from higher level code instead
  of the hard-coded port ID and baudrate, which would allow HCI drivers to
  change baudrates.
- Increase UART char timeout and RX buffer size.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-15 16:43:15 +10:00
iabdalkader 6abe3e1714 rp2/mpbthciport: Switch to static scheduler nodes.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-15 16:42:50 +10:00
David Lechner ffb43b2dd3 py/modthread: Return thread id from start_new_thread().
In CPython, `_thread.start_new_thread()` returns an ID that is the same ID
that is returned by `_thread.get_ident()`.  The current MicroPython
implementation of `_thread.start_new_thread()` always returns `None`.

This modifies the required functions to return a value. The native thread
id is returned since this can be used for interop with other functions, for
example, `pthread_kill()` on *nix. `_thread.get_ident()` is also modified
to return the native thread id so that the values match and avoids the need
for a separate `native_id` attribute.

Fixes issue #12153.

Signed-off-by: David Lechner <david@pybricks.com>
2023-09-03 18:49:18 +10:00
robert-hh 9f1576f2ad rp2/machine_timer: Fix printing of timer period.
Showing the period alway as microsecond quantities, since tick_hz is
assumed as 1_000_000 if the period is given by freq=xxx.  If the period is
larger than 0xffffffff, the value is divided by 1000 and "000" is appended
in the display.  That works for periods up to about 50 days.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-02 17:09:51 +10:00
Jim Mussared 873bd00ad4 rp2: Rename PICO, PICO_W to RPI_PICO, RPI_PICO_W.
PICO might not always be a unique name across all ports, and the
convention generally for other boards is to do VENDOR_BOARD.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23 15:49:37 +10:00
Jim Mussared 97ffc53ec9 {esp32,rp2,stm32}/Makefile: Append board variant to BUILD.
This allows switching between variants without clobbering the build
output.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23 13:54:37 +10:00
Jim Mussared 1a99f74063 ports/*/boards/*/board.json: Remove "id" field.
This was used to override the firmware filename generated by the build
server (to match the historical name before board definitions existed).

Now we're making everything use the board definition name (i.e. the
directory name).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23 13:54:37 +10:00
Jim Mussared 45845acf6d rp2: Use uppercase variant names.
This is to support a future change to add the variant name to the build
directory and therefore should be the same style as the board name.

This only affects the WEACTSTUDIO board. Also standardises on a convention
for naming flash-size variants. Normally we would write e.g. 2MiB, but in
uppercase, it's awkward to write 2MIB, so instead use 2M, 512K, etc for
variant names, but use 2MiB when not constrained by case (e.g. a regular
filename).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23 13:54:37 +10:00
Jim Mussared 9573d31071 all: Remove query-variants make target.
This is difficult to implement on cmake-based ports, and having the list
of variants in mpconfigboard.{cmake,mk} duplicates information that's
already in board.json.

This removes the existing query-variants make target from stm32 & rp2
and the definition of BOARD_VARIANTS from the various board files.

Also renames the cmake variable to MICROPY_BOARD_VARIANT to match other
variables such as MICROPY_BOARD. The make variable stays as
BOARD_VARIANT.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:37:44 +10:00
Jim Mussared ad123ed013 esp32/Makefile: Implement `make submodules` to match other ports.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:37:44 +10:00
Jim Mussared 24a6e951ec ports: Simplify board feature tags in board.json.
This commit:
- Finds a common set of board feature tags and maps existing features to
  that reduced set.
- Removes some less-useful board feature tags.
- Ensures all MCUs are specified correctly.
- Ensures all boards have a vendor (and fixes some vendor names).

This is to make the downloads page show a less intimidating set of filters.

Work done in conjunction with Matt Trentini <matt.trentini@gmail.com>.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-10 14:54:03 +10:00
robert-hh c02da6d81d rp2/machine_pin: Factor out pin-find code from machine_pin_make_new.
And use it in mp_hal_get_pin_obj() and machine_pin_make_new().  That way,
mp_hal_get_pin_obj() accepts both int and str objects as argument, allowing
use of a pin specifier instead of a pin object in the constructor of
devices which need a pin as parameter.

E.g. instead of

    uart = UART(0, tx=Pin(0), rx=Pin(1))

one can write:

    uart = UART(0, tx=0, rx=1)

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20 17:30:17 +10:00
Jim Mussared 7979a4d267 ports: In machine_i2s.c, rename uasyncio to asyncio.
Mostly updates comments, but also renames the UASYNCIO enum value to
ASYNCIO.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-19 18:36:54 +10:00
Jim Mussared 2fbc08c462 extmod/asyncio: Rename uasyncio to asyncio.
The asyncio module now has much better CPython compatibility and
deserves to be just called "asyncio".

This will avoid people having to write `from uasyncio import asyncio`.

Renames all files, and updates port manifests to use the new path. Also
renames the built-in _uasyncio to _asyncio.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-19 17:33:03 +10:00
Peter Harper 856e08b193 rp2/boards/PICO_W: Enable Bluetooth Low Energy support.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-14 22:20:20 +10:00
Peter Harper a459eaf3e6 rp2/mpbthciport: Cancel existing alarms.
Cancel any existing poll alarm before add a new one.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-14 22:20:20 +10:00
Peter Harper 888a15cda3 rp2: Add Bluetooth support via cyw43.
Using BTstack with CYW43 for Pico W.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-14 22:20:20 +10:00
Brian 'redbeard' Harrington ea8f0fd896 rp2/CMake: Normalize MICROPY_PORT_DIR.
In 5fe2a3f1 the ESP32 port underwent a change to how `MICROPY_PORT_DIR`
is defined.  This commit normalizes the `rp2` port to use the same
underlying variable mechanism (`CMAKE_CURRENT_LIST_DIR`).

Signed-off-by: Brian 'redbeard' Harrington <redbeard@dead-city.org>
2023-06-13 00:11:06 -07:00
Jim Mussared 5fd042e7d1 all: Replace all uses of umodule in Python code.
Applies to drivers/examples/extmod/port-modules/tools.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared 2eba98f1e0 all: Use MP_REGISTER_EXTENSIBLE_MODULE for overrideable built-ins.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:21 +10:00
Jim Mussared 45ac651d1a all: Rename *umodule*.c to remove the "u" prefix.
Updates any includes, and references from Makefiles/CMake.

This essentially reverts what was done long ago in commit
136b5cbd76

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:17 +10:00
Jim Mussared f5f9edf645 all: Rename UMODULE to MODULE in preprocessor/Makefile vars.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:11 +10:00
Jim Mussared 1bf2dcb15e all: Rename mp_umodule*, mp_module_umodule* to remove the "u" prefix.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:04 +10:00
Jim Mussared 30628d1bb7 all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere.
This renames the builtin-modules, such that help('modules') and printing
the module object will show "module" rather than "umodule".

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:53:57 +10:00
Jim Mussared 1d4b4f0ce2 ports: Standardise docs link in help text.
Updates all `help()` output to use the phrase:
`For online docs please visit http://docs.micropython.org/`

Some ports previously used different wording, some pointed to the wrong
link.  Also make all ports use `help.c` for consistency.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-02 11:48:46 +10:00
robert-hh 73cc6b750e ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51.
These have by default FAT support.  The SAMD21 build does not support FAT.
The nrf port also implements os.sync(), but has it's own copy of moduos.c.

Code size increases seen: 40 to 56 bytes.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01 11:39:01 +10:00
Ondrej Wisniewski 29401a719f rp2/mphalport: Only use CYW43 MAC for WLAN0 interface.
Building the Pico-W needs the MICROPY_PY_NETWORK_CYW43 flag to be set in
order to include building the CYW43 Wifi driver.  But then mp_hal_get_mac()
handles the MAC assignment for all nics the "CYW43 way", copying the real
MAC provided by the WiFi hardware.  This will fail for all other NIC types,
resulting in an invalid MAC address.

The solution in this commit is to add a check for the NIC type parameter
idx and handle the MAC address respectively.
2023-05-18 13:06:06 +10:00
Phil Howard 4ce360fa83 rp2/CMakeLists: Allow relative MICROPY_BOARD_DIR when invoking cmake.
Convert to an absolute path to always reliably locate manifest.py.  This is
already done in Makefile, but is also needed in CMakeLists.txt if cmake is
invoked directly.

Signed-off-by: Phil Howard <phil@pimoroni.com>
2023-05-18 12:51:36 +10:00
Adam Green f9958417d8 rp2: Make rp2_state_machine_exec accept integers.
Currently rp2.StateMachine.exec(instr_in) requires that the instr_in
parameter be a string representing the PIO assembly language instruction
to be encoded by rp2.asm_pio_encode(). This commit allows the parameter
to also be of integral type. This is useful if the exec() method is
being called often where the use of pre-encoded machine code is
desireable.

This commit still supports calls like:
    sm.exec("set(0, 1)")

It also now supports calls like:
    # Performed once earlier, maybe in __init__()
    assembled_instr = rp2.asm_pio_encode("out(y, 8)", 0)
    # Performed multiple times later as the PIO state machine is
    # configured for its next run.
    sm.exec(assembled_instr)

The existing examples/rp2/pio_exec.py and examples/rp2/pio_pwm.py that
exercise the rp2.StateMachine.exec() method still work with this change.

Signed-off-by: Adam Green <adamgrym@yahoo.com>
2023-05-18 12:33:02 +10:00
Damien George 38243cd8e0 extmod/machine_pwm: Remove PWM_INIT and PWM_DUTY_U16_NS config options.
All ports that enable MICROPY_PY_MACHINE_PWM now enable these two
sub-options, so remove these sub-options altogether to force consistency in
new ports that implement machine.PWM.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-04 13:19:19 +10:00
robert-hh 7952694a3c rp2/machine_pwm: Add duty_x() checks and return 0 if PWM is not started.
Changes in this commit:
- Limit duty_u16() to 65535 and duty_ns() to the period duration.
- Return 0 for pwm.freq() if the frequency has not been set yet.
- Return 0 for pwm.duty_us16() and duty_ns() unless both frequency and
  duty cycle have been set.
- Initialize the pin to PWM at the very end of the constructor, to avoid
  possible glitches on the pin when setting up the PWM.
2023-05-04 13:18:58 +10:00
robert-hh 0b3b508d1d rp2/machine_pwm: Add support for inverting a PWM channel output.
Using the invert=True|False keyword option with the constructor or init().
2023-05-04 13:18:47 +10:00
robert-hh 84302b2854 rp2/machine_pwm: Enable keyword args in constructor and add init method.
This adds support for freq/duty_u16/duty_ns keyword arguments in the PWM
constructor, and adds the PWM.init() method.  Using init() without
arguments enables a previously deinit-ed PWM again.

Further changes in this commit:
- Do not start PWM output if only duty was set.
- Stop all PWM slices on soft-reset.
- Fix a bug when changing the freq on a channel pair with duty_ns set.
2023-05-04 13:13:05 +10:00
Christian Clauss 2a1db770ce all: Fix cases of Python variable assigned but never used.
This fixes ruff rule F841.
2023-05-02 16:36:05 +10:00
Damien George b1229efbd1 all: Fix spelling mistakes based on codespell check.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 18:03:06 +10:00
Damien George 67e917609f rp2/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George 9955553001 extmod/modutime: Provide a generic time module.
Based on extmod/utime_mphal.c, with:
- a globals dict added
- time.localtime wrapper added
- time.time wrapper added
- time.time_ns function added

New configuration options are added for this module:
- MICROPY_PY_UTIME (enabled at basic features level)
- MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME
- MICROPY_PY_UTIME_TIME_TIME_NS

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:09:56 +10:00
Damien George 083dc1f082 ports: Use extmod version of mktime instead of port-specific one.
Apart from slight differences in the error message, the functionality of
all ports is unchanged.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 14:55:07 +10:00
Damien George fe4ac49d7f rp2/memmap_mp.ld: Allow a board to reserve memory for the C heap.
Since c80e7c14e6 changed the GC heap to use
all unused RAM, there is no longer any RAM available for the traditional C
heap (which is not used by default in MicroPython but may be used by C
extensions).  This commit adds a provision for a board to reserve RAM for
the C heap, by defining MICROPY_C_HEAP_SIZE.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-26 12:36:21 +10:00
Jim Mussared 256f47e2f8 extmod/btstack: Fix indicate/notify queuing.
This adds a mechanism to track a pending notify/indicate operation that
is deferred due to the send buffer being full. This uses a tracked alloc
that is passed as the content arg to the callback.

This replaces the previous mechanism that did this via the global pending
op queue, shared with client read/write ops.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
David (Pololu) bf3eb9dc39 rp2/machine_i2c: Add timeout parameter for machine.I2C().
This commit adds support for the `timeout` keyword argument to machine.I2C
on the rp2 port, following how it's done on other ports.

The main motivation here is avoid the interpreter crashing due to infinite
loops when SDA is stuck low, which is quite common if the board gets reset
while reading from an I2C device.

A default timeout of 50ms is chosen because it's consistent with:
- Commit a707fe50b0 which used a timeout of
  50,000us for zero-length writes on the rp2 port.
- The machine.SoftI2C class which uses 50,000us as the default timeout.
- The stm32 port's hardware I2C, which uses 50,000us for
  I2C_POLL_DEFAULT_TIMEOUT_US.

This commit also fixes the default timeout on the esp32 port to be
consistent with the above, and updates the documentation for machine.I2C to
document this keyword argument.
2023-04-21 18:03:33 +10:00
David Grayson c046b23ea2 shared/runtime/pyexec: Don't allow Ctrl+C to interrupt frozen boot code.
Helps prevent the filesystem from getting formatted by mistake, among other
things.  For example, on a Pico board, entering Ctrl+D and Ctrl+C fast many
times will eventually wipe the filesystem (without warning or notice).

Further rationale: Ctrl+C is used a lot by automation scripts (eg mpremote)
and UI's (eg Mu, Thonny) to get the board into a known state.  If the board
is not responding for a short time then it's not possible to know if it's
just a slow start up (eg in _boot.py), or an infinite loop in the main
application.  The former should not be interrupted, but the latter should.
The only way to distinguish these two cases would be to wait "long enough",
and if there's nothing on the serial after "long enough" then assume it's
running the application and Ctrl+C should break out of it.  But defining
"long enough" is impossible for all the different boards and their possible
behaviour.  The solution in this commit is to make it so that frozen
start-up code cannot be interrupted by Ctrl+C.  That code then effectively
acts like normal C start-up code, which also cannot be interrupted.

Note: on the stm32 port this was never seen as an issue because all
start-up code is in C.  But now other ports start to put more things in
_boot.py and so this problem crops up.

Signed-off-by: David Grayson <davidegrayson@gmail.com>
2023-04-05 10:38:50 +10:00
Damien George 783ddfc264 shared/tinyusb: Allow max USB descriptor string to be configured.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-04 11:57:25 +10:00
Damien George 38e7b842c6 ports: Implement simple write polling for stdout.
This is a best-effort implementation of write polling.  It's difficult to
do correctly because if there are multiple output streams (eg UART and USB
CDC) then some may not be writeable while others are.  A full solution
should also have a return value from mp_hal_stdout_tx_strn(), returning the
number of bytes written to the stream(s).  That's also hard to define.

The renesas-ra and stm32 ports already implement a similar best-effort
mechanism for write polling.

Fixes issue #11026.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-23 13:51:17 +11:00
robert-hh b7ea90d4cb rp2/machine_uart: Fix setting of UART LCR parameters.
Prior to this change, setting of UART parameters like parity, stop bits or
data bits did not work correctly.  As suggested by @iabdalkader, adding
__DSB() fixes the problem, making sure that changes to the UART LCR_H
register are seen by the peripheral.

Note: the FIFO is already enabled in the call to uart_init(), so the call
to uart_set_fifo_enabled() is not required, but kept for visibility.

Fixes issue #10976.
2023-03-22 16:21:48 +11:00
robert-hh 711bac511e rp2/main: Keep UART REPL with DEBUG=1 and MICROPY_HW_ENABLE_UART_REPL=1.
For builds with DEBUG=1 and MICROPY_HW_ENABLE_UART_REPL=1, calling
stdio_init_all() in main() detaches the UART input from REPL.  This change
suppresses calling stdio_init_all() then.
2023-03-20 22:33:45 +11:00
robert-hh be686e634e rp2: Allow disabling USB via MICROPY_HW_ENABLE_USBDEV config.
Previously, setting MICROPY_HW_ENABLE_USBDEV to 0 caused build errors.  The
change affects the nrf and samd ports as well, so MICROPY_HW_ENABLE_USBDEV
had to be explicitly enabled there.

The configuration options MICROPY_HW_ENABLE_USBDEV and
MICROPY_HW_ENABLE_UART_REPL are independent, and can be enabled or disabled
by a board.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-20 22:33:45 +11:00
iabdalkader a197823eb7 ports: Fix MCU tags in Arduino board.json files. 2023-03-20 15:22:24 +11:00
Christian Clauss 4376c969f6 all: Fix Python comparison to None and True, and use "not in".
These are basic PEP8 recommendations.
2023-03-10 13:32:24 +11:00
cpottle9 c80e7c14e6 rp2: Allocate GC heap from unused RAM.
Borrowing an idea from the mimxrt port (also stm32 port): in the loader
input file memmap_mp.ld calculate __GcHeapStart and __GcHeapEnd as the
unused RAM.  Then in main.c use these addresses as arguments to gc_init().

The benefits of this change are:

1) When libraries are added or removed in the future changing BSS usage,
   main.c's sizing of the GC heap does not need to be changed.

2) Currently these changes make the GC area about 30 KBytes larger, eg on
   PICO_W the GC heap increases from 166016 to 192448 bytes.  Without that
   change this RAM would never get used.

3) If someone wants to disable one or more SRAM blocks on the RP2040 to
   reduce power consumption it will be easy: just change the MEMORY section
   in memmap_mp.ld.  For instance to not use SRAM2 and SRAM3 change it to:

        MEMORY
        {
            FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2048k
            RAM(rwx) : ORIGIN =  0x21000000, LENGTH = 128k
            SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
            SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
        }

   Then to turn off clocks for SRAM2 and SRAM3 from MicroPython, set the
   appropriate bits in WAKE_EN0 and SLEEP_EN0.

Tested by running the firmware.uf2 file on PICO_W and displaying
micropython.mem_info().  Confirmed GC total size approximately matched the
size calculated by the loader.

Signed-off-by: cpottle9 <cpottle9@outlook.com>
2023-03-09 12:00:02 +11:00
David Grayson f80d040c03 rp2/modrp2: Disable other core, shorten delay to 8us in bootsel_button.
This function seems to work fine in multi-core applications now.

The delay is now in units of microseconds instead of depending on the clock
speed, and is adjustable by board configuration headers.

Also added documentation.
2023-03-09 11:44:20 +11:00
Tomofumi Inoue 673957b643 rp2/modrp2: Support reading the BOOTSEL button on the Pico board.
And any other board that exposes this pin with a button.
2023-03-09 11:43:39 +11:00
iabdalkader dc2186c35b rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Include "senml" in manifest. 2023-03-09 10:38:06 +11:00
iabdalkader 6bb60745be rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Add more external pins.
Add the missing A4, A5 external (Nina-W controlled) pins.
2023-03-08 00:59:36 +11:00
iabdalkader fd202fe757 rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Include "time" in manifest.
Freeze the micropython-lib time module to get strftime.
2023-03-08 00:52:54 +11:00
iabdalkader ddf39793f3 rp2/pendsv: Add MICROPY_BOARD_PENDSV_ENTRIES for board customisation. 2023-03-07 15:59:37 +11:00
Jim Mussared bad0098a49 stm32: Update to use the open-source lib version of cyw43-driver.
This removes the previous WiFi driver from drivers/cyw43 (but leaves behind
the BT driver), and makes the stm32 port (i.e. PYBD and Portenta) use the
new "lib/cyw43-driver" open-source driver already in use by the rp2 port.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:27:12 +11:00
Jim Mussared a377302623 extmod/modnetwork: Add network.hostname() and network.country().
This provides a standard interface to setting the global networking config
for all interfaces and interface types.

For ports that already use either a static hostname (mimxrt, rp2) they will
now use the configured value. The default is configured by the port
(or optionally the board).

For interfaces that previously supported .config(hostname), this is still
supported but now implemented using the global network.hostname.

Similarly, pyb.country and rp2.country are now deprecated, but the methods
still exist (and forward to network.hostname).

Because ESP32/ESP8266 do not use extmod/modnetwork.c they are not affected
by this commit.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:26:17 +11:00
Jim Mussared 8e430a7d43 rp2/Makefile: Allow specifying BOARD_DIR on make command line.
This matches the behavior of the makefile ports but implemented for CMake,
making it easy to specify custom board definitions.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-23 09:50:07 +11:00
Damien George b257c0152b rp2/cyw43_configport: Specify the chipset firmware include file.
Required by the latest version of cyw43-driver.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-17 14:03:19 +11:00