Wykres commitów

768 Commity (master)

Autor SHA1 Wiadomość Data
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 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 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
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
David (Pololu) bf3eb9dc39 rp2/machine_i2c: Add timeout parameter for machine.I2C().
This commit adds support for the `timeout` keyword argument to machine.I2C
on the rp2 port, following how it's done on other ports.

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

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

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

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

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

Signed-off-by: David Grayson <davidegrayson@gmail.com>
2023-04-05 10:38:50 +10:00
Damien George 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
IhorNehrutsa 416707eefe esp32/machine_pin: Use const for size of machine_pin_irq_handler array. 2023-03-13 12:14:09 +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
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 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 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
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
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 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
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
Red_M 1290329415 esp32/boards/GENERIC_S3_SPIRAM_OCT: Add ESP32S3 board with Octal SPIRAM. 2022-12-19 13:29:33 +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
Brian Cooke 7fe7c55bb8 esp32/machine_timer: Fix ESP32C3 timer period doubling.
The original ESP32 only supports timer source clock APB so it doesn't need
and doesn't have a clk_src field.

The ESP32C3 supports timer source clock APB and XTAL so it does have a
clk_src field, and this needs to be configured to get the correct period.

Fixes #8084.
2022-11-23 11:57:39 +11:00
Jim Mussared b705732d5f esp32/boards/GENERIC_S3_SPIRAM: Enable BLE.
Follow up to 8a91c719 to no longer explicitly disable BLE in
mpconfigport.h.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-23 09:42:54 +11:00
David Lechner 4dcfd19bbf extmod/extmod.cmake: Add MICROPY_PY_BTREE compiler definition.
Instead of defining `MICROPY_PY_BTREE` in `mpconfigport.h` we can define
it via CMake similar to how other ports that use Makefiles define it in
`mpconfigport.mk`.

Signed-off-by: David Lechner <david@pybricks.com>
2022-11-17 23:20:58 +11:00
PGE 8a91c71966 esp32/boards/GENERIC_S3_SPIRAM: Enable BLE support. 2022-11-15 23:40:42 +11:00
robert-hh eefd946e60 esp32/modmachine: Move dht_readinto() to the machine module. 2022-11-09 15:58:39 +11:00
robert-hh d68e3b03b1 esp32/usb: Add a timeout to usb_tx_strn().
If USB CDC is connected and the board sends data, but the host does not
receive the data, the device locks up.  This is fixed in this commit by
having a timeout of 500ms, after which time the transmission is skipped.
2022-11-09 11:16:55 +11:00
Patrick d0687e90ab esp32: Add 32MiB partition table templates.
Signed-off-by: Patrick <patrick@joytech.com.au>
2022-11-09 10:57:44 +11:00
robert-hh 7775523b2d esp32/machine_pwm: Verify PWM is active when config methods are called.
Checks are added for pwm.freq(), pwm_duty(), pwm_duty_u10() and
pwm.duty_u16().  This avoids a core dump on ESP32C3, and misleading error
messages on Xtensa ESP32 devices.
2022-10-31 11:54:46 +11:00
Ihor Nehrutsa 5b2929a0e6 esp32/machine_pin: Fix size of machine_pin_irq_handler array.
Set the size of machine_pin_irq_handler array to GPIO_NUM_MAX:
- Min GPIO_NUM_MAX is 22 for IDF_TARGET_ESP32C3.
- Max GPIO_NUM_MAX is 49 for IDF_TARGET_ESP32S3.

The MP_REGISTER_ROOT_POINTER entry must be hard-coded, because the location
that it's evaluated by the compiler does not include the relevant IDF
header to get a definition of GPIO_NUM_MAX.
2022-10-31 11:42:20 +11:00
Mark Grosen 12f9948151 esp32/machine_i2c: Fix clocks and timeouts for ESP32-C3, ESP32-S3.
Each SoC family has its own clocks and timings/timeouts. For I2C, the
default source clock is either APB (ESP32, ESP32-S2) or XTAL (ESP32-S3,
ESP32-C3) as shown in the datasheets.  Since
machine_i2c.c/machine_hw_i2c_init() uses the default clk_flags (0), the
alternate low-power clock source is never selected in ESP-IDF
i2c.c/i2c_param_config().  There is not an API in i2c.c to get the source
clock frequency, so a compile-time value is used based on SoC family.

Also, the maximum timeout is different across the SoC families, so use the
I2C_LL_MAX_TIMEOUT constant to eliminate the warning from
i2c_set_timeout().

With these changes, the following results were obtained.  The I2C SCL
frequencies were measured with a Saleae logic analyzer.

ESP32 (TTGO T Dislay)
    I2C(0, scl=22, sda=21, freq=101781)  Measured: 100KHz
    I2C(0, scl=22, sda=21, freq=430107)  Measured: 400KHz
    I2C(0, scl=22, sda=21, freq=1212121) Measured: 941KHz

ESP32-S3 (TTGO T-QT)
    I2C(0, scl=34, sda=33, freq=111111)  Measured: 107KHz
    I2C(0, scl=34, sda=33, freq=444444)  Measured: 400KHz
    I2C(0, scl=34, sda=33, freq=1111111) Measured: 842KHz

ESP32-C3 (XIAO ESP32C3)
    I2C(0, scl=7, sda=6, freq=107816)  Measured: 103KHz
    I2C(0, scl=7, sda=6, freq=444444)  Measured: 380KHz
    I2C(0, scl=7, sda=6, freq=1176470) Measured: 800KHz

(ESP32-S2 board was not available for testing.)
2022-10-28 19:06:41 +11:00
iabdalkader 427670c210 esp32: Rename machine I2C and SPI types consistently across ports.
This renames:
- machine_hw_i2c_type -> machine_i2c_type
- machine_hw_spi_type -> machine_spi_type
2022-10-22 12:56:10 +11:00
Damien George 95c614e2b6 esp32/machine_hw_spi: Use auto DMA channel on S2, S3, C3 chips.
Auto DMA channel is supported in IDF v4.4, and is required to be used on S3
chips, so use this simpler configuration option where possible.

Fixes issue #8634.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-04 17:43:48 +11:00
Damien George 0ee877a207 esp32/machine_i2s: Add I2S finaliser which calls deinit().
So that the FreeRTOS resources can be freed, eg on soft reset.

Fixes issue #9366.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-04 11:47:06 +11:00
Jim Mussared 924a3e03ec top: Replace upip with mip everywhere.
Updates all README.md and docs, and manifests to `require("mip")`.

Also extend and improve the documentation on freezing and packaging.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-30 17:34:03 +10:00
Damien George dd9dcb594c esp32/machine_pwm: Don't use LEDC_USE_REF_TICK on ESP32-C3 variants.
Because it's not supported by this particular MCU (since IDF v4.4.2).

Signed-off-by: Damien George <damien@micropython.org>
2022-09-26 00:11:42 +10:00
Damien George 3abcfb9aec esp32/modsocket: Use mp_obj_is_integer to test port type.
Because the value may be a big integer, which is still a valid type to use.

Fixes issue #9410.

Signed-off-by: Damien George <damien@micropython.org>
2022-09-26 00:07:58 +10:00
Jim Mussared 94beeabd2e py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other
methods.

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

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

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

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

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

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

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 18d0e6d0db esp32/Makefile: Add link to build troubleshooting on failure.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-15 12:22:18 +10:00
Damien George 0e8c2204da esp32/mphalport: Fix calculation of large sleep by using 64-bit arith.
Fixes issue #9304.

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

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-09-05 18:43:18 +10:00
robert-hh 5466f1b0ea esp32/machine_uart: Implement uart.flush() and uart.txdone().
uart.flush()

flush() will wait until all characters have been sent.To
avoid a permanent lock, a timeout applies depending on the
size of txbuf and the baud rate.

ret = uart.txdone()

ret is True if no transfer is in progress.
ret is False otherwise.
2022-08-31 00:18:14 +10:00
Damien George d108fc9c47 esp32/machine_sdcard: Free SPI bus when deiniting SD card.
So that everything is reset and the SD card can be created again after
calling SDCard.deinit() (and after a soft reset).

Fixes issue #8949.

Signed-off-by: Damien George <damien@micropython.org>
2022-08-30 12:54:18 +10:00
Damien George 730e975091 esp32/boards: Merge manifest_release modules into standard manifest.
Having two separate manifests is confusing.  It's simpler to have the daily
builds use the same configuration as the stable, release builds.

Signed-off-by: Damien George <damien@micropython.org>
2022-08-30 11:34:34 +10:00
Jim Mussared 8a0ee5a5c0 py/objstr: Split mp_obj_str_from_vstr into bytes/str versions.
Previously the desired output type was specified.  Now make the type part
of the function name.  Because this function is used in a few places this
saves code size due to smaller call-site.

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

