Wykres commitów

393 Commity (master)

Autor SHA1 Wiadomość Data
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
Damien George c6140ad0d4 rp2/mpconfigport: Enable os.dupterm and hashlib.sha1 on all boards.
This further aligns the features available on Pico and Pico W boards.

os.dupterm is generally useful, but can still be disabled by a board if
needed.  hashlib.sha1 requires mbedtls for the implementation, but that's
always available (due to ucryptolib's requirements).  The entire hashlib
module can still be disabled by an individual board if needed.

Fixes issue #7881.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-17 13:43:03 +11:00
Jim Mussared 5812611ab2 rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Use default aioble.
The default now includes all sub-components (security, l2cap, etc)
and using the kwarg options is no longer supported.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-16 12:32:03 +11:00
Damien George 0afe60b876 rp2/rp2_pio: Track use of PIO resources and free them on soft reset.
Prior to this commit, on Pico W (where the CYW43 driver is enabled) the PIO
instruction memory was not released on soft reset, so using PIO after a
soft reset would eventually (after a few soft resets) lead to ENOMEM when
allocating a PIO program.

This commit fixes that by tracking the use of PIO memory by this module and
freeing it on soft reset.

Similarly, use of the state machines themselves are tracked and released on
soft reset.

Fixes issue #9003.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-07 14:52:36 +11:00
Jim Mussared 6250337c9c ports: Make all network-capable boards use bundle-networking.
This will ensure that any board with networking support gets:
 - webrepl
 - mip
 - urequests
 - ntptime

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-01 12:42:06 +11:00
David Lechner 3446d440f6 shared/runtime/gchelper: Drop cpu directive from ARM asm helpers.
This drops the `.cpu` directive from the ARM gchelper_*.s files.  Having
this directive breaks the linker when targeting older CPUs (e.g. `-mthumb
-mthumb-interwork` for `-mcpu=arm7tdmi`).  The actual target CPU should be
determined by the compiler options.

The exact CPU doesn't actually matter, but rather the supported assembly
instruction set.  So the files are renamed to *_thumb1.s and *thumb2.s to
indicate the instruction set support instead of the CPU support.

Signed-off-by: David Lechner <david@pybricks.com>
2023-01-28 15:51:38 +11:00
Jay Greco be420bf9bb rp2/boards/NULLBITS_BIT_C_PRO: Add Bit-C PRO board. 2023-01-28 15:14:48 +11:00
Damien George 67fac4ebc5 rp2/machine_pin: Fix configuring OPEN_DRAIN with initial value.
Prior to this commit, Pin(Pin.OPEN_DRAIN, value=0) would not set the
initial value of the open-drain pin to low, instead it would be high.

Signed-off-by: Damien George <damien@micropython.org>
2023-01-24 17:29:45 +11:00
Damien George 8a0353525f rp2/main: Use mp_printf in nlr_jump_fail.
The mp_plat_print output is already being used by the subsequent call to
mp_obj_print_exception().  And this eliminates all references to printf for
this port (at least in non-debug builds).

Signed-off-by: Damien George <damien@micropython.org>
2023-01-24 16:58:29 +11:00
robert-hh d4a4cde42e rp2: Fix crash in a pin.irq handler.
When accessing the argument of the irq function.
2023-01-22 17:49:10 +01:00
iabdalkader d02f089058 rp2/boards: Add pin CSV files to board definitions.
Pin defines are:
- For Pico define board pins and the default LED pin (WL_GPIO25).
- For Pico-W define board pins, external pins and the default
  LED pin (WL_GPIO0).
- For the Nano-RP2040, define board pins, external pins and
  the default LED pin (GPIO25)
- For all other boards, the pins.csv defines the LED pin (if any)
  for backwards compatibility with code that assumes there's always
  an LED pin.
2023-01-16 11:44:28 +11:00
iabdalkader 7d01f38170 drivers/ninaw10: Implement machine.Pin external pin controls. 2023-01-16 11:44:28 +11:00
iabdalkader c214c9e648 rp2/machine_pin: Add support for named pins and alternate functions.
This commit adds support for generating named pin mappings for all pins
including CPU, board-defined, LED and externally controlled pins.  CPU pins
are mapped to `pin_GPIO<n>`, externally-controlled pins are mapped to
`pin_EXT_GPIO<n>`, and defined conditionally (up to 10 pins, and can be
expanded in the future), and they are non-const to allow `machine-pin.c` to
write the pin object fields.  Both CPU and externally controlled pins are
generated even if there's no board CSV file; if one exists it will just be
added to board pins.
2023-01-16 11:44:26 +11:00
iabdalkader 66e0cfc3b9 rp2/machine_pin: Refactor the machine.Pin class for external GPIO.
Handle externally controlled GPIO pins more generically, by removing all
CYW43-specific code from `machine_pin.c`, and adding hooks to initialise,
configure, read and write external pins.  This allows any driver for an
on-board module which controls GPIO pins (such as CYW43 or NINA), to
provide its own implementation of those hooks and work seamlessly with
`machine_pin.c`.
2023-01-16 11:37:18 +11:00
robert-hh 5890a17ae0 rp2/rp2_flash: Call MICROPY_EVENT_POLL_HOOK_FAST after reading flash.
To allow the USB to work in cases where there is a lot of filesystem
access, in particular on boot.

For example, registering of the USB CDC interface may fail if:
- the board file system is lfs2 (default), and
- sys.path contains entries for the local file system (default), and
- files are imported by boot.py or main.py from frozen bytecode of the file
  system (common) and the file system contains many files, like 100.

In that case the board is very busy with scanning LFS, and registering the
USB interface seems to time out.  This commit fixes this by allowing the
USB to make progress during filesystem reads.

Also switch existing MICROPY_EVENT_POLL_HOOK uses in this file to
MICROPY_EVENT_POLL_HOOK_FAST now that the latter macro exists.
2023-01-12 16:53:02 +11:00
Paul Grayson b208cf23e2 rp2/mphalport: Change order of pin operations to prevent glitches.
When switching from a special function like SPI to an input or output,
there was a brief period after the function was disabled but before the
pin's I/O state was configured, in which the state would be poorly defined.
This fixes the problem by switching off the special function after fully
configuring the I/O state.

Fixes #10226.

Signed-off-by: Paul Grayson <pdg@alum.mit.edu>
2023-01-12 16:36:03 +11:00
Paul Grayson f0f5c6568d rp2/machine_pwm: Fix overflows with freq > 268 MHz.
There were several places where 32-bit integer could overflow with
frequencies of 2^28 Hz or above (~268 MHz).  This fixes those overflows and
also introduces rounding for more accurate duty_ns computations.

Signed-off-by: Paul Grayson <pdg@alum.mit.edu>
2023-01-12 16:28:12 +11:00
Paul Grayson b5823604a0 rp2/machine_pwm: Use more accurate formulas for freq and duty_u16.
This changes the freq() and duty_u16() functions to use more simpler, more
accurate formulas, in particular increasing the frequency accuracy from a
few percent to a fraction of a percent in many cases.

Signed-off-by: Paul Grayson <pdg@alum.mit.edu>
2023-01-12 16:28:00 +11:00
Felix Dörre 439298be15 rp2: Fix lightsleep to work with interrupts and cyw43 driver.
This commit prevents the device from "hanging" when using lightsleep while
the WiFi chip is active.

Whenever the WiFi chip wants to interrupt the microcontroller to notify it
for a new package, it sets the CYW43_PIN_WL_HOST_WAKE pin to high,
triggering an IRQ.  However, as polling the chip cannot happen in an
interrupt handler, it subsequently notifies the pendsv-service to do a poll
as soon as the interrupt handler ended.  In order to prevent a new
interrupt from happening immediately afterwards, even before the poll has
run, the IRQ handler disables interrupts from the pin.

The first problem occurs, when a WiFi package arrives while the main loop
is in cyw43-code.  In order to prevent concurrent access of the hardware,
the network code blocks pendsv from running again while entering lwIP code.

The same holds for direct cyw43 code (like changing the cyw43-gpios, i.e.
the LED on the Pico W).  While the pendsv is disabled, interrupts can still
occur to schedule a poll (and disable further interrupts), but it will not
run.  This can happen while the microcontroller is anywhere in rp2040 code.

In order to preserve power while waiting for cyw43 responses,
cyw43_configport.h defines CYW43_DO_IOCTL_WAIT and
CYW43_SDPCM_SEND_COMMON_WAIT to __WFI().  While this might work in most
cases, there are 2 edge cases where it fails:
- When an interrupt has already been received by the cyw43 stack, for
  example due to an incoming ethernet packet.
- When the interrupt from the cyw43 response comes before the
  microcontroller entered the __WFI() instruction.

When that happens, wfi will just block forever as no further interrupts are
received.  The only way to safely use wfi to wake up from an interrupt is
inside a critical section, as this delays interrupts until the wfi is
entered, possibly resuming immediately until interrupts are reenabled and
the interrupt handler is run.  Additionally this critical section needs to
check whether the interrupt has already been disabled and pendsv was
triggered, as in such a case, wfi can never be woken up, and needs to be
skipped, because there is already a package from the network chip waiting.
Note that this turns cyw43_yield into a nop (and thereby the cyw43-loops
into busy waits) from the second time onwards, as after the first call, a
pendsv request will definitely be pending.  More logic could be added, to
explicitly enable the interrupt in this case.

Regarding lightsleep, this code has a similar problem.  When an interrupt
occurs during lightsleep, the IRQ and pendsv handler and thereby poll are
run immediately, with the clocks still disabled, causing the SPI transfers
to fail.  If we don't want to add complex logic inside the IRQ handler we
need to protect the whole lightsleep procedure form interrupts with a
critical section, exiting out early if an interrupt is pending for whatever
reason.  Only then we can start to shut down clocks and only enable
interrupts when the system is ready again.  Other interrupt handlers might
also be happy, that they are only run when the system is fully operational.

Tested on a Pico W, calling machine.lightsleep() within an endless loop and
pinging from the outside.
2022-12-20 15:54:51 +11:00
Jim Mussared 5f8f32f917 extmod/modnetwork: Use a type protocol to implement NIC functions.
This was previously implemented by adding additional members to the
mp_obj_type_t defined for each NIC, which is difficult to do cleanly with
the new object type slots mechanism. The way this works is also not
supported on GCC 8.x and below.

Instead replace it with the type protocol, which is a much simpler way of
achieving the same thing.

This affects the WizNet (in non-LWIP mode) and Nina NIC drivers.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-12-15 17:40:06 +11:00
iabdalkader e35bcb0f0b rp2/boards/ARDUINO_NANO_RP2040: Add more modules and enable MD5 hash.
Changes in this commit are:
- Enable MD5 hash to verify Nina WiFi firmware.
- Add ntptime, urequests and espflash to manifest.
2022-11-14 19:06:51 +11:00
Angus Gratton c8913fdbfa rp2: Allow enabling USB device without enabling USB-CDC.
Requires changing the USB-CDC stdin/stdout guards from
MICROPY_HW_ENABLE_USBDEV to the new (in this port)
MICROPY_HW_USB_CDC.
2022-11-11 16:49:18 +11:00
Angus Gratton 2e6e53057b shared/tinyusb: Further refactor static USB device implementation.
App the mp_ prefix to usbd_ symbols and files which are defined here and
not in TinyUSB.

rp2 only for now. This includes some groundwork for dynamic USB devices
(defined in Python).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2022-11-11 16:47:36 +11:00
Blake Felt eed4eb2645 shared/tinyusb: Create common TinyUSB code for reuse by ports.
This code originates from the rp2 port, and the rp2 port has been updated
to use this common code.
2022-11-11 16:33:30 +11:00
robert-hh acadc0a7dc rp2/modmachine: Move dht_readinto() to the machine module. 2022-11-09 15:57:17 +11:00
iabdalkader 345f1d2395 rp2/cyw43_configport: Make sure only core0 executes a __WFI().
This commit executes __WFI() on core 0 only to avoid core1 locking up since
it doesn't enable any interrupts by default (except for `SIO_IRQ_PROC1`).
This fixes a lockup when calling `cyw43_do_ioctl` from core1.

Fixes issue #9597.
2022-11-09 12:00:10 +11:00
robert-hh 8447fef9f9 rp2/mphalport: Add a timeout to mp_hal_stdout_tx_strn().
If USB CDC is connected and the board sends data, but the host does not
receive the data, the device locks up.  This is fixed in this commit by
having a timeout of 500ms, after which time the transmission is skipped.

Fixes issue #9634.
2022-11-09 11:12:53 +11:00
Damien George 8874a09119 extmod/mbedtls: Enable elliptic curve DH and DSA cryptography.
This is necessary to access sites that only support these protocols.

The rp2 port already has ECDH enabled, so this just adds ECDSA there.  The
other ports now gain both ECDH and ECDSA.  The code size increase is:

- rp2 (PICO_W): +2916 bytes flash, +24 bytes BSS
- stm32 (PYBD_SF6): +20480 bytes flash, +32 bytes data, +48 bytes BSS
- mimxrt (TEENSY41): +20708 bytes flash, +32 bytes data, +48 bytes BSS
- unix (standard x86-64): +39344 executable, +1744 bytes data, +96 BSS

This is obviously a large increase in code size.  But there doesn't seem to
be any other option because without elliptic curve cryptography devices are
partially cut off from the internet.  For use cases that require small
firmware size, they'll need to build custom firmware with a custom mbedtls
config.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:08:21 +11:00
Damien George 9347545f9e extmod/mbedtls: Enable MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE.
This was already enabled on all ports except mimxrt.  Now it's enabled on
all of them.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:06:21 +11:00
Damien George b337678964 extmod/mbedtls: Add common configuration file, and use it in all ports.
This is a no-op change.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:06:21 +11:00
iabdalkader 22ad45fda6 rp2: Rename machine I2C type consistently across ports.
This renames:
- machine_hw_i2c_type -> machine_i2c_type
2022-10-22 12:56:58 +11:00
robert-hh 92d9118038 rp2/fatfs_port: Fix the modification date of files.
It was off by 2000 % 128 == 80 years.

Addresses issue #9535.
2022-10-12 00:31:38 +11:00
Jim Mussared 924a3e03ec top: Replace upip with mip everywhere.
Updates all README.md and docs, and manifests to `require("mip")`.

Also extend and improve the documentation on freezing and packaging.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-30 17:34:03 +10:00
Matt Trentini bdbc44474f rp2/boards/WEACTSTUDIO: Add WEACTSTUDIO with multiple variants.
This supports 2, 4, 8 and 16MB flash variants.
2022-09-26 12:40:14 +10:00
Matt Trentini 0bc1d10557 rp2/Makefile: Add support for BOARD_VARIANTS.
Following stm32.  This allows a single board definition to define variants
of its configuration.
2022-09-26 12:38:58 +10:00
Jim Mussared 94beeabd2e py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other
methods.

This is a marginal code size improvement because most types have a make_new
(100/138 on PYBV11), however it improves consistency in how types are
declared, removing the special case for make_new.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:15 +10:00
Jim Mussared 6da41b5900 py/obj: Merge getiter and iternext mp_obj_type_t slots.
The goal here is to remove a slot (making way to turn make_new into a slot)
as well as reduce code size by the ~40 references to mp_identity_getiter
and mp_stream_unbuffered_iter.

This introduces two new type flags:
- MP_TYPE_FLAG_ITER_IS_ITERNEXT: This means that the "iter" slot in the
  type is "iternext", and should use the identity getiter.
- MP_TYPE_FLAG_ITER_IS_CUSTOM: This means that the "iter" slot is a pointer
  to a mp_getiter_iternext_custom_t instance, which then defines both
  getiter and iternext.

And a third flag that is the OR of both, MP_TYPE_FLAG_ITER_IS_STREAM: This
means that the type should use the identity getiter, and
mp_stream_unbuffered_iter as iternext.

Finally, MP_TYPE_FLAG_ITER_IS_GETITER is defined as a no-op flag to give
the default case where "iter" is "getiter".

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:13 +10:00
Jim Mussared a52cd5b07d py/obj: Add accessors for type slots and use everywhere.
This is a no-op, but sets the stage for changing the mp_obj_type_t
representation.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:07 +10:00
Jim Mussared 9dce82776d all: Remove unnecessary locals_dict cast.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 662b9761b3 all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE.
In preparation for upcoming rework of mp_obj_type_t layout.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared ca51d63c37 rp2/Makefile: Add link to build troubleshooting on failure.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-15 12:22:18 +10:00
Jim Mussared dec0ff7a10 rp2/boards: Remove all I2C,SPI pin defs that already match pico-sdk.
I.e. for whichever SPI/I2C instance is PICO_DEFAULT_I2C, there's no need to
set MICROPY_HW_SPIn_SCK.

The only ones remaining are for the non-default instance.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-08 14:51:15 +10:00
Jim Mussared 315e74236f rp2/machine_i2c: Use pico-sdk's default pins for I2C.
Inherits the default values for whichever instance is PICO_DEFAULT_I2C.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-08 14:51:11 +10:00
Jim Mussared 29437205f2 rp2/machine_spi: Use pico-sdk's default pins for SPI.
Rather than hardcoding the defaults, use pico-sdk's board definition.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-08 14:51:04 +10:00
Jim Mussared c364301817 rp2/boards: Set PICO_BOARD correctly for each board.
In most cases, it's calculated automatically from the board name, and so
doesn't need to be set at all.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-08 14:50:54 +10:00
Phil Howard 6aa3c94634 rp2/rp2_flash: Add start/len support to rp2.Flash() constructor.
This allows support for partitioned flash on rp2 boards.

See issue #9208.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2022-09-08 14:37:41 +10:00
Jim Mussared d84c6ef0e8 ports: Use micropython-lib version of drivers in manifests. 2022-09-08 11:27:05 +10:00
Jim Mussared 203dae41fb all: Update all manifest.py files to use new features.
Changes in this commit:
- Manifest include's now use the directory path where possible (no longer
  necessary to include the manifest.py file explicitly).
