Wykres commitów

96 Commity (master)

Autor SHA1 Wiadomość Data
Angus Gratton 0baa3b5528 rp2: Enable support for Python USB devices.
This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-15 14:24:52 +11:00
Damien George bfc3dde2c9 extmod/modmachine: Add MICROPY_PY_MACHINE_RESET configuration option.
Disabled by default, but enabled on all boards that previously had
`MICROPY_PY_MACHINE_BARE_METAL_FUNCS` enabled.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-15 12:04:37 +11:00
Damien George efa54c27b9 rp2/mpconfigport: Allow MICROPY_PY_THREAD to be disabled by a board.
Signed-off-by: Damien George <damien@micropython.org>
2024-01-16 11:42:47 +11:00
Damien George 0640ff3b97 ports: Move MICROPY_INTERNAL_WFE definition to mphalport.h.
It belongs here because the default value is defined in py/mphal.h.

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

Signed-off-by: Damien George <damien@micropython.org>
2024-01-05 15:40:06 +11:00
Damien George a78ec4ef7b rp2/mpconfigport: Enable MICROPY_PY_OS_DUPTERM_NOTIFY.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-18 12:20:47 +11:00
Angus Gratton 28529351ae rp2: Switch rp2 and drivers to use new event functions.
This commit changes all uses in the rp2 port, and drivers that are
optionally supported by that port.

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

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

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 12:49:43 +11:00
Damien George ad806df857 ports: Move definitions of ATOMIC_SECTION macros to mphalport.h.
Also move MICROPY_PY_PENDSV_ENTER/REENTER/EXIT to mphalport.h, for ports
where these are not already there.

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

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

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

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

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

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

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
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
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 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 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 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
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
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
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
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 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
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
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
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
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
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
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 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
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
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
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
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
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 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