This saves ~140 bytes on PYBV11.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-26 16:43:55 +10:00
robert-hh 8139cbcf6b esp32/machine_timer: Support all init arguments in Timer constructor.
Following the usual style of instantiation and init().
2022-08-24 17:31:39 +10:00
robert-hh 13dceaa4ea esp32/machine_uart: Change sendbreak time to be at least 15 bit times.
It used to be 10 bit times, which is too short.  The break state must be
longer than a regular character time, at least 13 bit times.  This is now
implemented by reducing the baudrate while sending the "0".  The break time
will now vary with data length and parity setting, but will at least be 15
bit times.

Tested with a GENERIC_SPIRAM, GENERIC_C3 and UM_TINYS2 board.
2022-08-23 17:22:15 +10:00
glenn20 0507f239e8 esp32/modnetwork: Add network.MODE_LR constant.
Adds the MODE_LR constant to the network module to support Espressif's
long-range communication protocol.
2022-08-23 16:33:03 +10:00
glenn20 76f2e3e62b esp32/network_wlan: Add support to set/get the wifi protocol.
Add 'protocol' option to WLAN.config() to support setting/getting the wifi
protocol modes: MODE_11G|MODE_11G|MODE_11N.
2022-08-23 16:32:30 +10:00
glenn20 98d1c50159 esp32/network_wlan: Use esp_wifi_set/get_channel to config wifi channel.
Set the channel with esp_wifi_set_channel(), which adds support for setting
the channel of the STA interface

Get the channel with esp_wifi_get_channel() which returns the actual wifi
channel of the radio, rather than the configured channel.
2022-08-23 16:28:49 +10:00
Ian Davies fbe9417b90 extmod/ntptime: Factor out ntptime module from esp8266 port.
The ntptime module was previously only included in the ESP8266 port.  This
commit factors that module out into the extmod directory, makes it support
different epochs, and includes it in the rp2 port.
2022-08-06 00:08:32 +10:00
Jim Mussared 19f5da9e1b esp32/Makefile: Force micropython-lib as a required submodule.
Also use mkrules.mk's submodule target rather than duplicating the call to
`submodule sync`.

Until we can find a way to use idf.py/cmake to discover submodules we have
no way to discover optional or board-specific submodules so need to err on
the side of including everything.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-03 00:07:35 +10:00
Jim Mussared be83c08f46 ports: Always append to GIT_SUBMODULES.
Avoids overwriting submodules required by base makefiles.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-03 00:05:26 +10:00
Jim Mussared 092784da19 ports: Remove unused mp_type_{fileio/textio} macros in mpconfigport.h.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-26 18:07:22 +10:00
Damien George 5dbb822ca4 esp32/mpconfigport: Enable BLE synchronous events and pairing/bonding.
Signed-off-by: Damien George <damien@micropython.org>
2022-07-22 17:41:21 +10:00
David Lechner b63282c361 esp32: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register all root pointers in the
esp32 port.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:34 +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 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
Damien George d7a162516e esp32/modmachine: Fix machine.freq to allow maximum 160MHz on ESP32-C3.
Fixes issue #8824.

Signed-off-by: Damien George <damien@micropython.org>
2022-07-08 22:46:51 +10:00
IhorNehrutsa 1ea82b6dcc esp32,esp8266: Rename WLAN dhcp_hostname config to hostname.
But retain old name for backwards compatibility.
2022-07-05 23:40:32 +10:00
Damien George ccaf197807 esp32/network_wlan: Don't raise exception when scan returns no results.
Prior to this commit, running scan() without any APs available would give:

    >>> wl.scan()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    RuntimeError: Wifi Unknown Error 0x0102

Signed-off-by: Damien George <damien@micropython.org>
2022-06-28 13:18:07 +10:00
Christian Walther ba21f76f89 esp32/modesp32: Add wake_on_ulp() so ULP can wake CPU from deepsleep.
Add esp32.wake_on_ulp() to give access to esp_sleep_enable_ulp_wakeup(),
which is needed to allow the ULP co-processor to wake the main CPU from
deep sleep.
2022-06-23 17:31:01 +10:00
Christian Walther cf550ad9d1 esp32/boards: Increase 512 bytes limit on ULP programs to 2040.
Allow esp32.ULP.load_binary() to use the maximum amount of memory available
again, which is 2040 bytes unless MICROPY_HW_RTC_USER_MEM_MAX is
customized.

This value regressed in 3d49b157b8
2022-06-23 17:24:59 +10:00
robert-hh 5f4539b0ca esp32/machine_uart: Implement the functionality of timeout_char arg.
Using it for the rx-timeout.  The value is given as ms, which is then
converted to character times.  A value of less than a character time will
cause the rx call to return immediately after 1 character, which may be
inefficient at high transmission rates.

Addresses #8778.
2022-06-23 17:13:41 +10:00
iabdalkader a7c7febe0b esp32/network_wlan: Rename WLAN keyword args to ssid/security/key.
The WLAN.config() method now supports "ssid", "security" and "key" as
aliases to the existing "essid", "authmode" and "password", which are now
deprecated.

Addresses issue #8083.
2022-06-17 21:43:44 +10:00
Damien George 5233fb3a3d extmod/machine_i2c: Only use WRITE1 option if transfer supports it.
When MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 is enabled the port's hardware
I2C transfer functions should support the MP_MACHINE_I2C_FLAG_WRITE1
option, but software I2C will not.  So add a flag to the I2C protocol
struct so each individual protocol can indicate whether it supports this
option or not.

Fixes issue #8765.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-17 11:57:57 +10:00
Damien George f63b4f85aa py/parse: Work around xtensa esp-2020r3 compiler bug.
This commit works around a bug in xtensa-esp32-elf-gcc version esp-2020r3.

The bug is in generation of loop constructs.  The below code is generated
by the xtensa-esp32 compiler.  The first extract is the buggy machine code
and the second extract is the corrected machine code.  The test
`basics/logic_constfolding.py` fails with the first code and succeeds with
the second.

Disassembly of section .text.push_result_rule:

00000000 <push_result_rule>:
  ...
  d6:   209770       or      a9, a7, a7
  d9:   178976       loop    a9, f4 <push_result_rule+0xf4>
                     d9: R_XTENSA_SLOT0_OP   .text.push_result_rule+0xf4
  dc:   030190       rsr.lend        a9
  df:   130090       wsr.lbeg        a9
  e2:   a8c992       addi    a9, a9, -88
  e5:   06d992       addmi   a9, a9, 0x600
  e8:   130190       wsr.lend        a9
  eb:   002000       isync
  ee:   030290       rsr.lcount      a9
  f1:   01c992       addi    a9, a9, 1
  f4:   1494e7       bne     a4, a14, 10c <push_result_rule+0x10c>
                     f4: R_XTENSA_SLOT0_OP   .text.push_result_rule+0x10c

Disassembly of section .text.push_result_rule:

00000000 <push_result_rule>:
  ...
  d6:   209770       or      a9, a7, a7
  d9:   178976       loop    a9, f4 <push_result_rule+0xf4>
                     d9: R_XTENSA_SLOT0_OP   .text.push_result_rule+0xf4
  dc:   030190       rsr.lend        a9
  df:   130090       wsr.lbeg        a9
  e2:   000091       l32r    a9, fffc00e4 <push_result_rule+0xfffc00e4>
                     e2: R_XTENSA_SLOT0_OP   .literal.push_result_rule+0x18
  e5:   0020f0       nop
  e8:   130190       wsr.lend        a9
  eb:   002000       isync
  ee:   030290       rsr.lcount      a9
  f1:   01c992       addi    a9, a9, 1
  f4:   1494e7       bne     a4, a14, 10c <push_result_rule+0x10c>
                     f4: R_XTENSA_SLOT0_OP   .text.push_result_rule+0x10c

Work done in collaboration with @jimmo.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-09 13:56:30 +10:00
Damien George 85597aa68e esp32/machine_pin: Only expose IO20 on esp32 for IDF 4.3.2 and above.
This IO was enabled in IDF commit 68f8b999bb69563f2f3d1d897bc073968f41f3bf,
which is available in IDF release v4.3.2 and above.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-08 18:29:01 +10:00
Damien George bd375df02c extmod/extmod.cmake: Require components to be explicitly enabled.
Otherwise include directories are added unconditionally to the build
variables if the component (submodule) is checked out.  This can lead to,
eg, the esp32 build using lib/lwip header files, instead of lwip header
files from the IDF.