- Add manifest.py for all drivers and components that are referenced by
  port/board manifests.
- Replace all uses of freeze() with package()/module(), except for port and
  board modules.
- Use opt=3 everywhere, for consistency and to reduce code size.
- Use require() instead of include() for all micropython-lib references.
- Remove support for optional board-level manifest.py in mimxrt port, to
  make it behave the same as other ports (the board must set
  FROZEN_MANIFEST to a custom manifest.py, which can optionally include the
  default, port-level manifest).
- Also reinstates modules that were accidentally removed from the esp8266
  512k build in fbe9417b90.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-09-05 18:43:18 +10:00
Jim Mussared da7f2537a1 top: Use micropython-lib unconditionally in manifests.
micropython-lib is now a submodule, and the manifest compilation process
will ensure it is available, so manifests no longer need to check that it
is available.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-05 17:00:43 +10:00
hoihu 85a25895ff rp2/mbedtls: Fix missing time.h include. 2022-08-31 00:22:34 +10:00
robert-hh 2488311dc2 rp2/machine_uart: Implement uart.flush() and uart.txdone().
uart.flush()

flush() will wait until all characters have been sent. It may return
while the last character is sent. if needed, the calling code has to
add one character wait time. To avoid a permanent lock, a timeout
applies depending on the size of txbuf and the baud rate.

