Wykres commitów

3639 Commity (0a3264ba9636f0414078fa0c498178eae2994118)

Autor SHA1 Wiadomość Data
Damien George 87cf439e0d stm32/adc: Add support for STM32L4A6 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-05-24 11:25:50 +10:00
Jim Mussared 0ba08e6299 stm32/boards/NUCLEO_G474RE: Make it easier to enable USB.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-24 11:13:23 +10:00
Jim Mussared f4b4d05e49 stm32/usb: Fix USB support on STM32G4.
Also fix MAX_ENDPOINT definition for G0, which follows G4.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-24 11:12:45 +10:00
robert-hh 5707fd74e5 mimxrt/boards/ADAFRUIT_METRO_M7: Add Adafruit Metro M7 board definition.
Support for WiFi and BLE is in progress.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-23 16:54:39 +10:00
iabdalkader 8d446b2ad5 mimxrt/led: Add support for up to four LEDs.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-23 10:54:23 +10:00
Yilin Sun 0f0dcec984 mimxrt/sdcard: Fix GCC 13 build error with sdcard_cmd_set_bus_width.
This updates the declaration of 'sdcard_cmd_set_bus_width()' to the same as
its definition.

Signed-off-by: Yilin Sun <imi415@imi.moe>
2023-05-23 10:38:13 +10:00
robert-hh c3f031afac samd/boards/ADAFRUIT_METRO_M4_EXPRESS: Add Metro M4 Express Airlift.
The board files can be used for both Adafruit Metro M4 variants.  The Wifi
support is in progress.
2023-05-23 10:17:16 +10:00
robert-hh 20fd22edad samd/machine_uart: Add support for UART hardware flow control.
By specifying rts=pin(x) and/or cts=Pin(x) in the constructor.  The pad
numbers for the UART pins are fix in this case: TX must be at pad 0, RX at
pad 1, RTS at pad 2 and CTS at pad 3.

repr(uart) shows the pin names for rts and cts, if set.  In case of a RX
overflow, the rx interrupt will be disabled instead of just discarding the
data.  That allows RTS to act.

If RTS is inactive, still 2 bytes can be buffered in the FIFO.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-23 09:53:24 +10:00
robert-hh 2a38531d73 samd/mcu: Reduce the startup time after hard reset.
With Crystal: set the crystal startup wait time to 1 second.  It was 2
seconds before, and that seeemed too long.

With USB-Sync: scan for up to 1 second for the USB to be registered and
carry on with boot as soon as it it.  Before, the code just waited for
500ms.

Side change: improve related comments.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:41:48 +10:00
robert-hh 984456731b samd/boards/SEEED_WIO_TERMINAL: Rename two pins starting with a digit.
So the names don't start with a digit, which isn't allowed in Python.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:40:23 +10:00
robert-hh 47fa723586 samd/modmachine: Make some machine classes configurable by #defines.
These include ADC, DAC, I2C, SoftI2C, SPI, SoftI2C, PWM, UART, pulse.  This
is useful for devices like the Adafruit Trinket series which have almost no
accessible GPIO pins.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:39:07 +10:00
robert-hh b2df094bf8 samd/modmachine: Add machine.deepsleep as alias of machine.lightsleep.
Just for coverage.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:38:51 +10:00
robert-hh 7a847bab1e samd/main: Fix sercom deinit ordering in soft-reset.
If sockets were open when calling soft reset, gc_sweep_all() would try to
close them.  In case of e.g. the NINA WiFi handler, connected through SPI,
spi_transfer() would be called for command exchange with the NINA module.
But at that time SerCom was already disabled.

Moving sercom_deinit_all() behind gc_sweep_all() solves this issue.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:37:35 +10:00
robert-hh b7180d53f0 samd/boards: Add default deploy instructions.
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:37:24 +10:00
robert-hh 05e684dc07 samd/mcu/samd51: Enable MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF.
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:37:11 +10:00
robert-hh 315eb949da samd: Rearrange the MCU-specific loader files.
Such that they are easier to adapt.  The maximum code size is set by:

    MICROPY_HW_CODESIZE=xxxK

in mpconfigmcu.mk for the MCU family as default or in mpconfigboard.mk for
a specific board.  Setting the maximum code size allows the loader to error
out if the code gets larger than the space dedicated for it.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:36:29 +10:00
robert-hh 457d9ee68a samd/boards/MINISAM_M4: Update pins.csv for the Mini SAM M4 board.
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:36:07 +10:00
robert-hh 267d1ab2ba samd/mpconfigport: Drop support for SoftSPI max speed.
Saves ~140 bytes and is not really needed, since for higher baud rates hard
SPI is available.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:35:45 +10:00
patrick a802f71908 esp32/uart: Use xtal as UART clock source on S3 and C3.
Change UART clock source on S3/C3 so the UART can operate when CPU
frequency is below 80MHz.  This allows the UART to remain operational when
using Dynamic Frequency Scaling (DFS).

Signed-off-by: Patrick Joy <patrick@joytech.com.au>
2023-05-22 10:11:24 +10:00
patrick 05e143dbdd esp32/esp32_ulp: Enable FSM ULP for S2 and S3 chips.
This commit enables the ULP for the S2 and S3 chips.

Note this is the FSM (Finite State Machine) ULP.

Signed-off-by: Patrick Joy <patrick@joytech.com.au>
2023-05-19 22:37:25 +10:00
UnexpectedMaker 3a7ad64267 esp32/boards: Add some missing board configs for two UM boards. 2023-05-19 22:30:42 +10:00
iabdalkader bfcaf39197 stm32/irq: Fix typo in comment about priorities.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-19 22:23:33 +10:00
iabdalkader 70b60fe24e renesas-ra/irq: Fix typo in comment about IRQ priorities.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-19 22:23:10 +10:00
Andrew Leech f03ac04321 stm32/mboot: Fix alignment of packed final buffer.
Once all the firmware has been flashed and the final signatures checked,
mboot writes the "all good" byte into the header of the application.  This
step uses the buffer firmware_head which, if unaligned in the build, fails
when cast to a uint64_t* in flash.c.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-05-19 22:16:53 +10:00
brave ulysses ad216be5f1 stm32/boards/stm32h723_af.csv: Fix ADC AF definitions.
These were incorrectly added in d995c01042.
The fix here includes the full differential ADC definitions.

Signed-off-by: brave ulysses <brave_ulysses@email.com>
2023-05-19 22:12:05 +10:00
Damien George 53cb073571 esp32,esp8266: Change network.WLAN from a function to a type.
When the network module was first introduced in the esp8266 port in
ee3fec3167 there was only one interface (STA)
and, to save flash, the WLAN object was aliased to the network module,
which had just static methods for WLAN operations.  This was subsequently
changed in 9e8396accb when the AP interface
was introduced, and the WLAN object became a true class.

But, network.WLAN remained a function that returned either the STA or AP
object and was never upgraded to the type itself.  This scheme was then
copied over to the esp32 port when it was first introduced.