Fixes issue #8727.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-08 13:03:34 +10:00
Damien George efe23aca71 all: Remove third argument to MP_REGISTER_MODULE.
It's no longer needed because this macro is now processed after
preprocessing the source code via cpp (in the qstr extraction stage), which
means unused MP_REGISTER_MODULE's are filtered out by the preprocessor.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-02 16:31:37 +10:00
Damien George 6bda80d811 esp32/machine_i2c: Implement write-then-read I2C transfers.
I2C transfers are much more efficient if they are combined, instead of
doing separate writes and reads.

Fixes issue #7134.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-01 13:20:30 +10:00
Damien George 6e71cde6aa ports: Use default VFS config for import_stat and builtin_open.
For ports with MICROPY_VFS and MICROPY_PY_IO enabled their configuration
can now be simplified to use the defaults for mp_import_stat and
mp_builtin_open.

This commit makes no functional change, except for the following minor
points:
- the built-in "open" is removed from the minimal port (it previously did
  nothing)
- the duplicate built-in "input" is removed from the esp32 port
- qemu-arm now delegates to VFS import/open

Signed-off-by: Damien George <damien@micropython.org>
2022-05-25 13:04:45 +10:00
David Lechner be5657b64f ports: Rename thread_t to mp_thread_t.
This adds the `mp_` prefix to the `thread_t` type.  The name `thread_t`
conflicts with the same in `mach/mach_types.h` on macOS.

Signed-off-by: David Lechner <david@lechnology.com>
2022-05-24 00:51:23 +10:00
Damien George c70f96f1c5 esp32: Track allocated iRAM and free it on soft reset.
This makes sure all iRAM allocated for native code is freed on soft reset.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-19 17:31:56 +10:00
Daniël van de Giessen ef16796f49 esp32/machine_pin: Fix ESP32C3 IDFv4.4.1 build.
Use new constants as seen in ESP-IDF commit b25fb1.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2022-05-19 16:47:13 +10:00
Algy Tynan 5dac142a1a esp32/boards/LILYGO_TTGO_LORA32: Remove ID from TTGO Lora32 board json.
Generic ID creates an incorrect link on the MicroPython download page.
Remove the ID to fix the link.

Signed-off-by: Algy Tynan <algy@tynan.io>
2022-05-19 16:45:18 +10:00
Michael Himing a1abf51a9d esp32/boards/UM_FEATHERS3: Use correct sdkconfig.board. 2022-05-19 16:43:59 +10:00
Jim Mussared 24127a4ac4 esp32: Make port-specific modules use MP_REGISTER_MODULE.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-18 20:56:30 +10:00
Jim Mussared bb794f05b7 extmod: Make port-included extmod modules use MP_REGISTER_MODULES.
_onewire, socket, and network were previously added by the port rather
than objmodule.c.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-18 20:49:12 +10:00
Jim Mussared 4eab44a1ec extmod: Make extmod modules use MP_REGISTER_MODULE.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-18 20:49:12 +10:00
Jim Mussared 0e7bfc88c6 all: Use mp_obj_malloc everywhere it's applicable.
This replaces occurences of

    foo_t *foo = m_new_obj(foo_t);
    foo->base.type = &foo_type;

with

    foo_t *foo = mp_obj_malloc(foo_t, &foo_type);

Excludes any places where base is a sub-field or when new0/memset is used.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-03 22:28:14 +10:00
Damien George eb9674822b esp32/modnetwork: Fix build when MICROPY_PY_NETWORK_WLAN is disabled.
Fixes issue #8541.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-22 21:56:31 +10:00
wemos ff28d2e3b3 esp32/network_wlan: Support setting/getting txpower in WLAN.config(). 2022-04-22 21:52:28 +10:00
Stephane Smith 988827b85a esp32/modesp32: Properly define RTC_VALID_EXT_PINS on S2/S3 variants.
On ESP32 S2/S3 variants, GPIO0 through GPIO21 are valid RTC pins.  This
commit defines the valid RTC_VALID_EXT_PINS for the S2/S3 variants,
otherwise, it keeps functionality the same.
2022-04-14 16:17:52 +10:00
Stephane Smith 7005354099 esp32/machine_pin: Don't expose pins 33-37 when octal SPIRAM is enabled.
For ESP32-S3 configurations, CONFIG_SPIRAM_MODE_OCT requires pins 33-37 for
PSRAM.  So exclude them from the machine_pin_type and machine_pin_irq_type
object tables.
2022-04-14 16:14:13 +10:00
Stephane Smith ae3d5289a5 esp32/boards: Compile GENERIC_SPIRAM and UM_TINYPICO with -Os.
These boards do not build with IDF v4.4 because the section .iram0.text
does not fit in region iram0_0_seg.  Enabling SPIRAM increases the code
size so use -Os instead of -O2 to build these boards.

Fixes issue #8260.
2022-04-14 16:06:41 +10:00
Damien George fe9eaf12f3 esp32: Add MICROPY_HW_ENABLE_UART_REPL and enable on generic S2/S3.
Some S2/S3 modules don't use the native USB interface but instead have an
external USB-UART.  To make the GENERIC_S3/S3 firmware work on these boards
the UART REPL is enabled in addition to the native USB CDC REPL.

Fixes issues #8418 and #8524.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 14:39:20 +10:00
Damien George be25e333df esp32/boards: Add test manifest to test freezing during build.
Includes tests for freezing @micropython.native and @micropython.viper
code.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 14:06:38 +10:00
Damien George aab005c75b extmod/modusocket: Provide config macro for socket.listen backlog deflt.
To make it possible to change this value for any given port or board.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-11 15:28:56 +10:00
Jon Bjarni Bjarnason 919f696ad2 extmod/modusocket: Implement optional socket.listen backlog argument.
This follows the CPython change: https://bugs.python.org/issue21455

Socket listen backlog defaults to 2 if not given, based on most bare metal
targets not having many resources for a large backlog.  On UNIX it defaults
to SOMAXCONN or 128, whichever is less.
2022-04-11 15:26:47 +10:00
iabdalkader 5682595d75 esp32: Allow overriding cmake frozen manifest from the command line.
If MICROPY_FROZEN_MANIFEST is set from the cmake command line, then it will
override the default and any manifest set by the board.
2022-04-04 23:49:10 +10:00
Kattni Rembor 61c02e6500 esp32/machine_pin: Expose pin 20 for ESP32.
This pin is available on some ESP32 packages.

Signed-off-by: Kattni Rembor <kattni@adafruit.com>
2022-03-22 10:40:00 +11:00
Algy Tynan afceb56ee2 esp32/boards: Add support for LilyGO LoRa32 boards.
Boards use ESP32-PICO-D4.

Added pins for hardware versions v1.0, v1.2, v1.6 and v2.0.

Signed-off-by: Algy Tynan <algy@tynan.io>
2022-03-22 00:19:36 +11:00
robert-hh 09b55dc297 esp32/machine_hw_spi: Use automatic DMA channel selection for SPI on C3.
Addresses issue #8204.
2022-03-22 00:13:25 +11:00
wemos 1a0bd352d3 esp32/boards: Add LOLIN C3 MINI ESP32-C3 based board. 2022-03-22 00:11:02 +11:00
Jonathan Hogg 3b9de192be esp32/boards/UM_TINYPICO: Remove use of PULL_HOLD.
Change APA102 power handling to not use the (now removed) PULL_HOLD
constant.
2022-03-21 23:59:48 +11:00
Jonathan Hogg 21d0599bd1 esp32/modesp32: Add new gpio_deep_sleep_hold function.
Add a new function to control whether held pins will retain their function
through deep-sleep.

Also document this function and explain how to use this in quickref to
retain pin configuration during deep-sleep.
2022-03-21 23:59:07 +11:00
Jonathan Hogg 7684c996bc esp32/machine_pin: Add new hold keyword argument and remove PULL_HOLD.
The current pull=Pin.PULL_HOLD argument doesn't make a lot of sense in the
context of what it actually does vs what the ESP32 quickref document says
it does.

This commit removes PULL_HOLD and adds a new hold=True|False keyword
argument to Pin()/Pin.init().  Setting this to True will cause the ESP32 to
lock the configuration of the pin – including direction, output value,
drive strength, pull-up/-down – such that it can't be accidentally changed
and will be retained through a watchdog or internal reset.