ret = uart.txdone()

ret is True if no transfer is in progress. It may return True if the
last byte of a transfer is sent.
ret is False otherwise.
2022-08-31 00:17:54 +10:00
Jim Mussared 8a0ee5a5c0 py/objstr: Split mp_obj_str_from_vstr into bytes/str versions.
Previously the desired output type was specified.  Now make the type part
of the function name.  Because this function is used in a few places this
saves code size due to smaller call-site.

This makes `mp_obj_new_str_type_from_vstr` a private function of objstr.c
(which is almost the only place where the output type isn't a compile-time
constant).

This saves ~140 bytes on PYBV11.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-26 16:43:55 +10:00
robert-hh 47c45d0e7f rp2/machine_wdt: Check for the maximum timeout value of watchdog.
The value will be checked for timeout <= 8388.  Notes were added to the
documentation.
2022-08-23 16:26:29 +10:00
Jacob Siverskog 0546a12238 rp2: Correctly determine path to arm-none-eabi-size.
Figure out path to arm-none-eabi-size the same way it's done for the
other binaries, instead of assuming it to be in the user's $PATH.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2022-08-11 14:23:28 +10:00
Phil Howard 71f6eb5ac9 rp2: Mark gc_heap NOLOAD for faster boot.
Create a new linker section .unitialized_bss for bss that does not need
zero-initialising.