This commit changes network.WLAN from a function to a reference to the WLAN
type.  This makes it consistent with other ports and network objects, and
allows accessing constants of network.WLAN without creating an instance.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-18 14:52:28 +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
Takeo Takahashi 3229791b60 renesas-ra: Add a macro definition to avoid compile error of FSP v4.4.0.
FSP v4.4.0 refers to CMSIS V5.4.1, and __COMPILER_BARRIER() is used in bsp.
On the other hand, lib/cmsis is V5.1.0 and the macro is not defined.
Therefore, compile error happens.
As the workaround, the macro definition is added.
If lib/cmsis is updated in the future, this addition can be removed.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-05-11 16:18:39 +10:00
Takeo Takahashi b4834e5cba renesas-ra: Update boards and ra directory files to support FSP v4.4.0.
* Update boards and ra files
* Remove unreferenced files, board_init.c and board_leds.c, from Makefile
* Remove unreferenced FSP instances from ra_gen/*.[ch]
* Remove unreferenced FSP config files ra_cfg/*.h
* e2 studio generates FSP instances but renesas-ra uses only followings:
  lpm, flash, ioport

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-05-11 16:18:39 +10:00
David Lechner 6a4a9bc147 windows/Makefile: Allow variants to add QSTR_DEFS.
This modifies the windows port Makefile to use += for QSTR_DEFS and
QSTR_GLOBAL_DEPENDENCIES so that variants can add additional files if
needed (similar to stm32 port).

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-11 14:34:15 +10:00
David Lechner 6836acf3dc unix/Makefile: Allow variants to add QSTR_DEFS.
This modifies the unix port Makefile to use += for QSTR_DEFS and
QSTR_GLOBAL_DEPENDENCIES so that variants can add additional files if
needed (similar to stm32 port).

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-11 14:34:01 +10:00
robert-hh 65d376b11d mimxrt/machine_pin: Perform full configuration in machine_pin_set_mode.
machine_pin_set_mode() is used by the internal mp_hal_pin_xxx() set of
functions to configure pins.
2023-05-09 16:15:05 +10:00
robert-hh 14b862f70f mimxrt/machine_spi: Ignore transfers with len=0.
It was treated as an error before.  The error surfaced when using the
NINAW10 drivers for WiFi support.  Even if this is a bad behavior of the
NINA driver, machine_spi can be forgiving in that situation.
2023-05-09 16:14:40 +10:00
robert-hh d2a02dcee3 mimxrt: Add missing UART defintion and remove obsolete config.
Changes in this commit:
- Add a missing UART defintion for MIMXRT1010_EVK.
- Remove an obsolete line from mpconfigport.h.
2023-05-09 16:13:51 +10:00
robert-hh facc51f3ea mimxrt/mpconfigport: Add back lost uos.urandom().
It got lost in a clean-up session recently.
2023-05-09 16:13:27 +10:00
Philipp Ebensberger a3f3b9045c mimxrt/flash: Separate low level driver code from flash object.
Separate low level flash access from mimxrt flash driver object.  Allows
better abstraction from hardware for testing and reuse in other areas (e.g.
bootloader).

Signed-off-by: Philipp Ebensberger <philipp.ebensberger@3bricks-software.de>
2023-05-09 15:18:36 +10:00
Jim Lipsey 7333c06d05 stm32/boards/ARDUINO_PORTENTA_H7: Enable FDCAN.
Add pin definitions to enable FDCAN support using the pyb.CAN() class.
2023-05-09 13:25:03 +10:00
glenn20 1093dea709 esp32,esp8266: Add support to set/get power saving mode of WLAN.
For esp32 and esp8266 this commit adds:
- a 'pm' option to WLAN.config() to set/get the wifi power saving mode; and
- PM_NONE, PM_PERFORMANCE and PM_POWERSAVE constants to the WLAN class.

This API should be general enough to use with all WLAN drivers.

Documentation is also added.
2023-05-06 13:51:00 +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 2ac643c15b esp8266/machine_pwm: Implement duty_u16() and duty_ns() for consistency.
Also adds these keyword arguments to the constructor and init method.
2023-05-04 13:17:55 +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
robert-hh 250757716a samd/machine_pwm: Add init() method to PWM and simplify the PWM code.
The PWM.init() method has been added.  Calling init() without arguments
restarts a PWM channel stopped with deinit().  Otherwise single parameters
except for "device=n" can be changed again.  The device can only be
specified once, either in the constructor or the first init() call.

Also simplify get_pwm_config() and get_adc_config(), and shrink the PWM
object.
2023-05-04 13:10:38 +10:00
robert-hh 9c7ad68165 mimxrt/machine_pwm: Start PWM only if freq and duty are set.
And also fix/improve the following:
- Simplify the duty handling a little bit.
- Allow duty_u16(65536), which sets the output high.
- Rename machine_pwm_start() to mp_machine_pwm_start(), in preparation for
  a possible start/stop method pair.
2023-05-04 13:09:39 +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
Christian Clauss 79e57473b2 all: Fix various Python coding inconsistencies found by ruff.
This fixes:
- type-comparison (E721): do not compare types, use isinstance().
- string-dot-format-missing-arguments (F524): .format call is missing
  argument(s) for placeholder(s): {message}.
- f-string-missing-placeholders (F541).
- is-literal (F632): Use != to compare constant literals.

The last one is fixed by just comparing for truthfulness of `state`.
2023-05-02 16:14:45 +10:00
Christian Clauss 8f8bd98164 all: Fix strings with backslash by using raw string literals. 2023-05-02 11:55:02 +10:00
Glenn Moloney 7fa322afb8 esp32,esp8266: Add support for the Espressif ESP-NOW protocol.
ESP-NOW is a proprietary wireless communication protocol which supports
connectionless communication between ESP32 and ESP8266 devices, using
vendor specific WiFi frames.  This commit adds support for this protocol
through a new `espnow` module.

This commit builds on original work done by @nickzoic, @shawwwn and with
contributions from @zoland.  Features include:
- Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO.
- Signal strength (RSSI) monitoring.
- Core support in `_espnow` C module, extended by `espnow.py` module.
- Asyncio support via `aioespnow.py` module (separate to this commit).
- Docs provided at `docs/library/espnow.rst`.

Methods available in espnow.ESPNow class are:
- active(True/False)
- config(): set rx buffer size, read timeout and tx rate
- recv()/irecv()/recvinto() to read incoming messages from peers
- send() to send messages to peer devices
- any() to test if a message is ready to read
- irq() to set callback for received messages
- stats() returns transfer stats:
    (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts)
- add_peer(mac, ...) registers a peer before sending messages
- get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt)
- mod_peer(mac, ...) changes peer info parameters
- get_peers() returns all peer info tuples
- peers_table supports RSSI signal monitoring for received messages:
    {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...}

ESP8266 is a pared down version of the ESP32 ESPNow support due to code
size restrictions and differences in the low-level API.  See docs for
details.

Also included is a test suite in tests/multi_espnow.  This tests basic
espnow data transfer, multiple transfers, various message sizes, encrypted
messages (pmk and lmk), and asyncio support.

Initial work is from https://github.com/micropython/micropython/pull/4115.
Initial import of code is from:
https://github.com/nickzoic/micropython/tree/espnow-4115.
2023-05-01 16:47:21 +10:00
Carlosgg b5f4611969 lib/mbedtls_errors: Add esp32-specific mbedtls error file.
This allows updating mp_mbedtls_errors.c for the other mbedtls based ports
based on mbedTLS v2.28.1.  This esp32-specific file will not be required
after updating IDF support to >= v4.4.1.

Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-05-01 10:50:01 +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 143b863f54 zephyr/modutime: Use extmod version of time module.
API change: time.time_ns() is added, but it just returns 0.

No API or functional change to existing time functions.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:52 +10:00
Damien George fa8a81ae23 webassembly/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:52 +10:00
Damien George 127fd170c8 unix/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:52 +10:00
Damien George 996a1f911b stm32/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:52 +10:00
Damien George d7cb53cb60 samd/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 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 322c53bbc9 renesas-ra/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 a3c427898e nrf/modules/utime: Use extmod version of time module.
API additions;
- time.sleep() is added
- time.ticks_cpu() is added, but it just returns 0

No API or functional change to existing time functions.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George c234a26954 mimxrt/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 4a4046d825 esp8266/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 5be20b67df esp32/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 8ad2da93be cc3200/mods/modutime: Use extmod version of time module.
API change: time.time_ns() is added, but it just returns 0.

No API or functional change to existing time functions.

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
Takeo Takahashi dc7de6ed83 renesas-ra: Change MICROPY_HW_BOARD_NAME definition to product name.
Changes in this commit:
- Change MICROPY_HW_BOARD_NAME definition to match the product name.
- Rename board folder's name to match the product name style.
- Change related files like Makefile, document descriptions, test cases, CI
  and tools.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-04-27 14:12:53 +10:00
Damien George a14e79bcfb stm32/cyw43_configport: Provide cyw43_hal_pin_config_irq_falling func.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-26 12:57:35 +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
IcedRooibos 7ea06a3e26 esp32/esp32_rmt: Fix looping behaviour for RMT on ESP32-S3.
The previous code worked on ESP32 but not ESP32-S3.  All the IDF (v4.4.3)
examples call rmt_set_tx_loop_mode before rmt_write_items, so make that
change here.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-26 12:32:13 +10:00
Jim Mussared a42a8022d8 extmod/modbluetooth: Make all HCI transports trace in the same format.
- Use HCI_TRACE macro consistently.
 - Use the same colour formatting.
 - Add a tool to convert to .pcap for Wireshark.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +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
Jim Mussared bc9ec1cf71 extmod/modbluetooth: Merge gatts_notify/indicate implementation.
Makes gatts_notify and gatts_indicate work in the same way: by default they
send the DB value, but you can manually override the payload.

In other words, makes gatts_indicate work the same as gatts_notify.

Note: This removes support for queuing notifications and indications on
btstack when the ACL buffer is full. This functionality will be
reimplemented in a future commit.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Damien George 9e6885ad82 extmod/btstack: Switch to use hci_dump_init instead of hci_dump_open.
The latter is no longer available in the version of BTstack now in use by
this repository.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-22 00:39:31 +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
iabdalkader 0acc73344a mimxrt: Fix the build for boards without ROM API. 2023-04-12 17:01:25 +02:00
iabdalkader bde222ce84 mimxrt/modmachine: Implement machine.bootloader().
If a board defines a custom bootloader entry function it will be called
first, if not and the ROM API supports RUN bootloader API, then
`machine.bootloader()` will jump to the ROM serial downloader in USB mode.
2023-04-11 17:40:18 +10:00
iabdalkader 8b72721b29 mimxrt/mpconfigport: Allow configuring different network interfaces.
This commit allows boards to disable Ethernet and keep the networking stack
enabled, to use an alternate networking interface, such as WiFi.

Note that the `network` and `socket` modules are now enabled by default for
a board.
2023-04-11 17:20:29 +10:00
iabdalkader 944b4c2058 mimxrt/boards/MIMXRT1064_EVK: Fix board config to use internal flash.
This commit is necessary to make MicroPython work on this eval kit out of
the box, as the eval kit ships with the HyperFlash physically disconnected
from the bus (refer to the schematics or the user guide) and the QSPI
connected instead, but the fuses/board/pins are configured to boot from
internal flash (on FlexSPI2).

Note that enabling the HyperFlash is not trivial, as it requires soldering
and desoldering of many small footprint resistors and changing fuses.
2023-04-11 17:04:21 +10:00
iabdalkader ed5e3598f1 mimxrt/Makefile: Fix internal flash configuration and build. 2023-04-11 17:03:28 +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
iabdalkader db4b416ea8 mimxrt/pendsv: Clean up PendSV code.
The dispatch active flag is only set once and never reset, so it will
always call the dispatch handler (once enabled), and it's not really
needed because it doesn't make things more efficient.

Also remove unused included headers.
2023-04-05 10:16:22 +10:00
robert-hh eb6e5143c4 nrf/modules/machine/uart: Prevent UART lock-up after a receive error.
Like frame error, overrun, etc.  Fix is provided by @ricksorensen.
2023-04-05 10:00:43 +10:00
robert-hh a529e0e8cf nrf/nrfx_config: Use UARTE for nrf52xxx devices.
It was incomplete.
2023-04-05 10:00:06 +10:00
robert-hh 408556504c nrf/modules/machine/pwm: Fix resource conflict, and change id to device.
Changes in this commit:
- Move the pwm_seq array to the p_config data structure.  That prevents
  potential resource collisions between PWM devices.
- Rename the keyword argument 'id' to 'device'.  That's consistent with the
  SAMD port as the other port allowing to specify it.
2023-04-05 09:58:33 +10:00
Jan Hrudka 5652f1f661 stm32/flash: Fix get_bank function for STM32H750.
STM32H750 has only 1 flash bank so function get_bank should always return
FLASH_BANK_1.
2023-04-04 14:58:54 +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
Sebastian Romero 0a3600a9ad stm32/boards/ARDUINO_NICLA_VISION: Fix incorrect bootloader PID. 2023-03-31 17:11:14 +11: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
Damien George 31e7a0587d stm32/boards/NUCLEO_G0B1RE: Add config for USB and mboot.
But leave these disabled.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00
Damien George 31638473b7 stm32/mboot: Add support for G0 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00
Damien George c7923b1139 stm32: Add support for USB on G0 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +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
Damien George 051e2900d9 stm32/boards/NUCLEO_H723ZG: Add new H723 board.
The following have been tested and are working:
- 550MHz CPU frequency
- UART REPL via ST-Link
- USB REPL and mass storage
- 3x LEDs and 1x user button
- Ethernet

Signed-off-by: Damien George <damien@micropython.org>
2023-03-21 14:05:59 +11:00
Damien George d995c01042 stm32/boards: Add ld and af.csv for H723.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-21 14:02:49 +11:00
Damien George 13fcd8440e stm32: Add support for STM32H723 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-21 14:02:49 +11:00
Damien George 3187e4c7e7 stm32/mphalport: Update HAL version to 1.11.0 to match stm32lib.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-21 14:02:49 +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
robert-hh a2b31f968d nrf/modules/machine: Support the freq=n argument for machine.I2C.
Mostly for compatibility.  Effective values are 100000, 250000 and 400000.
The supplied values are mapped to these.
2023-03-20 16:27:44 +11:00
robert-hh 3bbf2ef3fb nrf/modules/machine: Use a dedicated function for machine.idle().
Calling MICROPY_EVENT_POLL_HOOK.  That allows Ctrl-C to break loops with
idle().
2023-03-20 16:15:43 +11:00
robert-hh 2cd3a7b45c nrf/nrfx_config: Use the UARTE definitions and drivers for the NRF52xx.
Suggested by @ricksorensen after testing.  These match better the hardware
of the NRF52xx.
2023-03-20 16:12:16 +11:00
robert-hh 7ea192af05 nrf/modules/machine/uart: Add timeout keyword options and "any" method.
Changes in this commit:
- Add the timeout and timeout_char keyword options.
- Make uart.read() non-blocking.
- Add uart.any().
- Add ioctl MP_STREAM_POLL handling.
- Change uart.write() into non-busy waiting. uart.write() still waits until
  all data has been sent, but calls MICROPY_EVENT_POLL_HOOK while waiting.
  uart.write() uses DMA for transfer.  One option would be to add a small
  local buffer, such that transfers up to the size of the buffer could be
  done without waiting.
- As a side effect to the change of uart.write(), uart.txdone() and ioctl
  flush now report/wait correctly for the end of transmission.
- Change machine_hard_uart_buf_t in machine_hard_uart_obj_t to an instance
  of that struct, rather than a pointer to one.
2023-03-20 16:08:35 +11:00
Damien George 42511b5291 stm32/boards/NUCLEO_H743ZI2: Fix MCU tag in board.json file.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-20 15:24:45 +11:00
iabdalkader a197823eb7 ports: Fix MCU tags in Arduino board.json files. 2023-03-20 15:22:24 +11:00
robert-hh 05bb26010e samd: Always provide the machine.RTC class.
Even if boards do not have a clock crystal.  In that case, the clock
quality will be very poor.

Always having machine.RTC means that the date/time can be set in a way that
is consistent with other ports.

This commit also removes the special code in modutime.c for devices without
the RTC class.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-13 12:44:34 +11:00
pmendham d5c45a80d2 embed: Fix arguments to mp_raw_code_load_mem.
Update arguments to mp_raw_code_load_mem so that the embed port can build
when MICROPY_PERSISTENT_CODE_LOAD is enabled.
2023-03-13 12:35:12 +11:00
IhorNehrutsa 416707eefe esp32/machine_pin: Use const for size of machine_pin_irq_handler array. 2023-03-13 12:14:09 +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
Damien George b3c8ab37ec py/gc: Make gc_dump_info/gc_dump_alloc_table take a printer as argument.
So that callers can redirect the output if needed.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-10 10:58:10 +11:00
Damien George f450e94ba0 ports: Rename remaining "Micro Python" to "MicroPython".
Signed-off-by: Damien George <damien@micropython.org>
2023-03-10 10:54:00 +11:00
robert-hh ed1f42cb49 nrf/modules/machine/pwm: Support using all 4 channels of a PWM module.
These have the same frequency, but can have different duty cycle and
polarity.

pwm.deinit() stops all channels of a module, but does not release the
module.  pwm.init() without arguments restarts all outputs.
2023-03-10 10:44:02 +11:00
robert-hh e3b877826c nrf/modules/machine/soft_pwm: Add PWM for nrf51x boards using soft PWM.
Using extmod/machine_pwm.c for the Python bindings and the existing
softpwm.c driver, by just adding the interface.

Properties:
- Frequency range 1-3906 Hz.
- All PWM outputs run at the same frequency but can have different duty
  cycles.
- Limited to the P0.x pins.

Since it uses the existing softpwm.c mechanism, it will be affected by
playing music with the music class.
2023-03-10 10:44:02 +11:00
robert-hh a1f838cdf1 nrf/modules/machine/pwm: Use extmod/machine_pwm.c for PWM module.
This is a breaking change, making the hardware PWM on the nrf port
compatible with the other ports providing machine.PWM.

Frequency range 4Hz - ~5.4 MHz.  The base clock range is 125kHz to 16 MHz,
and the divider range is 3 - 32767.

The hardware supports up to four outputs per PWM device with different duty
cycles, but only one output is (and was) supported.
2023-03-10 10:43:55 +11:00
robert-hh cf43df4caa nrf/modules/machine/pwm: Add paramter checks and error messages. 2023-03-10 10:30:16 +11:00
Damien George b336b6bb74 stm32/pybthread: Make pyb_thread_dump take a printer as its argument.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 13:20:59 +11:00
Damien George 067c7cd9dc stm32/pin: Make pin_find debug output use mp_printf.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 13:20:59 +11:00
Damien George f43c4dfc68 stm32/extint: Make ExtInt.regs print using mp_printf.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 13:20:59 +11:00
Damien George f6a35f76af stm32/modmachine: Make machine.info print using mp_printf.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 13:20:59 +11:00
Damien George 6c8b19c7e2 stm32/spi: Return error code and raise exception if SPI init fails.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +11:00
Damien George 98937dcfc2 stm32/i2c: Return error code and raise exception if I2C init fails.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +11:00
Damien George b981e37ccd stm32/main: Use mp_printf instead of printf for MPY start-up messages.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +11:00
Damien George b9dad0add2 stm32: Remove commented-out printf's and debugging code.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +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 8307046406 stm32/boards: Include "senml" in manifest for ARDUINO boards. 2023-03-09 10:37:06 +11:00
Damien George a234aa44f3 stm32/powerctrl: Don't compile WB helpers on WL MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-08 23:57:53 +11:00
Damien George 8b3f1d47a6 stm32/powerctrlboot: Provide custom SystemInit for WB55.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Damien George <damien@micropython.org>
2023-03-08 14:04:14 +11:00
Andrew Leech c551723914 stm32/powerctrl: Disable WB55 BLE before entering deepsleep.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-03-08 14:03:36 +11:00
Andrew Leech 2eca86e8fa stm32/powerctrl: Add sleep RCC semaphore management for WB55 MCUs.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-03-08 11:33:00 +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 e764bf0138 stm32/cyw43_configport: Add cyw43_sdio_enable_high_speed_4bit function.
Needed by the latest version of cyw43-driver.
2023-03-08 00:59:36 +11:00
iabdalkader 40a49f5a7a stm32/boards/ARDUINO_GIGA: Add support for Arduino Giga H7 board. 2023-03-08 00:55:51 +11:00
iabdalkader b6904cba76 stm32/boards/ARDUINO_NICLA_VISION: Add support for Arduino Nicla Vision. 2023-03-08 00:55:38 +11:00
iabdalkader 449be91e1a stm32/Makefile: Include HAL HSEM driver on H747 MCUs. 2023-03-08 00:55:01 +11:00
iabdalkader cc645b65a9 nrf/boards/arduino_nano_33_ble_sense: Add support for REV-2 chipset.
These changes allow the firmware to support both the REV-1 and REV-2
versions of the board:
- Freeze the new device drivers used in REV-2.
- Add a board-level module that abstracts the IMU chipset.
2023-03-08 00:53:25 +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 d18de7ec81 stm32/boards/ARDUINO_PORTENTA_H7: Update board config files.
Changes are:
- Freeze micropython-lib time module to get strftime.
- Reserve the last 1MB of QSPI flash for (optional) WiFi firmware storage.
- Disable SD card mount on boot.
- Enable high-speed BLE firmware download.
2023-03-08 00:51:33 +11:00
iabdalkader fb94ae48e9 samd/pendsv: Add MICROPY_BOARD_PENDSV_ENTRIES for board customisation. 2023-03-07 15:59:58 +11:00
iabdalkader ddf39793f3 rp2/pendsv: Add MICROPY_BOARD_PENDSV_ENTRIES for board customisation. 2023-03-07 15:59:37 +11:00
iabdalkader 9171cb91b1 mimxrt/pendsv: Add MICROPY_BOARD_PENDSV_ENTRIES for board customisation. 2023-03-07 15:57:58 +11:00
iabdalkader 4d3897f80e mimxrt: Enable ROM text compression.
To reduce size of firmware, by about 3k.
2023-03-07 15:09:07 +11:00
iabdalkader 0f92954eee stm32/cyw43_configport: Allow boards to override default resource files. 2023-03-02 22:44:29 +11:00
iabdalkader e98d7ec804 stm32/boards/PYBD_SF2: Set CYW43 Bluetooth fimrware download baudrate. 2023-03-02 22:30:31 +11:00
iabdalkader 4937174b43 stm32/cyw43_configport: Fix build for boards without an RF switch.
Check if an RF switch is enabled before defining the RF switch pin.
2023-03-01 10:05:04 +11:00
Jim Mussared 7d40317a4a stm32: Add a default implementation of pyb.country.
This is for boards without networking support so that the default boot.py
continues to work.

Also update boot.py to use network.country and network.hostname instead.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:28:12 +11:00
Damien George 593375aa5d stm32/boards: Update linker scripts now that big_const is gone.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-01 01:27:51 +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 6207b605ce esp8266: Use extmod/modnetwork.c instead of port-specific version.
Rather than duplicating the implementation of `network`, this allows
ESP8266 to use the shared one in extmod.  In particular this gains access
to network.hostname and network.country.

Other than adding these two methods, there is no other user-visible change.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:27:06 +11:00
Jim Mussared eb51ca4a11 esp32: Use extmod/modnetwork.c instead of port-specific version.
Rather than duplicating the implementation of `network`, this allows ESP32
to use the shared one in extmod.  In particular this gains access to
network.hostname and network.country.

Set default hostnames for various ESP32 boards.

Other than adding these two methods and the change to the default hostname,
there is no other user-visible change.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:26:54 +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 8d9a7fd228 stm32/Makefile: Clean up nested if-else to chained if-else-if.
Makefile's support "else ifdef", so use it to make the logic clearer.

Also dedent some associated lines for consistency.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-23 10:14:04 +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
Jim Mussared 742037ec38 esp32/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:49:54 +11:00
Jim Mussared 69b93527d5 ports: Make BOARD default from BOARD_DIR in Makefile's.
This allows:

    $ make BOARD_DIR=path/to/board

to infer BOARD=board, rather than the previous behavior that required
additionally setting BOARD explicitly.

Also makes the same change for VARIANT_DIR -> VARIANT on Unix.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2023-02-23 09:47:08 +11:00
robert-hh b110266897 samd/moduos: Add uos.urandom() using the phase-jitter rng.
This RNG passes many of the Diehard tests and also the AIS31 test suite.
The RNG is quite slow, delivering 200bytes/s.

Tested on boards with and without a crystal.
2023-02-21 23:17:44 +11:00
robert-hh 4160ec087b samd/mcu: Set the SAMD21 us-counter to 2 MHz for better resolution.
It turned out that the result of calling ticks_us() was always either odd
or even, depending on some internal state during boot.  So the us-counter
was set to a 2 MHz input and the result shifted by 1.  The counting period
is still long enough, since internally a (now) 63 bit value is used for us.
2023-02-21 23:17:12 +11:00
robert-hh 76cf98c35b samd/mcu: Implement a hardware seed for the SAMD21 random module.
By using the phase jitter between the DFLL48M clock and the FDPLL96M clock.
Even if both use the same reference source, they have a different jitter.
SysTick is driven by FDPLL96M, the us counter by DFLL48M.  As a random
source, the us counter is read out on every SysTick and the value is used
to accumulate a simple multiply, add and xor register.  According to tests
it creates about 30 bit random bit-flips per second.  That mechanism will
pass quite a few RNG tests, has a suitable frequency distribution and
serves better than just the time after boot to seed the PRNG.
2023-02-21 23:15:29 +11:00
robert-hh 7e0b1bc95d samd/mcu: Use the FDPLL96M clock for the SAMD21 CPU.
Allowing to increase the clock a little bit to 54Mhz.  Not much of a gain,
but useful for generating a RNG entropy source from the jitter between
DFLL48M and FDPLL96M.
2023-02-21 23:15:00 +11:00
robert-hh 60ab556385 samd/mcu: Rework the comments in clock_config.c.
For more clarity. clock_config.c is not overly readable, so comments are
important.
2023-02-21 23:14:45 +11:00
robert-hh c3afafd1ec samd/boards: Clean up comments and some pins in pins.csv files.
Remove two SPARKFUN_SAMD51_THINGS_PLUS pin definitions.  There were
definitions of TXD and RXD, but these pins do not exist on the board.  They
were only shown in the schematics.

Also remove any reference to LED_.  This is just a text change, no
functional change.
2023-02-21 23:13:01 +11:00
manobendro 294098d28e minimal: Increase heap size for Linux builds.
Otherwise use of the REPL is quite limited.

Fixes issue #10644.
2023-02-20 10:44:14 +11:00
robert-hh 4598b89ce9 samd: Add Pin.board and Pin.cpu classes to Pin.
For compatibility with other ports.  Code increase up to ~1250 bytes for
SAMD21.  The feature is configurable via MICROPY_PY_MACHINE_PIN_BOARD_CPU
in case flash memory is tight.
2023-02-17 17:27:21 +11:00
robert-hh 7198c25175 mimxrt/Makefile: Move the FROZEN_MANIFEST setting after board config.
Such that a respective statement in mpconfigboard.mk is executed first.
2023-02-17 14:29:04 +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
robert-hh de1f1dd164 shared/runtime/softtimer: Use consistently the same clock source.
Before, both uwTick and mp_hal_ticks_ms() were used as clock source.  That
assumes, that these two are synchronous and start with the same value,
which may be not the case for all ports.  If the lag between uwTick and
mp_hal_ticks_ms() is larger than the timer interval, the timer would either
rush up until the times are synchronous, or not start until uwTick wraps
over.

As suggested by @dpgeorge, MICROPY_SOFT_TIMER_TICKS_MS is now used in
softtimer.c, which has to be defined in a port's mpconfigport.h with
the variable that holds the SysTick counter.

Note that it's not possible to switch everything in softtimer.c to use
mp_hal_ticks_ms() because the logic in SysTick_Handler that schedules
soft_timer_handler() uses (eg on mimxrt) the uwTick variable directly
(named systick_ms there), and mp_hal_ticks_ms() uses a different source
timer.  Thus it is made fully configurable.
2023-02-16 12:59:48 +11:00
iabdalkader 68d049ea5e nrf/Makefile: Add support for BOSSAC flasher.
Used by Arduino boards.
2023-02-16 12:46:23 +11:00
Jim Mussared 4eb72b34df stm32/boards/ARDUINO_PORTENTA_H7: 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
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
iabdalkader e140c7d26a stm32/boards/ARDUINO_PORTENTA_H7: Fix macro value check for QSPI.
QSPI deepsleep should be enabled only when the internal flash storage is
not used.
2023-02-16 12:21:48 +11:00
Andrew Leech 75e7e7d034 stm32/boards/STM32F769DISC: Fix building with USE_QSPI_XIP=1.
Signed-off-by: Damien George <damien@micropython.org>
2023-02-16 12:04:29 +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 8b27482692 top: Update Python formatting to black "2023 stable style".
See https://black.readthedocs.io/en/stable/the_black_code_style/index.html

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-02 12:51:03 +11:00
Damien George fe2a8332ff stm32/boards/NUCLEO_H743ZI2: Refer to NUCLEO_H743ZI for frozen manifest.
Fixes build issue introduced by 6250337c9c

Signed-off-by: Damien George <damien@micropython.org>
2023-02-01 23:22:18 +11:00
stijn 6abf03b5d0 windows/msvc: Fix module freezing.
Make this more generally useful and in line with what the mingw
and unix ports do: 16bit dig size to work on 32bit ports, a
self-contained qstrdefs.preprocessed.h because makemanifest.py
uses that, and a dev variant which effectively puts this to use:
previously the uasyncio module wasn't frozen but instead tests
ran by importing it from the extmod/ directory.
2023-02-01 13:10:00 +11:00
stijn e145318a81 windows/msvc: Fix qstr generation dependency.
The mpversion.h file must exist before py/ source can be preprocessed,
but this went unnoticed because micropython.vcxproj always calls
MakeVersionHdr before MakeQstrDefs.
2023-02-01 13:10:00 +11:00
stijn 65941ea0e5 windows/msvc: Make mpy-cross independent of micropython variant.
The variant.props may have incompatible build options which break
the mpy-cross build and in any case mpy-cross has nothing to do
with variant support.
2023-02-01 13:10:00 +11:00
stijn 55a76f4edd windows/msvc: Remove variant suffix from executable filename.
This is in line with the change made for other ports in d53c3b6a: since
the default output directory already includes the variant name in it
there's no need to add it to the executable as well.
2023-02-01 13:10:00 +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
robert-hh c2ab1b5185 esp32/boards/OLIMEX_ESP32_POE: Remove id from and update board.json. 2023-01-28 15:29:01 +11:00
robert-hh 0baf6c80d9 nrf/mpconfigport: Enable seeding of the PRNG by the hardware RNG.
A suitable function already existed, so just the declaration was needed.
2023-01-28 15:23:26 +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
Damien George a8a1ad1391 embed: Add new "embed" port which builds a simple C package.
Signed-off-by: Damien George <damien@micropython.org>
2023-01-20 22:28:50 +11:00
小权一句两句 94ee1b629a unix/main: Free pathbuf when there's an error opening a file. 2023-01-20 19:38:14 +11:00
robert-hh d6bc34a13a esp32: Add a small delay before leaving wlan.active().
The delay is 1 ms. It avoids the crashes reported by the
issues #8289, #8792 and #9236 with esp-idf versions >= 4.2, but does
not solve an underlying problem in the esp-idf.
2023-01-19 21:31:46 +01:00
ma-lalonde 30db33d1e0 esp32/network_lan: Add support for Ethernet PHY KSZ8081.
This is available since ESP-IDF v4.4.

Signed-off-by: Damien George <damien@micropython.org>
2023-01-19 22:50:41 +11:00
Clayton Cronk 54e85fe212 esp32/boards/GENERIC_UNICORE: Add board definition for unicore chips.
Tested to work on an ESP32-MINI-1, which is a single core ESP32-U4DWH.

Signed-off-by: Clayton Cronk <awesomecronk@gmail.com>
2023-01-19 22:38:02 +11:00
robert-hh 32a858e254 esp32/boards: Add board definition for Olimex ESP32 PoE boards.
The major setting is about the PHY interface configuration.  The
configuration matches the Olimex ESP32 Gateway as well.

Tested with esp-idf v4.2.4 and Olimex ESP32 POE boards.
2023-01-19 20:24:06 +11:00
iabdalkader 3b5cafc716 stm32/Makefile: Leave DFU mode after download when using dfu-util.
Not all DFU bootloaders exit after download, this modifier is required for
some boards to reset, otherwise they sit idle in DFU mode.
2023-01-19 16:23:22 +11:00
Juan Francisco Cantero Hurtado 720f2cfba9 unix/Makefile: Disable building the shared library of libffi.
MicroPython doesn't need the shared library and disabling it in the
configure could ease the build of a static version of MicroPython.
2023-01-19 15:24:43 +11:00
Damien George 4eb7063608 esp8266/README: Remove notice about port being "experimental".
It has been around for a long time and the API is mature enough.

Signed-off-by: Damien George <damien@micropython.org>
2023-01-19 14:59:18 +11:00
Antonello Margottini e30e543a75 esp8266/modnetwork: Add ability to set tx power for WLAN interface. 2023-01-19 13:39:05 +11:00
Maripo GODA fb0dd86b39 esp32/machine_sdcard: Change dma_channel to SPI_DMA_CH_AUTO for ESP32S3.
Specifying DMA channel 2 causes an "invalid dma channel" error.  In
ESP-IDF, the only available channel for ESP32S3 is SPI_DMA_CH_AUTO=3.
2023-01-19 13:13:42 +11:00
Damien George 67097d8c2b esp32/network_lan: Fix compilation on IDF lower than v4.4.
Signed-off-by: Damien George <damien@micropython.org>
2023-01-18 13:47:10 +11:00
Damien Tournoud c7301b8d03 esp32/network_lan: Fix setting MAC address of ethernet devices.
`esp_eth_ioctl(ETH_CMD_S_MAC_ADDR)` sets the MAC address of the hardware
device, but we also need to notify the upper layers of the change so that
e.g. DHCP work properly.
2023-01-18 11:19:12 +11:00
Damien Tournoud e982c1d8de esp32/network_lan: Add support for SPI-based ethernet chips.
Add support for various SPI-based ethernet chips (W5500, KSZ8851SNL,
DM9051) to the ESP32 port.  This leverages the existing support in ESP-IDF
for these chips -- which configures these chips in "MAC raw" mode -- and
the existing support for network.LAN in the ESP32 port.  In particular,
this doesn't leverage the wiznet5k support that is used on the rp2 and
stm32 ports (because that's for native use of lwIP).

Tested on the POE Featherwing (with the SJIRQ solder jumper bridged) and a
ESP32-S3 feather.

A note about the interrupt pin: The W5500 implementation within ESP-IDF
relies on hardware interrupt, and requires the interrupt pin from the W5500
to be wired to a GPIO.  This is not the case by default on the Adafruit
Ethernet FeatherWing, which makes it not directly compatible with this
implementation.
2023-01-18 11:16:09 +11:00
robert-hh 4b52003fb8 esp32/network_lan: Support configuration of ETH ref_clk pin.
Both the direction and the Pin used for ref_clk can now be configured.  It
Requires at least idf v4.4.  The new keyword arguments to the constructor
are:

- ref_clk_mode=mode: with mode being Pin.IN or Pin.OUT.  If it is not set,
  then the default configuration is used, which may be configured by
  kconfig settings.

- ref_clk=pin_obj: which defines the Pin used for ref_clk.  This is either
  Pin(0), Pin(16) or Pin(17).  No check is done for the pin number.  If it
  is the wrong one, it simply will not work.  Besides that, no harm.
2023-01-18 10:05:13 +11:00
robert-hh efb4bd3555 esp32/network_lan: Add support for LAN8710 PHY.
LAN8710 uses the same drivers as LAN8720, so this commit just adds the
names.  Alternatively, both could be summarised under LAN87xx, like the
esp-idf does.
2023-01-18 10:04:31 +11:00
robert-hh 1583c1f670 mimxrt: Set MICROPY_GC_STACK_ENTRY_TYPE to uint32_t for large RAM.
It was uint16_t. The change sets it to uint32_t for devices with SDRAM.

Fixes issue #10366.
2023-01-16 12:26:39 +11: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
Andrew Leech fa57ee971b stm32/boards: Consolidate linker snippets to reduce duplication.
This commit uses the REGION_ALIAS GNU linker command to simplify the linker
snippets and consolidate the duplication.

Signed-off-by: Damien George <damien@micropython.org>
2023-01-13 15:14:26 +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
Red_M 1290329415 esp32/boards/GENERIC_S3_SPIRAM_OCT: Add ESP32S3 board with Octal SPIRAM. 2022-12-19 13:29:33 +11:00
Damien George bb77c1d5a3 stm32/powerctrl: Fix build on STM32G0xx and STM32H7Bx MCUs.
STM32G0xx doesn't have DBGMCU, and STM32H7Bx doesn't have EXTI_D2.

Signed-off-by: Damien George <damien@micropython.org>
2022-12-16 16:48:59 +11:00
robert-hh 988b6e2dae renesas-ra: Add the UART methods uart.txdone() and uart.flush().
This required to add two functions down the stack to uart.c and ra.sci.c.

- One for telling, whther the transmission is busy.
- One for reporting the size of the TX buffer.

Tested with a EK-RA6M2 board.
2022-12-15 12:09:34 +01:00
Jim Mussared 68090cc6cd cc3200: Remove unused NIC type customisation.
See the previous commit, except in this case the customisation didn't
actually do anything so can just be removed.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-12-15 17:40:18 +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
brave ulysses 7f71057a89 stm32/boards/NUCLEO_F756ZG: Add board definition for NUCLEO-F756ZG.
Signed-off-by: Damien George <damien@micropython.org>
2022-12-15 14:59:26 +11:00
iabdalkader 5b7f71882b stm32/powerctrl: Improve standby mode entry code for H7 MCUs.
Changes in this commit:
- Clear and mask D2 EXTIs.
- Set correct voltage scaling level for standby mode.
- Disable debug MCU (if debugging is disabled), for all MCU series.
2022-12-15 14:39:28 +11:00
robert-hh 564945a2a0 nrf/boards/seeed_xiao_nrf52: Add defn for Seeed XIAO NRF52840 Sense.
It keeps compatibility with the XIAO bootloader by:
- using Soft Device 7.3.0
- reserving 48k memory for the bootloader.

So on double reset a drive pops for uploading an uf2 image or a nrfutil zip
pkg file.  Instructions to create it from a hex file are included.  The
bootloader can as well be activated with the touch 1200 option of nrfutil.

The script download_ble_stack.sh has been adapted to get the version 7.3.0
soft device files.  It may have to be executed once before building.

The file system is set to 256k and the pin definitions are adapted.
Besides that, it has the common functionality and omissions.  The on-board
sensors and additional flash can be supported by Python scripts.
2022-12-15 14:27:08 +11:00
Jim Mussared 6d460d33dc samd/boards/SEEED_XIAO: Rename to SEEED_XIAO_SAMD21.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-12-15 14:18:44 +11:00
Damien Tournoud fd1e66edb3 esp32/usb: Cleanup connection detection.
This was introduced by 35fb90bd57, but
it is much simpler and essentially the same to just use
`tud_cdc_n_connected()`.

The only difference is that tud_cdc_n_connected() only checks for DTR,
but this is correct anyway: DTR indicates device presence, RTS indicates
that the host wants to receive data.

Signed-off-by: Damien Tournoud <damien@platform.sh>
2022-12-13 20:46:32 -08:00
Jim Mussared 9bec52a2f8 esp32/main: Don't call usocket_events_deinit if unavailable.
usocket_events_deinit will only be available if MICROPY_PY_USOCKET_EVENTS
is enabled (which is only enabled when webrepl is enabled).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-12-14 13:51:20 +11:00
Wind-stormger 3a3739037d esp32/machine_touchpad: Fix TouchPad for ESP32S2, ESP32S3. 2022-12-14 13:46:41 +11:00
David Lechner 958f748e53 unix/moduos: Implement 2-arg version of os.getenv().
This adds the `default` argument of `os.getenv(key, default=None)`.

Signed-off-by: David Lechner <david@pybricks.com>
2022-12-14 13:38:39 +11:00
robert-hh b75b5c102c mimxrt/sdcard: Remove obsolete code already excluded by preprocessor. 2022-12-14 13:05:27 +11:00
robert-hh aea4174937 mimxrt/sdcard: Fix an error when writing large blocks.
Which happened when a read followed a large write.
2022-12-14 13:04:58 +11:00
robert-hh 913f9ad5ad mimxrt/machine_rtc: Set the microsecond value to 0.
Set the subsecond value reported by rtc.datetime() and rtc.now() to 0.
Synchronizing the roll-over with the second change was not precise.
2022-12-14 13:04:09 +11:00
robert-hh 17ab2f671b samd: Support entering bootloader via USB CDC 1200bps touch. 2022-12-14 12:50:04 +11:00
robert-hh e69313f89c samd: Add a vref=num option to the ADC and DAC constructor.
ADC: The argument of vref=num is an integer. Values for num are:

    SAMD21:
    0  INT1V   1.0V voltage reference
    1  INTVCC0 1/1.48 Analog voltage supply
    2  INTVCC1 1/2 Analog voltage supply (only for VDDANA > 2.0V)
    3  VREFA   External reference
    4  VREFB   External reference

    SAMD51:
    0  INTREF  internal bandgap reference
    1  INTVCC1 Analog voltage supply
    2  INTVCC0 1/2 Analog voltage supply (only for VDDANA > 2.0v)
    3  AREFA   External reference A
    4  AREFB   External reference B
    5  AREFC   External reference C (ADC1 only)

DAC: The argument of vref=num is an integer. Suitable values:

    SAMD21:
    0  INT1V   Internal voltage reference
    1  VDDANA  Analog voltage supply
    2  VREFA   External reference

    SAMD51:
    0  INTREF Internal bandgap reference
    1  VDDANA Analog voltage supply
    2  VREFAU Unbuffered external voltage reference (not buffered in DAC)
    4  VREFAB Buffered external voltage reference (buffered in DAC).
2022-12-14 12:48:24 +11:00
robert-hh a73dcb3d22 samd/machine_uart: Fix uart.deinit() and save some RAM.
Changes in this commit:
- Do not deinit IRQ when uart.deinit() is called with an inactive object.
- Remove using it for the finaliser.  There is another machanism for soft
  reset, and it is not needed otherwise.
- Do not tag the UART buffers with MP_STATE_PORT, it is not required.
2022-12-14 12:46:20 +11:00
robert-hh f78dd25a2c samd/machine_uart: Check the UART TX pin assignment.
Check, if TX is at Pad 0 (SAMD51), or Pad 0 or 2 (SAMD21).
2022-12-14 12:45:51 +11:00
robert-hh 5b1fd8802a samd/machine_uart: Simplify machine_uart_any() and machine_uart_read().
Remove the call to uart_drain_rx_fifo().  It is not required, and may cause
a race condition.
2022-12-14 12:43:34 +11:00
robert-hh 4199f986ad samd/machine_uart: Fix IRQ flag setting and clearing.
Clearing the DRE flag for the transmit interrupt at the end of a
uart.write() also cleared the RXC flag disabling the receive interrupt.

This commit also changes the flag set/clear mechanism in the driver for SPI
as well, even if it did not cause a problem there.  But at least it saves a
few bytes of code.
2022-12-14 12:42:34 +11:00
robert-hh fcd1788937 samd: Avoid under-/overflow in I2C and SPI baudrate calculations.
Applies to both SPI and I2C.  The underflow caused high baudrate settings
resulting in the lowest possible baudrate.  The overflow resulted in
erratic baudrates, not just the lowest possible.
2022-12-14 12:41:42 +11:00
robert-hh 43fc133dbd samd/mpconfigport: Use __WFE() in MICROPY_EVENT_POLL_HOOK.
Like WFI, WFE also responds to a hardware interrupt, and using WFE speeds
up at least spi.read().  Power consumption at an idle REPL is unchanged.
2022-12-14 12:40:22 +11:00
robert-hh 3cc359c204 samd/mpconfigport: Support MICROPY_HW_SOFTSPI_MIN_DELAY.
Bringing the SoftSPI baudrate up to about 500 kHz.
2022-12-14 12:39:54 +11:00
Dale Weber f2de289ef3 stm32/boards/NUCLEO_F429ZI: Enable I2C1 and I2C2 with default pins.
The datasheet on page 55 shows PF0 (SDA) and PF1 (SCL) are the pins for
I2C2, but these pins do not work.  Checking the MBED pinout for the
NUCLEO-F429ZI shows:

    I2C1: PB8 (SCL) and PB9 (SDA).
    I2C2: PB10 (SCL) and PB11 (SDA).

Both of these work and can be scanned and find devices connected to them.

Signed-off-by: Dale Weber <hybotics.sd@gmail.com>.
2022-12-13 17:35:55 +11:00
stijn f6f177807f windows/.gitignore: Simplify by removing build artefacts.
Since all output is now in the build-<variant>/ directory, which is already
excluded by the root .gitignore, we don't need to repeat that.
2022-12-13 17:22:11 +11:00
stijn 9c7ff87643 all: Keep msvc build output in build/ directories.
This follow the change made for Makefile-based projects in b2e82402.
2022-12-13 17:18:53 +11:00
Antonin ENFRUN db19ee7e15 webassembly/library: Extract and send data to print as UInt8Array.
This allows utf-8 data to work.  It's the receiving layer's responsibility
to deal with decoding the data.
2022-12-13 17:16:37 +11:00
Damien George b042fd5120 drivers/bus: Change QSPI read_cmd signature to return an error code.
Signed-off-by: Damien George <damien@micropython.org>
2022-12-09 13:25:18 +11:00
Andrew Leech 7ee5afe8d1 drivers/bus: Detect QSPI transfer errors and pass up to spiflash driver.
This changes the signatures of QSPI write_cmd_data, write_cmd_addr_data and
read_cmd_qaddr_qdata so they return an error code.  The softqspi and stm32
hardware qspi driver are updated to follow this new signature.  Also the
spiflash driver is updated to use these new return values.

Signed-off-by: Damien George <damien@micropython.org>
2022-12-09 13:25:18 +11:00
Jeff Epler d75ff42297 unix/coverage: Add extra GC coverage test for ATB gap byte.
The assertion that is added here (to gc.c) fails when running this new test
if ALLOC_TABLE_GAP_BYTE is set to 0.

Signed-off-by: Jeff Epler <jepler@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-12-08 14:35:08 +11:00
iabdalkader fb7d211530 stm32/boards: Add missing LPUART macros for H7 HAL.
The STM32H7xx HAL LPUART AF macros are missing the number, this HAL is the
only one that's inconsistent in the way it defines LPUART AF macros, so we
only need to define them for H7.
2022-12-01 15:35:07 +11:00