Fixes issue #8283, and see also #8284.
2022-03-21 23:55:02 +11:00
Damien George 818be10bb5 zephyr/moduos: Convert module to use extmod version.
This also adds uos.unlink(), for all ports that use extmod/moduos.c.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-09 10:03:23 +11:00
Damien George 1c53d85162 esp32/moduos: Convert module to use extmod version.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-09 10:03:23 +11:00
Damien George 926b554daf extmod/moduos: Create general uos module to be used by all ports.
Based on the rp2 port version, with the rp2 port converted to use this
module.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-09 10:03:23 +11:00
Jonathan Hogg 33083bf527 esp32/machine_pin: Add support for pin drive strength.
Add support for configuring drive strength of output pins with `drive` 
keyword argument and `DRIVE_*` constants.
2022-03-07 23:41:29 +11:00
robert-hh d696d9141e esp32/machine_uart: Make UART.init preserve unspecified parameters.
Most of the settings behaved that way, except for baudate, timeout,
timout_char, invert and flow.
2022-03-07 13:45:50 +11:00
robert-hh 55a0125a15 esp32/machine_pwm: Always set the duty cycle when setting the frequency.
If setting the frequency to a value used already by an existing timer, this
timer will be used.  But still, the duty cycle for that channel may have to
be changed.

Fixes issues #8306 and #8345.
2022-03-07 13:37:23 +11:00
Daniël van de Giessen 665f0e2a68 esp32: Sleep one tick in MICROPY_EVENT_POLL_HOOK.
If MicroPython threads are enabled, loops waiting for an incoming event
should release the GIL and suspend, allowing other tasks to run while they
wait.

Prior to this commit, the problem can easily be observed by running a
thread that is both busy and regularly releases the GIL (for example a loop
doing something then sleeping a few ms after each iteration).  When the
main task is at the REPL, the thread is significantly stalled.  If the main
task is manually made to release the GIL (for example, by calling
utime.sleep_ms(500)) the other thread can be seen immediately working at
the expected speed again.

Additionally, there are various instances in where blocking functions run
MICROPY_EVENT_POLL_HOOK in a loop while they wait for a certain event/
condition.  For example the uselect methods poll objects to determine
whether data is available, but uses 100% of CPU while it does, constantly
calling MICROPY_EVENT_POLL_HOOK in the process.

The MICROPY_EVENT_POLL_HOOK macro is only ever used in waiting loops, where
(if threads are enabled) it makes sense to yield for a single tick so that
these loops do not consume all CPU cycles but instead other threads may
execute.  (In fact, the thing these loops wait for may even indirectly or
directly depend on another task being able to run.)

This change moves the sleep that was inside the REPL input function to
inside the MICROPY_EVENT_POLL_HOOK macro, where the GIL is already being
released, solving both the blocking REPL issue and the 100% CPU use issue
at the same time.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2022-03-02 12:57:43 +11:00
Andrew Leech 919e586e46 esp32/machine_uart: Allow limited configuration of REPL UART.
Some applications may want to adjust the hard coded 115200 REPL buadrate,
and this commit allows it to be changed dynamically via machine.UART(0).
2022-03-01 18:16:50 +11:00
Andrew Leech 2cc9232781 esp32/uart: Correctly init low-level UART driver for REPL.
uart_driver_install() needs to be called to set up the UART correctly.
2022-03-01 17:33:36 +11:00
Damien George 546e213265 esp32/boards: Add specific deploy instructions for S3 variant.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-25 16:52:58 +11:00
Damien George 64bfaae7ab esp32/README.md: Update list of supported IDF versions.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-24 15:23:50 +11:00
Damien George f30b32e084 esp32/modules: Create ffat partition object with block_size=512.
Because these are formatted with a 512 sector size.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-22 00:37:55 +11:00
Damien George 106a83de22 esp32/esp32_partition: Add support for specifying block_size.
To support filesystems that use a block size different from the native
erase-page size.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-22 00:37:25 +11:00
Damien George 5935fa229c esp32/mpconfigport.h: Enable remaining features to get to "extra" level.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-18 16:01:18 +11:00
Damien George c8cd5a9960 esp32/mpconfigport.h: Use the "extra" feature level.
This commit is a no-op change to simplify existing config.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-18 15:50:01 +11:00
Seon Rozenblum aca40127bf esp32/boards: Add three UM ESP32-S3 based boards. 2022-02-09 00:13:10 +11:00
Damien George 468d1979ba esp32/machine_adc: Fix configuration of default ADC atten value.
Prior to this fix, if the ADC atten value was not explicitly given then
adc1_config_channel_atten() would never be called.

Fixes issue #8275.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-08 23:45:41 +11:00
Seon Rozenblum ada836b834 esp32/machine_adcblock: Fix ADC bit width for ESP32-S3. 2022-02-08 12:35:47 +11:00
Damien George 6fe3856c4f esp32/partitions-16MiB.csv: Increase 14MiB filesystem to maximum size.
The original value was 14000000, it's now changed to 14 * 1024 * 1024.

Fixes issue #8266.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-08 12:25:10 +11:00
Damien George fbd47fc46c ports: Consolidate inclusion of umachine module in built-ins.
The inclusion of `umachine` in the list of built-in modules is now done
centrally in py/objmodule.c.  Enabling MICROPY_PY_MACHINE will include this
module.

As part of this, all ports now have `umachine` as the core module name
(previously some had only `machine` as the name).

Signed-off-by: Damien George <damien@micropython.org>
2022-02-03 10:08:54 +11:00
Damien George 71b3ce3ace esp32: Create .uf2 binaries for S2 and S3 chips.
The name of the filesystem partition is updated to support "ffat", as used
by TinyUF2.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-02 23:47:49 +11:00
Damien George 872bab6b3c esp32: Remove unneeded modesp.h.
Made redundant by 71f4faac27

Signed-off-by: Damien George <damien@micropython.org>
2022-02-02 16:20:41 +11:00
Emil Kondayan b18d4392b4 esp32/adc: Fix wrong mapping between ADC2 channel and GPIO number.
According to the IO_MUX table in the ESP32 datasheet, the ADC2 channels are
mapped to different GPIO numbers.
2022-02-02 15:29:02 +11:00
Michael O'Cleirigh eae2e3516c esp32/main: Automatically size SPIRAM heap when allocated using malloc.
This change allows the same heap allocation rules to be used when using
malloc regardless if the board has SPRAM or normal RAM.

Integrating with the esp32-camera for example requires that ESP32 SPRAM be
allocatable using the esp-idf capabilities aware allocation functions.  In
the case of esp32-camera it's for the framebuffer.

Detect when CONFIG_SPIRAM_USE_MALLOC is in use and use the standard
automatic configuration of leaving 1/2 of the SPRAM available to other
FreeRTOS tasks.
2022-02-02 15:24:02 +11:00
Damien George 1f04a9a1fc esp32/esp32_rmt: Select correct last RMT channel on S2, S3, C3 variants.
For example the ESP32-C3 has 2 TX channels and 2 RX channels in total, and
in this case channel 1 must be the default for bitstream.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-01 16:58:56 +11:00
IhorNehrutsa 15e65b77eb esp32/machine_pwm: Clean up macro names and their use.
- Remove UI_RES_SHIFT macro.
- Rename PWFREQ to PWM_FREQ.
- Rename PWRES to PWM_RES_10_BIT.
- Use UI_RES_16_BIT flag instead of HIGHEST_PWM_RES.
2022-02-01 16:47:29 +11:00
IhorNehrutsa a5e64c209f esp32/machine_pwm: Fix PWM not allowing frequencies < 611 Hz.
Fixes issue #8189.
2022-02-01 16:46:55 +11:00
Damien George e1a84a0c6f esp32/partitions: Increase size of app-part from 0x180000 to 0x1F0000.
To fill out all of the available flash up to the start of the filesystem
partition.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-27 16:44:13 +11:00
ubi de feo ea5744fd8d esp32/boards: Provide custom deploy_c3.md for ESP32-C3 boards.
This fixes the flash address for installation on ESP32-C3.
2022-01-22 11:18:50 +11:00
Damien George bb9d688454 esp32/main: Use heap_caps_get_info on IDF <4.1 to compute total heap.
heap_caps_get_total_size() is only available in IDF 4.1 and above.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-22 10:46:31 +11:00
marcidy ac39960aa1 esp32/modnetwork: Fix test for WIFI_AUTH_MAX for IDF v4.3.0.
Signed-off-by: marcidy <marcidy@gmail.com>
2022-01-22 00:55:07 +11:00
Sean Coates 6a10d3ed99 esp32/README.md: Fix URL for esp-idf installation.
The current URL points to a pinned version of the document (v4.0.2) and is
currently not found (404).
2022-01-22 00:53:26 +11:00
Damien George 23b1a4e0b6 esp32/main: Allocate at most 1/2 of available IDF heap for MP heap.
So that there is some memory left for the OS, eg for ssl buffers.

See issue #7214.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-22 00:46:12 +11:00
Damien George 648656dbbd esp32/esp32_rmt: Call rmt_driver_install directly if running on core 1.
Signed-off-by: Damien George <damien@micropython.org>
2022-01-22 00:11:14 +11:00
jason 357078504d esp32: Pin MicroPython to core 1 again.
This follows up on #5489, where we changed the esp32 core pinning to core 0
in order to work around an issue with IDF < 4.2.0.  Now that IDF > 4.2.0 is
available, we allow pinning back to core 1, which eliminates some
problematic callback latency with WiFi enabled.