Move gc_heap to this section, which saves ~30ms from rising edge of RESET
to setting a pin HIGH in MicroPython.

Zero fill happens in Pico SDK crt0.S before ROSC is configured.  It's very,
very slow.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2022-08-11 14:16:29 +10:00
omogenot 6e51dbd95a rp2/boards/W5500_EVB_PICO: Add new board definition for W5500_EVB_PICO.
Signed-off-by: github@mymeterinfo.info
2022-08-11 14:12:55 +10:00
Damien George f72d3cec23 rp2/machine_spi: Add mp_hal_get_spi_obj helper function.
And remove the now-obsolete spi_from_mp_obj() function.

Signed-off-by: Damien George <damien@micropython.org>
2022-08-10 14:05:02 +10:00
Ian Davies fbe9417b90 extmod/ntptime: Factor out ntptime module from esp8266 port.
The ntptime module was previously only included in the ESP8266 port.  This
commit factors that module out into the extmod directory, makes it support
different epochs, and includes it in the rp2 port.
2022-08-06 00:08:32 +10:00
Ian Davies b560b9fe71 rp2/mbedtls: Enable certificate validity time validation. 2022-08-06 00:08:01 +10:00
Jim Mussared 9a7ac41be6 rp2/Makefile: Always use cmake to discover submodules.
Used to be special-cased for Pico, but now everything depends on
micropython-lib if it's using a frozen manifest.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-03 00:05:54 +10:00
Peter Harper 45ab801c30 rp2/cyw43_configport: Add event hook into cyw43_delay_ms.
Still see some USB issues apparently caused by delays loading wifi
firmware.  cyw43_delay_ms is used to wait in the driver, so we should call
the event hook in there.

Fixes #8963.
2022-07-27 13:42:21 +10:00
Jim Mussared 092784da19 ports: Remove unused mp_type_{fileio/textio} macros in mpconfigport.h.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-26 18:07:22 +10:00
robert-hh 0c45a28d24 rp2/rp2_pio: Fix StateMachine.restart when PIO program is shared.
The state machines were not properly restarted in the case that the same
PIO program was shared among multiple StateMachine instances.  This is
because only the first StateMachine to use the program would set the
rp2_state_machine_initial_pc variable.

See https://forum.micropython.org/viewtopic.php?f=21&t=12776&p=69464#p69464
2022-07-26 02:00:01 +10:00
Damien George f64862a766 rp2/cyw43_configport: Set CYW43_WIFI_NVRAM_INCLUDE_FILE value.
Required for latest cyw43-driver.

Signed-off-by: Damien George <damien@micropython.org>
2022-07-26 01:39:30 +10:00
Peter Harper 33d6994d4c rp2/cyw43_configport: Set CYW43_EVENT_POLL_HOOK value.
This should allow USB to work while we're loading WiFi firmware.

Fixes issue #8904.
2022-07-26 01:39:08 +10:00
Jim Mussared a053827084 extmod/network_ninaw10: Move ninaw10 root pointer registrations here.
Originally in drivers/ninaw10/nina_wifi_bsp.c but that isn't a QSTR source.