NimBLE is also pinned to core 1 - the same core as MicroPython - when using
IDF >=4.2.
2022-01-22 00:10:16 +11:00
Jonathan Hogg 63438a31bb esp32/machine_adcblock: Add new machine.ADCBlock class and update ADC.
Rework the ADC implementation to follow the improved ADC/ADCBlock API.
This adds support for calibrated voltage readings and the ADC2 block.  The
ADC API is backwards compatible with what it was before this change.

Resolves #6219.
2022-01-21 22:55:24 +11:00
Damien George a3bbd5332b esp32/machine_bitstream: Reinstate bitstream bit-bang implementation.
The bit-bang implementation was replaced with the RMT implementation in
599b61c086.  This commit brings back that
bit-bang code, and allows it to be selected via the new static method:

    esp32.RMT.bitstream_channel(None)

The bit-bang implementation may be useful if the RMT needs to be used for
something else, or if bit-banging is more stable in certain applications.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-14 16:40:01 +11:00
Damien George e754c2e84f esp32/esp32_rmt: Install RMT driver on core 1.
MicroPython currently runs on core 0 of the esp32.  Calling
rmt_driver_install will mean that the RMT interrupt handler is also
serviced on core 0.  This can lead to glitches in the RMT output if
WiFi is enabled (for esp32.RMT and machine.bitstream).

This patch calls rmt_driver_install on core 1, ensuring that the RMT
interrupt handler is serviced on core 1.  This prevents glitches.

Fixes issue #8161.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-14 15:41:59 +11:00
Damien George ff0227fa0d esp32/boards/GENERIC_D2WD: Build with -Os optimisation.
This board has only 2MiB of flash so the build needs to be reduced in size
to fit.  Commit 549448e8bb made all boards
build with -O2 by default (for performance) so this overrides that default.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-09 11:25:37 +11:00
Damien George df3f59ca4b ports: Update board.json files to link to new board images.
Signed-off-by: Damien George <damien@micropython.org>
2022-01-07 11:33:28 +11:00
Damien George b96318ab61 esp32: Enable platform module with IDF version.
Output looks like this:

    >>> import platform
    >>> platform.libc_ver()
    ('newlib', '3.0.0')
    >>> platform.platform()
    'MicroPython-1.17.0-xtensa-IDFv4.2.2-with-newlib3.0.0'
    >>> platform.python_compiler()
    'GCC 8.4.0'

Signed-off-by: Damien George <damien@micropython.org>
2022-01-06 18:25:48 +11:00
Simon Baatz 79ae7098ca esp32/machine_bitstream: Fix signal duplication on output pins.
After changing the bitstream implementation to use the RMT driver in
commit 72d8615812
("esp32/machine_bitstream.c: Replace with RMT-based driver."), using
multiple `Neopixel` instances shows signal duplication between the
instances (i.e. a `write()` on one instance is written to all instances).

On invocation, the rmt driver configures the GPIO matrix to route the
output signal to the respective GPIO pin.  When called for a different
`NeoPixel` instance using a different pin, the new route is established,
but the old route still exists.  Now, the RMT output signal is sent to both
pins.