Also remove outdated commment about root pointers in mpconfigport.h.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-21 16:21:50 +10:00
Jim Mussared 8b4298a4bf rp2/mpbthciport: Remove mp_bthci_uart from set of root pointers.
This is a statically-allocated UART (see machine_uart.c), and doesn't
contain any heap pointers other than the ringbufs (which are already root
pointers), so no need to track it additionally.

Saves needing to add mpbthciport.c to the QSTR sources.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-21 16:19:42 +10:00
robert-hh 80339f1a33 ports: Adapt mimxrt, nrf and rp2 ports to work with latest TinyUSB.
rp2: change tud_task() to tud_task_ext().

mimxrt: use lib/tinyusb/src/portable/chipidea/ci_hs/dcd_ci_hs.c instead of
lib/tinyusb/src/portable/nxp/transdimension/dcd_transdimension.c.

nrf: add a definition for the changed tud_task().  tud_task() is changed
to tud_task_ext(), and the #define for backward compatibility is in
src/device/usbd.h.

The items I know which are fixed with this version:
- Fix for the SAMD USB lock-up.
- Support the MIMXRT11XX series of MCUs.
- Fix a wrong pin definition for MIMXRT1050_EVKB.

Tested with the MIMXRT boards, rp2 Pico, SAMD boards, nrf board.
2022-07-19 11:27:21 +10:00
Damien George b89422ceaa extmod: Always use custom mbedtls error message code.
All ports that use mbedtls use the custom error messages in
mp_mbedtls_errors.c.  This commit simplifies the build so that ports don't
need to explicitly add this file, it's now used by default when mbedtls is
enabled.

Signed-off-by: Damien George <damien@micropython.org>
2022-07-18 22:55:22 +10:00
David Lechner 7e4b205cb0 py/mpstate: Drop MICROPY_PORT_ROOT_POINTERS from mp_state_vm_t.
All in-tree uses of MICROPY_PORT_ROOT_POINTERS have been replaced with
MP_REGISTER_ROOT_POINTER(), so now we can remove both
MICROPY_PORT_ROOT_POINTERS and MICROPY_BOARD_ROOT_POINTERS from the code
and remaining config files.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:51:16 +10:00
David Lechner ffa22b8f97 rp2: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register all port-specific root
pointers in the rp2 port.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:34 +10:00
David Lechner a3703584fe extmod/modnetwork: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register mod_network_nic_list and
removes the same from all mpconfigport.h.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:25 +10:00
David Lechner e531b72b56 extmod/nimble: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register bluetooth_nimble_memory
and bluetooth_nimble_root_pointers and removes the same from all
mpconfigport.h.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:14 +10:00
David Lechner ac86e8449a drivers/ninaw10/nina_wifi_bsp: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register mp_wifi_spi, mp_wifi_timer
and mp_wifi_sockpoll_list and removes the same from all mpconfigport.h.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:49:28 +10:00
David Lechner 81dbea1ce3 shared/readline: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register the readline_history root
pointer array used by shared/readline.c and removes the registration from
all mpconfigport.h files.

This also required adding a new MICROPY_READLINE_HISTORY_SIZE config option
since not all ports used the same sized array.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:48:49 +10:00
Jim Mussared 74794d42b8 rp2/CMakeLists: Use armv6m mpy-cross arch for rp2.
Commit 0e28a1f0e5 made it possible to set
-march=armv6m.  It needs to be used when freezing for rp2.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-12 23:50:19 +10:00
Peter Harper 9f0f7e34c7 rp2/mphalport: Fix missing storage_read_blocks symbol in debug build.
When building `make BOARD=PICO_W DEBUG=1` the cyw43-driver requires
storage_read_blocks().

Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
2022-07-12 16:56:38 +10:00
Jim Mussared c5563aa024 rp2/mpconfigport: Make networking options consistent across boards.
Enable the same set of networking features on boards with wifi/ethernet.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-12 16:28:44 +10:00
Jim Mussared 662dc8602b rp2: Make atomic sections suspend the other core (if active).
When a flash write/erase is in progress, we need to ensure that the
other core cannot be using XIP.

This also implements MICROPY_BEGIN_ATOMIC_SECTION as a full mutex, which
is necessary as it's used to syncronise access to things like the scheduler
queue.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-12 16:20:21 +10:00
Jim Mussared daff597753 rp2: Run USB stack task exclusively from core 0.
The goal is to avoid a situation where core 1 is shut down while holding
the tinyusb spinlock, which could happen during soft reset if
mp_thread_deinit is called while core1 is running tud_task().

This also fixes a latent race where the two cores are competing to
decrement and compare `vm_hook_divisor` with no mem fence or atomic
protection -- only core0 will now do this.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-12 16:17:19 +10:00
Jim Mussared 2efaebc899 rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Add urequests module.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-05 23:03:02 +10:00
Jim Mussared 11ef618bbc rp2/CMakeLists: Don't override cyw43-driver unless necessary.
This supresses a warning from pico-sdk when the board isn't using this
driver.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-05 23:00:43 +10:00
Jim Mussared 5f4143dd40 rp2/CMakeLists: Give error if required submodules are missing.
Ensure that nimble and cyw43-driver are initialised when the board requires
it.  Also make these work with `make submodules`.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-05 23:00:36 +10:00
Jim Mussared 651b370484 rp2/Makefile: Regenerate cmake if generated Makefile missing.
`CMakeCache.txt` can exist even if cmake failed. Use `Makefile` instead.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-05 22:47:06 +10:00
Damien George 85be3d3da8 rp2/mpconfigport: Factor core event handling to EVENT_POLL_HOOK_FAST.
Signed-off-by: Damien George <damien@micropython.org>
2022-07-05 16:11:42 +10:00
Damien George 4b9a2abbde rp2/main: Set default AP auth mode to WPA2_AES_PSK.
Signed-off-by: Damien George <damien@micropython.org>
2022-07-05 11:07:16 +10:00
Damien George 3d76292f37 rp2/boards/GARATRONIC_PYBSTICK26_RP2040: Change pico-sdk board name.
This follows a similar renaming in pico-sdk.

Signed-off-by: Damien George <damien@micropython.org>
2022-07-05 09:45:44 +10:00
Damien George 99c2589778 rp2/boards/PICO_W: Add new Pico W board, an RP2040 with WiFi.
Work done in collaboration with Graham Sanderson and Peter Harper.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 17:03:51 +10:00
Damien George 50e46552c0 rp2: Integrate CYW43xx WiFi driver.
This includes:
- Configuration file for the cyw43-driver.
- Integration of cyw43-driver into the build, using lwIP.
- Enhancements to machine.Pin to support extension IO pins provided by the
  CYW43xx.