Fix this by setting the standard GPIO output function for the current pin
after uninstalling the RMT driver.

Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
2022-01-06 13:21:37 +11:00
MikeTeachman 49d8ae3ecc esp32/machine_i2s: Add support for ESP-IDF 4.4.
- Add default values for I2S features added in ESP-IDF 4.4.
- Add workaround for bug introduced in ESP-IDF 4.4
  (https://github.com/espressif/esp-idf/issues/8121).
2022-01-06 13:10:38 +11:00
Jim Mussared 599b61c086 esp32/machine_bitstream: Replace bit-bang code with RMT-based driver.
This aims to solve glitching issues on long neopixel strips.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-12-22 12:04:13 +11:00
IhorNehrutsa 09fe80d091 esp32/machine_pwm: Keep duty constant when changing frequency.
Save and restore the same duty cycle when the frequency (or frequency
resolution) is changed.  This allows a smooth frequency change.

Also update the esp32 PWM quickref to be clearer.
2021-12-22 00:05:58 +11:00
IhorNehrutsa 4189c64869 esp32/modnetwork: Synchronize WiFi AUTH_xxx constants with IDF values. 2021-12-21 23:56:23 +11:00
Damien George de43b500bd py/runtime: Allow initialising sys.path/argv with defaults.
If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is enabled (which it is by default)
then sys.path and sys.argv will be initialised and populated with default
values.  This keeps all bare-metal ports aligned.

Signed-off-by: Damien George <damien@micropython.org>
2021-12-18 00:08:07 +11:00
Jim Mussared 86ce442607 ports: Add '.frozen' as the first entry in sys.path.
Frozen modules will be searched preferentially, but gives the user the
ability to override this behavior.

This matches the previous behavior where "" was implicitly the frozen
search path, but the frozen list was checked before the filesystem.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-12-18 00:08:07 +11:00
Tomas Vanek 9aa151e3f3 esp32/boards: Remove SPI pin defaults from GENERIC S2/S3 boards.
Default SPI pins are now correctly assigned by machine_hw_spi.c even for S2
and S3.  mpconfigboard.h files define defaults with flipped SPI(1) and
SPI(2) to workaround a bug in machine_hw_spi.c - the bug is fixed.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
2021-12-15 15:53:17 +11:00
Tomas Vanek e761152d72 esp32/machine_hw_spi: Set proper default SPI(id=2) pins on S2 and S3.
Use IO_MUX pins as defined by ESP IDF in soc/esp32/include/soc/spi_pins.h

ESP32S2 and S3 don't have IO_MUX pins for SPI3, GPIO matrix is always used.
Choose suitable defaults for S2 and S3.

ESP32C3 does not have SPI3 at all.  Don't define pin mappings for it.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
2021-12-15 15:53:17 +11:00
Tomas Vanek d08886558b esp32/machine_hw_spi: Set proper default SPI(id=1) pins on S2,S3 and C3.
Use IO_MUX pins as defined by ESP IDF in soc/esp32*/include/soc/spi_pins.h
Alternatively use now deprecated HSPI_IOMUX_PIN_NUM_xxx
(or FSPI_IOMUX_PIN_NUM_xxx for ESP32S2) for compatibility with IDF 4.2
and older.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
2021-12-15 15:50:27 +11:00
Tomas Vanek 3305ec44a2 esp32/machine_hw_spi: Fix SPI default pins reordering on ESP32-S2/S3.
The index of machine_hw_spi_obj and machine_hw_spi_default_pins arrays is
assigned to 0 for ARG_id==HSPI_HOST and 1 for another SPI.  On ESP32S2 and
S3 HSPI_HOST=2 so the first set (idx=0) of default pins is used for
SPI(id=2) aka HSPI/SPI3 and the second set (idx=1) for SPI(id=1) aka
FSPI/SPI2.  This makes a misleading mess in MICROPY_HW_SPIxxxx definitions
and it is also in contradiction to the comments around the definitions.

Change the test of ARG_id to fix the order of machine_hw_spi_default_pins.

This change might require adjusting MICROPY_HW_SPIxxxx definitions in
mpconfigboard.h of S2/S3 based boards.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
2021-12-15 15:49:23 +11:00
Tomas Vanek f9733705a9 esp32/machine_pin: Make GPIO 26 usable for S2,S3 if SPIRAM not config'd.
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
2021-12-15 15:48:46 +11:00
Damien George 5adb1fa40e esp32,esp8266: Extract qstr from object when comparing keys in config().
Following on from a previous fix for the same problem made in
3a431fba50.

Fixes issue #8052.

Signed-off-by: Damien George <damien@micropython.org>
2021-12-14 14:27:13 +11:00
IhorNehrutsa b491967bbd esp32/machine_pwm: Implement duty_u16() and duty_ns() PWM methods.
The methods duty_u16() and duty_ns() are implemented to match the existing
docs.  The duty will remain the same when the frequency is changed.
Standard ESP32 as well as S2, S3 and C3 are supported.

Thanks to @kdschlosser for the fix for rounding in resolution calculation.

Documentation is updated and examples expanded for esp32, including the
quickref and tutorial.  Additional notes are added to the machine.PWM docs
regarding limitations of hardware PWM.
2021-12-03 23:58:52 +11:00
Jim Mussared 678f4b959f esp32/boards/GENERIC_S3: Enable BLE on ESP32 S3.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-11-26 11:58:12 +11:00
Seon Rozenblum 1904833e0c esp32: Add SDCard support for S3, and a GENERIC_S3_SPIRAM board.
Also add support for GPIO 47 and 48 on S3 boards.
2021-11-19 14:05:55 +11:00
MikeTeachman 6d5296e65e stm32,esp32: In machine_i2s, make object reference arrays root pointers.
This change eliminates the risk of the IRQ callback accessing invalid data.
Discussed here:
https://github.com/micropython/micropython/pull/7183#discussion_r660209875

Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
2021-11-13 12:22:42 +11:00
MikeTeachman 0be3b91f11 stm32,esp32: In machine_i2s, send null samples in underflow situations.
Eliminate noise data from being sent to the I2S peripheral when the
transmitted sample stream is stopped.

Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
2021-11-12 16:50:15 +11:00
Magnus von Wachenfeldt 6d9da27c21 esp32: Support building with latest IDF v5.
The latest ESP-IDF v5.0-dev declares MAJOR_VERSION 5 and MINOR_VERSION 0.
timer_ll_set_alarm_enable() is also changed to timer_ll_set_alarm_value().
2021-11-12 16:40:46 +11:00
Mike Causer 7f14344428 ports: Add images, features and urls to board.json. 2021-10-28 15:25:38 +11:00
Mike Causer 07ea1afe74 esp32/boards/ESP32_S2_WROVER: Link to specific deploy_s2 instructions. 2021-10-28 12:58:58 +11:00
Mike Causer 3ace779e8e esp32/boards/LOLIN_S2_PICO: Add LOLIN_S2_PICO board definition files. 2021-10-28 12:58:50 +11:00
Damien George 1e4849557d esp32/usb: Further improve speed of USB CDC output.
Following on from ba940250a5, the change here
makes output about 15 times faster (now up to about 550 kbytes/sec).

tinyusb_cdcacm_write_queue will return the number of bytes written, so
there's no need to use tud_cdc_n_write_available.

Signed-off-by: Damien George <damien@micropython.org>
2021-10-28 11:37:35 +11:00
Seon Rozenblum 5b9c9cd097 esp32/boards: Update board and deploy metadata for UM_xxx boards. 2021-10-28 11:32:13 +11:00
Mike Causer 5bb14c4e46 esp32/boards/LOLIN_S2_MINI: Add image to board.json. 2021-10-28 09:51:04 +11:00
Jim Mussared 910e9f9111 esp32: Add specific deploy_s2.md instructions for esp32-s2.
In particular the UM S2 boards (and update the features list).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-10-28 09:47:47 +11:00
Jim Mussared e359b077dd ports: Add board.json for all boards.
This will be used by https://micropython.org/download/ to generate the
full listing of boards and firmware files.

Optionally supports a board.md for additional customisation of the
download page, as well as deploy.md for flashing instructions.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-10-27 14:04:53 +11:00
Damien George ba940250a5 esp32/usb: Improve speed of USB CDC output.
Signed-off-by: Damien George <damien@micropython.org>
2021-10-16 00:23:59 +11:00
Damien George 549448e8bb esp32: Enable optimisations and move code to iRAM to boost performance.
This commit enables some significant optimisations for esp32:
- move the VM to iRAM
- move hot parts of the runtime to iRAM (map lookup, load global/name,
  mp_obj_get_type)
- enable MICROPY_OPT_LOAD_ATTR_FAST_PATH
- enable MICROPY_OPT_MAP_LOOKUP_CACHE
- disable assertions
- change from -Os to -O2 for compilation

It's hard to measure performance on esp32 due to external flash and
hardware caching.  But this set of changes improves performance compared to
master by (on a TinyPICO with the GENERIC build, using IDF 4.2.2, running
at 160MHz):

diff of scores (higher is better)
N=100 M=100    esp32-master -> esp32-perf       diff      diff% (error%)
bm_chaos.py           71.28 ->     268.08 :  +196.80 = +276.094% (+/-0.04%)
bm_fannkuch.py        44.10 ->      69.31 :   +25.21 = +57.166% (+/-0.01%)
bm_fft.py           1385.27 ->    2538.23 : +1152.96 = +83.230% (+/-0.01%)
bm_float.py         1060.94 ->    3900.62 : +2839.68 = +267.657% (+/-0.03%)
bm_hexiom.py          10.90 ->      32.79 :   +21.89 = +200.826% (+/-0.02%)
bm_nqueens.py       1000.83 ->    2372.87 : +1372.04 = +137.090% (+/-0.01%)
bm_pidigits.py       288.13 ->     664.40 :  +376.27 = +130.590% (+/-0.46%)
misc_aes.py          102.45 ->     345.69 :  +243.24 = +237.423% (+/-0.01%)
misc_mandel.py      1016.58 ->    2121.92 : +1105.34 = +108.731% (+/-0.01%)
misc_pystone.py      632.91 ->    1801.87 : +1168.96 = +184.696% (+/-0.08%)
misc_raytrace.py      76.66 ->     281.78 :  +205.12 = +267.571% (+/-0.05%)
viper_call0.py       210.63 ->     273.17 :   +62.54 = +29.692% (+/-0.01%)
viper_call1a.py      208.45 ->     269.51 :   +61.06 = +29.292% (+/-0.00%)
viper_call1b.py      185.44 ->     228.25 :   +42.81 = +23.086% (+/-0.01%)
viper_call1c.py      185.86 ->     228.90 :   +43.04 = +23.157% (+/-0.01%)
viper_call2a.py      207.10 ->     267.25 :   +60.15 = +29.044% (+/-0.00%)
viper_call2b.py      173.76 ->     209.42 :   +35.66 = +20.523% (+/-0.00%)

Five tests have more than 3x speed up (200%+).

The performance of the tests bm_fft, bm_pidigits and misc_aes now scale
with CPU frequency (eg changing frequency to 240MHz boosts the performance
of these by 50%), which means they are no longer influenced by timing of
external flash access.  (The viper_call* tests did previously scale with
CPU frequency, and they still do.)

Turning off assertions reduces code size by about 80k, and going from -Os
to -O2 costs about 100k, so the net change in code size (for the GENERIC
board) is about +20k.

If a board wants to enable assertions, or use -Os instead of -O2, that's
still possible by overriding the sdkconfig parameters.

Signed-off-by: Damien George <damien@micropython.org>
2021-10-16 00:07:11 +11:00
Damien George ea186de4c5 esp32: Split out WLAN code from modnetwork.c to network_wlan.c.
To match network_lan.c and network_ppp.c, and make it clear what code is
specifically for WLAN support.

Also provide a configuration option MICROPY_PY_NETWORK_WLAN which can be
used to fully disable network.WLAN (it's enabled by default).

Signed-off-by: Damien George <damien@micropython.org>
2021-09-24 12:41:35 +10:00
Damien George f046b50ca5 esp32/main: Add option for a board to hook code into startup sequence.
To do this the board must define MICROPY_BOARD_STARTUP, set
MICROPY_SOURCE_BOARD then define the new start-up code.

For example, in mpconfigboard.h:

    #define MICROPY_BOARD_STARTUP board_startup
    void board_startup(void);

in mpconfigboard.cmake:

    set(MICROPY_SOURCE_BOARD
        ${MICROPY_BOARD_DIR}/board.c
    )

and in a new board.c file in the board directory:

    #include "py/mpconfig.h"

    void board_startup(void) {
        boardctrl_startup();
        // extra custom startup
    }

This follows stm32's boardctrl facilities.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-24 12:23:14 +10:00
leo chung 4fdf795efa esp32/mpthreadport: Fix TCB cleanup function so thread_mutex is ready.
Because vPortCleanUpTCB is called by the FreeRTOS idle task, and it checks
thread, but didn't check the thread_mutex.

And if thread is not NULL, but thread_mutex not ready then it will crash
with an error when calling mp_thread_mutex_lock(&thread_mutex, 1).

As suggested by @dpgeorge, move the thread = &thread_entry0 line to the end
of mp_thread_init().

Signed-off-by: leo chung <gewalalb@gmail.com>
2021-09-24 12:12:03 +10:00
Seon Rozenblum a39a596b79 esp32/machine_pin: Block out IO16 and IO17 when using SPIRAM on ESP32.
Fixes issue #7819.
2021-09-24 10:56:09 +10:00
Seon Rozenblum 35fb90bd57 esp32/usb: Add USB host connection detection for CDC serial output.
This callback allows detecting if there is a USB host connected to the CDC
or not, in which case the stdout_tx should skip CDC TX writing and
flushing or the system will block.

Fixes issue #7820.
2021-09-22 00:42:20 +10:00
Seon Rozenblum 7bf466a281 esp32/README: Updated readme with req IDF vers for ESP32-S2, C3 and S3. 2021-09-22 00:41:02 +10:00
IhorNehrutsa 52636fa692 esp32/machine_pwm: Add support for all PWM timers and channels.
This commit allows using all the available PWM timers (up to 8) and
channels (up to 16), without affecting the PWM API.

If a new frequency is set, first it checks if another timer is using the
same frequency.  If yes, then it uses this timer, otherwise, it creates a
new one.  If all timers are used, the user should set an already used
frequency, or de-init a channel.

This work is based on #6276 and #3608.
2021-09-21 23:18:09 +10:00
Stewart Bonnick 0d9429f44c esp32/boards: Add LOLIN_S2_MINI ESP32-S2 board.
To support Lolin S2 Mini ESP32-S2 Variant board.  More information about
this board can be found at https://www.wemos.cc/en/latest/s2/s2_mini.html
2021-09-21 22:49:51 +10:00
patrick 4cfd85eb4a esp32/boards: Add board definition for ESP32-S2-WROVER module. 2021-09-19 16:49:35 +10:00
Seon Rozenblum 13e6e0d7f5 esp32/machine_hw_spi: Fix hardware SPI DMA channels for S2/S3. 2021-09-19 10:23:12 +10:00
Damien George 80fe25689f esp32/boards: Add new GENERIC_S3 board definition.
Thanks to Seon Rozenblum aka @UnexpectedMaker for the work.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-16 22:58:47 +10:00
Damien George 54d33b266c esp32: Add support for ESP32-S3 SoCs.
Thanks to Seon Rozenblum aka @UnexpectedMaker for the work.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-16 22:58:47 +10:00
Seon Rozenblum f690fd3a47 esp32/machine_timer: Use tx_update member for IDF 4.4 and above. 2021-09-13 18:25:16 +10:00
Seon Rozenblum 9a7f77bfbc esp32/boards: Add new FeatherS2-Neo board definition. 2021-09-10 15:40:32 +10:00
Damien George af64c2ddbd extmod/machine_pwm: Factor out machine.PWM bindings to common code.
This commit refactors machine.PWM and creates extmod/machine_pwm.c.  The
esp8266, esp32 and rp2 ports all use this and provide implementations of
the required PWM functionality.  This helps to reduce code duplication and
keep the same Python API across ports.

This commit does not make any functional changes.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-04 16:31:17 +10:00
Damien George d41f6dde56 extmod/modonewire: Make _onewire module configurable via macro option.
Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Damien George afe0634c98 extmod/machine_spi: Make SoftSPI configurable via macro option.
Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Damien George 122d901ef1 extmod/machine_i2c: Make SoftI2C configurable via macro option.
The zephyr port doesn't support SoftI2C so it's not enabled, and the legacy
I2C constructor check can be removed.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
David Lechner 86371781e9 tools/uncrustify: Force 1 newline at end of file.
To keep things neat and tidy, we ensure that each file has 1 and only 1
newline at the end of each file.

Signed-off-by: David Lechner <david@pybricks.com>
2021-08-31 13:14:45 +10:00
Patrick Van Oosterwijck a66bd7a489 esp32/boards: Add GENERIC_C3_USB board with USB serial/JTAG support.
Add a new board type for ESP32-C3 revision 3 and up that implement the USB
serial/JTAG port on pin 18 and 19.  This variant uses the USB serial for
programming and console, leaving the UART free.

- Pins 18 and 19 are correctly reserved for this variant.  Also pins 14-17
  are reserved for flash for any ESP32-C3 so they can't be reconfigured
  anymore to crash the system.
- Added usb_serial_jtag.c and .h to implement this interface.
- Interface was tested to work correctly together with webrepl.
- Interface was tested to work correctly when sending and receiving
  large files with ampy.
- Disconnecting terminal or USB will not hang the system when it's
  trying to print.
2021-08-31 00:12:41 +10:00
Jim Mussared 996f703166 esp32,esp8266: Remove dead code for end_ticks in machine_bitstream.
The compiler was optimising this out already so it's a no-op change.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-24 23:55:08 +10:00
Jim Mussared 62fd450e62 drivers/neopixel: Add common machine.bitstream-based neopixel module.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-19 22:50:32 +10:00
Jim Mussared 71f4faac27 esp32: Replace esp.neopixel with machine.bitstream.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-19 22:50:32 +10:00
Damien George e25c5cb8d2 esp32/machine_pin: Make check for non-output pins respect chip variant.
Fixes issue #7631.

Signed-off-by: Damien George <damien@micropython.org>
2021-08-16 15:24:05 +10:00
Jonathan Hogg 5b655665ab esp32/machine_hw_spi: Release GIL during transfers.
Release the GIL while waiting for SPI transfers to complete to allow other
threads to make progress.

Fixes #7662.
2021-08-16 15:21:10 +10:00
Jim Mussared 5733c49174 stm32,esp32,rp2: Enable MICROPY_PY_FSTRINGS by default.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-14 16:58:40 +10:00
Damien George 3835f5f597 esp32/makeimg.py: Get bootloader and partition offset from sdkconfig.
So that it works on ESP32C3, which has the bootloader at 0x0.

Fixes issue #7565.

Signed-off-by: Damien George <damien@micropython.org>
2021-08-10 00:19:49 +10:00
Damien George 8616129f2e esp8266,esp32: Include hidden networks in WLAN.scan results.
Addresses issues #2697 and #5329.

Signed-off-by: Damien George <damien@micropython.org>
2021-08-07 13:28:34 +10:00
Jim Mussared bfc8e88ce1 esp32/mpconfigport.h: Enable reverse and inplace special methods.
Reverse operations are supported on stm32 and rp2, and esp32 has enough
space to also enable inplace operations, to make it complete.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-07 13:27:09 +10:00
Patrick Van Oosterwijck 028fc815cd esp32/boards: Add Silicognition wESP32 board configuration.
For rev 7+ boards with 16MB of flash.  Partition table allocates 2.4 MiB
for MicroPython, 11 MiB for the filesystem.
2021-08-07 12:50:13 +10:00
Will Sowerbutts a3675294ae esp32/machine_uart: Add flow kw-arg to enable hardware flow control.
This enables optional support for the hardware UART to use the RTS and/or
CTS pins for flow control.

The new "flow" constructor keyword specifies a bitmask of RTS and/or CTS.
This matches the interface used by machine.UART on stm32 and rp2.

Previously on ESP32 it was possible to specify which pins to use for the
RTS and CTS signals, but hardware flow control was never functional: CTS
was not checked before transmitting bytes, and RTS was always driven high
(signalling no buffer space available).  With this patch, CTS and RTS both
operate as expected.

This also includes an update to the machine.UART documentation.

Signed-off-by: Will Sowerbutts <will@sowerbutts.com>
2021-08-04 13:52:15 +10:00
Damien George 6214fa3f9e esp32/mphalport: Always yield at least once in delay_ms.
This helps the OS switch to and give other threads processing time during
the sleep.  It also ensures that pending events are handled, even when
sleeping for 0ms.

Fixes issue #5344.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-22 00:20:53 +10:00
Damien George 2cfbe5bc0f esp32/modmachine: Release the GIL in machine.idle().
So that other threads get a chance to run when taskYIELD() is called.

See issue #5344.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-22 00:17:59 +10:00
Damien George c77225ae5b esp32/boards/GENERIC_C3: Add generic C3-based board.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 23:58:24 +10:00
Damien George 6823514845 esp32: Add initial support for ESP32C3 SoCs.
Supported features for this SoC are:
- UART REPL, filesystem
- Pin, ADC, PWM, SoftI2C, SoftSPI, Timer, RTC
- OneWire, DHT, NeoPixel
- RMT
- WiFi, Bluetooth

Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 23:58:24 +10:00
Damien George 59dbbe9be7 esp32: Fix use of mp_int_t, size_t and uintptr_t.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 23:58:16 +10:00
Damien George 0fc0ccabec esp32/machine_i2s: Add MICROPY_PY_MACHINE_I2S option, enable by default.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 12:31:13 +10:00
Damien George 1f9243f8d4 esp32/machine_dac: Add MICROPY_PY_MACHINE_DAC option, enable by default.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 12:11:10 +10:00
Jonathan Hogg 8be29b9b1b esp32/machine_hw_spi: Use a 2 item SPI queue for long transfers.
Using a 2-item transaction queue instead of 1 allows long transfers to 
be executed with the minimum inter-transaction delay. Limit maximum 
transaction length to ensure an integer multiple of the SPI `bits` 
setting are transferred. Fixes #7511.
2021-07-16 16:12:45 +01:00
Jonathan Hogg eb3029c669 esp32/machine_spi: Calculate actual attained baudrate.
Calculate the actual baudrate that the hardware is capable of achieving 
and remember it so that printing the SPI object will show this. Fixes 
#7530.
2021-07-16 23:05:30 +10:00
Damien George 136369d72f all: Update to point to files in new shared/ directory.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12 17:08:10 +10:00
Damien George 925878b2f8 ports: Update for move of crypto-algorithms, uzlib to lib.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12 16:37:20 +10:00
Damien George 132d93886f ports: Use common mp_hal_stdout_tx_strn_cooked instead of custom one.
To reduce code duplication.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-08 12:59:31 +10:00
Mike Teachman 8a5bfe44a5 esp32,stm32: Add new machine.I2S class for I2S protocol support.
This commit adds I2S protocol support for the esp32 and stm32 ports, via
a new machine.I2S class.  It builds on the stm32 work of blmorris, #1361.

Features include:
- a consistent I2S API across the esp32 and stm32 ports
- I2S configurations supported:
  - master transmit and master receive
  - 16-bit and 32-bit sample sizes
  - mono and stereo formats
  - sampling frequency
  - 3 modes of operation:
    - blocking
    - non-blocking with callback
    - uasyncio
  - internal ring buffer size can be tuned
- documentation for Pyboards and esp32-based boards
- tested on the following development boards:
  - Pyboard D SF2W
  - Pyboard V1.1
  - ESP32 with SPIRAM
  - ESP32

Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
2021-07-05 23:42:25 +10:00
Jonathan Hogg 18e48a71ee esp32/esp32_rmt: Enhance RMT with idle_level and write_pulses modes.
This change allows specification of the idle level and TX carrier output
level (through changed initialisation API), and more flexible specification
of pulses for write_pulses.

This is a breaking change for the esp32.RMT constructor API.  Previous code
of this form:

    esp32.RMT(..., carrier_duty_percent=D, carrier_freq=F)

will now raise an exception and should be changed to:

    esp32.RMT(..., tx_carrier=(F, D, 1))
2021-07-01 13:39:39 +10:00
Jonathan Hogg 30422ca7c2 esp32/esp32_rmt: Fix RMT looping in newer IDF versions.
When looping, now disable the TX interrupt after calling rmt_write_items()
function to handle change in IDF behaviour (since v4.1).  Also check length
of pulses to ensure it fits hardware limit.

Fixes issue #7403.
2021-06-25 12:05:12 +10:00
Damien George 0009a7dc30 esp32/main: Allow MICROPY_DIR to be overridden.
This is necessary when building a custom out-of-tree board.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-24 16:03:25 +10:00
Michael Weiss b3a34dde36 esp32,esp8266: Add __len__ to NeoPixel driver to support iterating.
Signed-off-by: mishafarms <github@mishafarms.us>
2021-06-22 16:33:55 +10:00
Damien George bbf9dd849a esp32/boards/sdkconfig.base: Disable MEMPROT_FEATURE to alloc from IRAM.
Dynamically generate/loaded native code (eg from @micropython.native or
native .mpy files) needs to be able allocate from IRAM, and the memory
protection feature must be disabled for that to work.  Disabling it is
needed to get native code working on ESP32-S2 and -C3.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-20 22:54:20 +10:00
Damien George 4eb13c50cd esp32/machine_sdcard: Use deinit_p to deinit SD bus in SPI mode.
Fixes issue #7352.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-18 09:55:22 +10:00
Jonathan Hogg 89945b1989 esp32/machine_hw_spi: Allow None for unused pins in initializer.
Make the hardware SPI initializer method match the `init()` method by 
allowing `None` to be given for `sck`/`mosi`/`miso` to specify an unused 
signal.
2021-06-17 18:52:22 +10:00
Thomas Wenrich 060066804a esp32/modnetwork: Add "reconnects" option to WLAN STA interface.
This adds a wlan.config(reconnects=N) option to set the number of reconnect
attempts that will be made if the WLAN connection goes down.  The default
is N=-1 (infinite retries, current behavior).  Setting
wlan.config(reconnects=0) will disable the reconnect attempts.

A nice side effect of reconnects=0 is that wlan.status() will report the
disconnect reason now.  See related issue #5326.
2021-06-17 18:48:06 +10:00
Tobias Eydam 48437cec45 esp32/network_lan: Add Ethernet support for IDF v4.1 and above.
Ethernet-PHYs from ESP-IDF (LAN8720, IP101, RTL8201, DP83848) are now
supported in IDF v4.1 and above.  PHY_KSZ8041 is only for ESP-IDF 4.3 and
above.  ESP32S2 is not supported.

Signed-off-by: Tobias Eydam <eydam-prototyping@outlook.com>
2021-06-17 15:36:14 +10:00
IhorNehrutsa da8aad18a4 esp32/README: Describe how to select compatible version of existing IDF. 2021-06-11 19:52:10 +10:00
noslaver f314cac604 esp32/partitions-2MiB.csv: Update table so firmware fits.
The current MicroPython app size is larger than the size allocated in the
partitions table.
2021-06-11 17:57:40 +10:00
Damien George 865abba197 esp32/makeimg.py: Load sizes from partition table and verify data fits.
Changes introduced are:
- the application offset is now loaded from the partition table instead of
  being hard-coded to 0x10000
- maximum size of all sections is computed using the partition table
- an error is generated if any section overflows its allocated space
- remaining bytes are printed for each section

Signed-off-by: Damien George <damien@micropython.org>
2021-06-11 15:43:49 +10:00
leo chung fad0efdcf2 esp32/Makefile: Fix wrong target for partition-table.bin.
"$(BUILD)/partition_table/partition  -table.bin" is typing mistake.

Signed-off-by: leo chung <gewalalb@gmail.com>
2021-06-04 01:04:35 +10:00
Joseph Chiu c5d2095e59 esp32/espneopixel: Add support for GPIO32 and GPIO33.
Adds support for NeoPixels on GPIO32 and GPIO33 on ESP32.  Otherwise,
NeoPixels wired to GPIO32/33 wll silently fail without any hints to the
user.

With thanks to @robert-hh.

Fixes issue #7221.
2021-05-30 23:36:50 +10:00
IAMLIUBO a18f695e29 esp32/boards: Add M5STACK_ATOM board definition.
ATOM is a very small ESP32 development board produced by M5Stack, with a
size of 24mm * 24mm, with peripherals such as WS2812, IR, button, MPU6886
(Only Matrix), and 8 GPIO extensions.  It also has a plastic shell.
2021-05-30 23:15:13 +10:00
Damien George db8704ecbd esp8266,esp32: Update manifest to point to new dirs in micropython-lib.
Following a refactoring of micropython-lib.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-28 18:32:56 +10:00
Mike Causer 605b74f390 esp32/boards: Fix spelling mistakes in comments for UM_xxx boards. 2021-05-14 22:26:29 +10:00
Mike Causer 9e65662a11 esp32/boards: Set default I2C and SPI pins on UM_xxx boards.
And fix incorrect I2C and SPI pins in the feathers2 module.
2021-05-14 22:26:05 +10:00
Mike Causer 538b9a9be5 esp32/machine_i2c: Allow boards to configure I2C pins using new macros.
Following how SPI is configured (and how stm32 does it).
2021-05-14 22:22:13 +10:00
Chris Greening cce7096d1a esp32/boards/UM_TINYPICO: Fix include of sdkconfig fragment.
This was broken by 32ec07a350
2021-05-11 09:36:41 +10:00
Damien George 0e87459e2b esp32/boards: Add UM_FEATHERS2 and UM_TINYS2 board definitions.
Based on original commit made by Seon Rozenblum aka @UnexpectedMaker.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-10 16:56:53 +10:00
Seon Rozenblum 32ec07a350 esp32/boards: Rename TINYPICO board to UM_TINYPICO.
And add default hardware SPI 0 pins in mpconfigboard.h, and
CONFIG_LWIP_LOCAL_HOSTNAME in sdkconfig.board.
2021-05-10 16:56:53 +10:00
Damien George 5093d49fae esp32: Extend support for S2 series, and S3 where applicable.
Improvements made:
- PSRAM support for S2
- partition definition for 16MiB flash
- correct ADC and DAC pins
- correct GPIO and IRQ pins
- S3 components in CMakeLists

Based on original commit made by Seon Rozenblum aka @UnexpectedMaker.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-10 16:56:53 +10:00
Damien George 864e4ecc47 esp32/mpthreadport: Use binary semaphore instead of mutex.
So a lock can be acquired on one Python thread and then released on
another.  A test for this is added.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-08 22:47:03 +10:00
Damien George 31e0b8c71c esp32/mpthreadport: Don't explicitly free thread struct in TCB cleanup.
Because vPortCleanUpTCB runs on the FreeRTOS idle task and cannot execute
any VM or runtime related code like freeing memory.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-08 22:47:03 +10:00