- More mp-hal pin helper functions.
- mp_hal_get_mac_ascii MAC address helper function.
- Addition of rp2.country() function to set the country code.

A board can enable this driver by setting MICROPY_PY_NETWORK_CYW43 in their
cmake snippet.

Work done in collaboration with Graham Sanderson and Peter Harper.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 17:03:51 +10:00
Damien George c001cfa603 rp2/mpnetworkport: Convert network task scheduling to use PendSV IRQ.
It is more reliable and scales better when more components need it.

Work done in collaboration with Graham Sanderson and Peter Harper.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 17:03:47 +10:00
Damien George 7cdad05e54 rp2/rp2_flash: Add asserts for size of flash filesystem partition.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 16:03:21 +10:00
Damien George c95f99105a rp2/lwip_inc: Enable lwIP status callback.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 16:03:21 +10:00
Damien George 11f920f8ad rp2/mbedtls: Enable some more mbedtls options.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 16:03:21 +10:00
Jim Mussared 797a83ac3e rp2/mpthreadport: Ensure core1 doesn't hold gc lock in deinit.
Prior to this commit the following code would lock up the device when
Ctrl-D is entered at the REPL:

    import gc, _thread

    def collect_thread():
        while True:
            gc.collect()

    _thread.start_new_thread(collect_thread, [])

Fixes part of #8494.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-06-30 11:53:25 +10:00
Damien George b004e7e397 rp2/modmachine: Implement lightsleep() with optional sleep period.
This gets basic machine.lightsleep([n]) behaviour working on the rp2 port.
It supports:

- Calling lightsleep without a specified period, in which case it uses xosc
  dormant mode.  There's currently no way to wake it up from this state,
  unless you write to raw registers to enable a GPIO wake up source.

- Calling lightsleep with a period n in milliseconds.  This period must be
  less than about 72 minutes and uses timer alarm3 to wake it up.

The RTC continues to run during lightsleep, but other peripherals have
their clock turned off during the sleep.

It doesn't yet support longer periods than 72 minutes, or waking up from
GPIO IRQ.

Measured current consumption from the USB port on a PICO board is about
1.5mA when doing machine.lightsleep(5000), and about 0.9mA when doing
machine.lightsleep().

Addresses issue #8770.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 11:40:17 +10:00
iabdalkader de823e7741 rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Enable Arduino 1200bps touch. 2022-06-23 14:32:56 +10:00
Damien George f5769698e5 extmod/modlwip: Clean up inclusion of modlwip in build process.
The following changes are made:

- Guard entire file with MICROPY_PY_LWIP, so it can be included in the
  build while still being disabled (for consistency with other extmod
  modules).

- Add modlwip.c to list of all extmod source in py/py.mk and
  extmod/extmod.cmake so all ports can easily use it.

- Move generic modlwip GIT_SUBMODULES build configuration code from
  ports/rp2/CMakeLists.txt to extmod/extmod.cmake, so it can be reused by
  other ports.

- Remove now unnecessary inclusion of modlwip.c in EXTMOD_SRC_C in esp8266
  port, and in SRC_QSTR in mimxrt port.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-20 23:37:38 +10:00
iabdalkader f522aabab2 rp2/modmachine: Allow boards to provide custom bootloader code.
And expose the machine_bootloader() C function so it can be used elsewhere.
2022-06-17 13:38:21 +10:00
Andrew Scheller cedb93c179 docs: Update Raspberry Pi URLs from .org to .com. 2022-06-14 11:41:13 +10:00
Damien George bd375df02c extmod/extmod.cmake: Require components to be explicitly enabled.
Otherwise include directories are added unconditionally to the build
variables if the component (submodule) is checked out.  This can lead to,
eg, the esp32 build using lib/lwip header files, instead of lwip header
files from the IDF.

Fixes issue #8727.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-08 13:03:34 +10:00
Damien George 9670a156da all: Rename MICROPY_PY_WIZNET5K to MICROPY_PY_NETWORK_WIZNET5K.
To match MICROPY_PY_NETWORK_CYW43 and MICROPY_PY_NETWORK_NINAW10.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-07 16:55:18 +10:00