Commit Graph

281 Commits

Author SHA1 Message Date
Josh Lloyd
59c1b7d4b8 esp32/boards: Split out CPU frequency config, make 160MHz the default.
Remove the 240MHz CPU config option from sdkconfig.base and create a new
sdkconfig.240mhz file for those boards that want to use 240MHz on boot.

The default CPU frequency is now 160MHz (was 240MHz), to align with the ESP
IDF and support more boards (eg those with D2WD chips).

Fixes issue #5169.
2019-10-18 13:42:24 +11:00
Jeremy Herbert
7a7ee16ccf esp32/machine_uart: Add ability to invert UART pins. 2019-10-18 12:05:16 +11:00
Damien George
ce1de1faf0 esp32: Convert to use FROZEN_MANIFEST to specify frozen code.
All symlinks are removed.  boards/manifest.py is used as a default, and can
optionally use boards/manifest_release.py for more scripts.
2019-10-15 21:37:02 +11:00
Jim Mussared
4b2b05718a esp32: Run NimBLE on the app core.
This prevents issues with concurrent access to the ringbuf.
MICROPY_BEGIN_ATOMIC_SECTION is only atomic to the same core.  We could
address this with a mutex, but it's also not safe to call mp_sched_schedule
across cores.
2019-10-15 17:22:15 +11:00
Jim Mussared
418f12c5f5 extmod/modbluetooth: Increase maximum connections from 1 to 4.
This avoids a confusing ENOMEM raised from gap_advertise if there is
currently an active connection.  This refers to the static connection
buffer pre-allocated by Nimble (nothing to do with MicroPython heap
memory).
2019-10-15 17:20:25 +11:00
Damien George
d7a9388fe0 ports: Add new make target "submodules" which inits required modules. 2019-10-15 17:14:41 +11:00
Jim Mussared
d5cbee3cfb esp32: Add 4.x version of IDLE WDT config. 2019-10-11 14:30:47 +11:00
Jim Mussared
cd8bbf4cfc esp32/boards: Enable BLE by default when building with IDF 4.x. 2019-10-08 14:50:01 +11:00
Jim Mussared
6a9bd1c1ab esp32: Implement BLE using Nimble from IDF 4.x. 2019-10-08 14:50:01 +11:00
Damien George
917f027c0b esp32: Enable native emitter. 2019-10-05 13:45:25 +10:00
Jim Mussared
c33a4cc213 esp32/Makefile: Fix printing of supported git hash. 2019-09-20 14:37:53 +10:00
Jim Mussared
62d78e231c esp32/main: Use both 3.3 and 4.0 config vars to enable SPIRAM. 2019-09-18 15:49:45 +10:00
Jim Mussared
f469634c0c esp32: Add check to Makefile that the toolchain is in PATH. 2019-09-17 12:26:47 +10:00
Jim Mussared
970f798ea9 esp32: Add check to Makefile for pyparsing version. 2019-09-17 12:26:42 +10:00
Jim Mussared
96008ff59a esp32: Support building with ESP IDF 4.0-beta1.
This commit adds support for a second supported hash (currently set to the
4.0-beta1 tag).  When this hash is detected, the relevant changes are
applied.

This allows to start using v4 features (e.g. BLE with Nimble), and also
start doing testing, while still supporting the original, stable, v3.3 IDF.

Note: this feature is experimental, not well tested, and network.LAN and
network.PPP are currently unsupported.
2019-09-17 12:25:36 +10:00
Damien George
356a728bd0 esp32/Makefile: Add SDKCONFIG_H to QSTR_GLOBAL_REQUIREMENTS.
Fixes issue #5091.
2019-09-12 18:16:16 +10:00
Damien George
bd1d27f00f esp32/modules/inisetup.py: Use bdev.ioctl instead of bdev.SEC_SIZE.
Since the bdev is now a Partition it doesn't have SEC_SIZE.
2019-09-10 22:41:50 +10:00
Alex Albino
80d37d936c esp32: Add support for ESP32-D2WD with 2MiB internal flash.
This patch adds a partitions file for the D2WD and a new board GENERIC_D2WD
which runs on these chip variants.

Resolves issue #4986.
2019-09-10 15:22:16 +10:00
Damien George
31de44775c esp32: Add VFS FAT partition to partitions.csv and mount it as the FS.
This patch uses the newly-added esp32.Partition class to replace the
existing FlashBdev class.  Partition objects implement the block protocol
so can be directly mounted via uos.mount().  This has the following
benefits:

- allows the filesystem partition location and size to be specified in
  partitions.csv, and overridden by a particular board
- very easily allows to have multiple filesystems by simply adding extra
  entries to partitions.csv
- improves efficiency/speed of filesystem operations because the block
  device is implemented fully in C
- opens the possibility to have encrypted flash storage (since Partitions
  can be encrypted)

Note that this patch is fully backwards compatible: existing filesystems
remain untouched and work with this new code.
2019-09-10 15:14:13 +10:00
Damien George
e9af6f5f88 esp32/boards/TINYPICO: Switch to use QIO and 80MHz for SPI interface. 2019-09-10 11:10:19 +10:00
Braden Mars
5641aa55dd esp32: Update to use ESP IDF v3.3
Includes patches for CVE-2019-12586 & CVE-2019-12587
2019-09-07 01:28:11 -05:00
Damien George
983283a8cd esp32/machine_adc: Add ADC.read_u16() method. 2019-09-05 22:13:04 +10:00
Jim Mussared
50482cdc0c esp32/Makefile: Fix subst->patsubst in ESPIDF_BOOTLOADER_SUPPORT_O. 2019-09-03 23:21:50 +10:00
Eric Poulsen
5635b96461 esp32: Add 'config' function to network.LAN, reusing network.WLAN. 2019-08-28 13:11:48 +10:00
Damien George
05eb897d06 esp32: Add esp32.Partition class to expose partition and OTA funcs.
Partitions are exposed as a standard MicroPython block device.
2019-08-20 16:49:18 +10:00
stijn
af5c998f37 py/modmath: Implement math.isclose() for non-complex numbers.
As per PEP 485, this function appeared in for Python 3.5.  Configured via
MICROPY_PY_MATH_ISCLOSE which is disabled by default, but enabled for the
ports which already have MICROPY_PY_MATH_SPECIAL_FUNCTIONS enabled.
2019-08-17 23:23:17 +10:00
Jim Mussared
8db517f26d esp32: Add per-board configs, following other ports.
Replaces the `SDKCONFIG` makefile variable with `BOARD`.  Defaults to
BOARD=GENERIC.  spiram can be enabled with `BOARD=GENERIC_SPIRAM`

Add example definition for TINYPICO, currently identical to GENERIC_SPIRAM
but with custom board/SoC names for the uPy banner.
2019-08-16 00:22:29 +10:00
Damien George
baeebc557c esp32/modules: On initial setup mount internal flash at root.
Like it's done on normal boot up.  Fixes issue #5004.
2019-08-15 22:03:09 +10:00
Damien George
2ccf030fd1 esp32: Add support for mDNS queries and responder.
They are both enabled by default, but can be disabled by defining
MICROPY_HW_ENABLE_MDNS_QUERIES and/or MICROPY_HW_ENABLE_MDNS_RESPONDER to
0.  The hostname for the responder is currently taken from
tcpip_adapter_get_hostname() but should eventually be configurable.
2019-08-15 16:36:47 +10:00
Kenta IDA
b6906fa573 esp32/network_ppp: Add authentication support to the PPP interface.
This commit adds the connect() method to the PPP interface and requires
that connect() be called after active(1).  This is a breaking change for
the PPP API.

With the connect() method it's now possible to pass in authentication
information for PAP/CHAP, eg:

    ppp.active(1)
    ppp.connect(authmode=ppp.AUTH_PAP, username="user", "password="password")

If no authentication is needed simply call connect() without any
parameters.  This will get the original behaviour of calling active(1).
2019-08-14 17:20:58 +10:00
Damien George
7c15e50eb8 esp32/Makefile: Include CFLAGS_EXTRA in CFLAGS definition.
Following other ports, so builds can be customised more easily, eg on the
command line building with a user C-module.
2019-07-30 17:31:23 +10:00
Amir Gonnen
995f9cfdfc esp32: Pin MicroPython tasks to a specific core.
On this port the GIL is enabled and everything works under the assumption
of the GIL, ie that a given task has exclusive access to the uPy state, and
any ISRs interrupt the current task and therefore the ISR inherits
exclusive access to the uPy state for the duration of its execution.

If the MicroPython tasks are not pinned to a specific core then an ISR may
be executed on a different core to the task, making it possible for the
main task and an ISR to execute in parallel, breaking the assumption of the
GIL.

The easiest and safest fix for this is to pin all MicroPython related code
to the same CPU core, as done by this patch.  Then any ISR that accesses
MicroPython state must be registered from a MicroPython task, to ensure it
is invoked on the same core.

See issue #4895.
2019-07-25 15:33:47 +10:00
Damien George
e3e7e3a781 esp32/Makefile: Simplify include of IDF source by using wildcards. 2019-07-20 14:07:18 +10:00
Damien George
b88e51d718 esp32/Makefile: Put OBJ and LIB rule additions in gen_espidf_lib_rule. 2019-07-20 13:04:55 +10:00
Jim Mussared
331c224e07 esp32/Makefile: Fix path expansion for ESPIDF_DRIVER_O.
It was using subst to s/.c/.o/ which changed .c anywhere in the path.
2019-07-20 12:32:43 +10:00
Damien George
a29334761d esp32: Add support for hardware I2C. 2019-07-19 16:31:25 +10:00
Eric Poulsen
fa5c0b819c esp32/network_ppp: Add ppp_set_usepeerdns(pcb, 1) when init'ing iface.
Without this you often don't get any DNS server from your network provider.
Additionally, setting your own DNS _does not work_ without this option set
(which could be a bug in the PPP stack).
2019-07-04 11:17:41 +10:00
Damien George
c80614dfc8 ports: Provide mp_hal_stdio_poll for sys.stdio polling where needed. 2019-07-01 17:10:12 +10:00
Josh Lloyd
2f262d5f9a esp32/Makefile: Include all driver/*.c source files in the build.
Fixes #4869.
2019-06-25 15:12:34 +10:00
Damien George
b80bccccff esp32/modnetwork: Still try to reconnect to WLAN even with AUTH_FAIL.
WIFI_REASON_AUTH_FAIL does not necessarily mean the password is wrong, and
a wrong password may not lead to a WIFI_REASON_AUTH_FAIL error code.  So to
improve reliability connecting to a WLAN always reconnect regardless of the
error.
2019-06-22 21:50:49 +10:00
Damien George
3ee3995be1 esp32: Update to use ESP IDF v3.3-beta3.
This updates ESP IDF to use v3.3-beta3.  And also adjusts README.md to
point to stable docs which provide a link to download the correct toolchain
for this IDF version, namely 1.22.0-80-g6c4433a-5.2.0
2019-06-19 14:32:15 +10:00
Nicko van Someren
1a51fc9ddf esp32/machine_sdcard: Fix bug in SPI slot number selection.
And fix minor typo in docs when referring to SDCard class.
2019-06-17 12:36:22 +10:00
Nicko van Someren
8e3af7d4c8 esp32: Add machine.SDCard class using built-in HW SD/MMC controller.
This adds support for SD cards using the ESP32's built-in hardware SD/MMC
host controller, over either the SDIO bus or SPI.  The class is available
as machine.SDCard and using it can be as simple as:

    uos.mount(machine.SDCard(), '/sd')
2019-06-03 00:37:41 +10:00
Martin Dybdal
de76f73d34 esp32/machine_timer: Reuse Timer handles, deallocate only on soft-reset.
The patch solves the problem where multiple Timer objects (e.g. multiple
Timer(0) instances) could initialise multiple handles to the same internal
timer.  The list of timers is now maintained not for "active" timers (where
init is called), but for all timers created.  The timers are only removed
from the list of timers on soft-reset (machine_timer_deinit_all).

Fixes #4078.
2019-05-31 14:55:07 +10:00
Damien George
883e987b90 esp32/modsocket: Raise EAGAIN when accept fails in non-blocking mode.
EAGAIN should be for pure non-blocking mode and ETIMEDOUT for when there is
a finite (but non-zero) timeout enabled.
2019-05-28 17:43:00 +10:00
Tom Manning
887a6712c2 esp32/machine_touchpad: Use HW timer for FSM to enable wake-on-touch. 2019-05-28 11:14:34 +10:00
Damien George
0557f0b74b esp32/network_ppp: Add a timeout for closing PPP connection.
This also fixes deleting the PPP task, since eTaskGetState() never returns
eDeleted.

A limitation with this patch: once the PPP is deactivated (ppp.active(0))
it cannot be used again. A new PPP instance must be created instead.
2019-05-17 17:14:45 +10:00
Damien George
2630d3e51f esp32/machine_uart: Implement UART.deinit() method. 2019-05-15 17:01:54 +10:00
Damien George
8586afa6f5 esp32/modnetwork: Change type to size_t for uses of mp_obj_str_get_data. 2019-05-13 12:39:03 +10:00
Krono
fbd4e61e57 esp32/machine_wdt: Add timeout arg to select interval, make WDT panic.
The machine.WDT() now accepts the "timeout" keyword argument to select the
WDT interval.  And the WDT is changed to panic mode which means it will
reset the device if the interval expires (instead of just printing an error
message).
2019-04-30 16:53:05 +10:00
Damien George
0646e607b5 ports: Convert to use pyexec_file_if_exists() to execute boot/main.py.
The stm32 and nrf ports already had the behaviour that they would first
check if the script exists before executing it, and this patch makes all
other ports work the same way.  This helps when developing apps because
it's hard to tell (when unconditionally trying to execute the scripts) if
the resulting OSError at boot up comes from missing boot.py or main.py, or
from some other error.  And it's not really an error if these scripts don't
exist.
2019-04-26 15:22:14 +10:00
Damien George
4ce0091449 esp32/README: Add info about pyparsing and the correct Python version.
See issue #4655.
2019-04-18 14:17:01 +10:00
Damien George
69cb24a21d esp32/boards/sdkconfig: Disable WDT check of idle task on CPU1.
With dual-core enabled it's possible that the uPy task has full utilisation
of CPU1.  Fixes issue #4673.
2019-04-05 12:25:21 +11:00
Damien George
92149c8a79 esp32/boards: Enable dual core support by default.
Single core is still supported, just by adding CONFIG_FREERTOS_UNICORE=y to
a custom sdkconfig file.
2019-03-27 11:20:21 +11:00
Damien George
815b79a8d0 esp32/mpthreadport: Exit vPortCleanUpTCB early if threading not init'd. 2019-03-27 11:11:06 +11:00
Damien George
673db939b5 esp32/machine_pin: Rework pull mode config to fix GPIO hold feature.
For gpio_hold_en() to work properly (not draw additional current) pull
up/down must be disabled when hold is enabled.  This patch makes sure this
is the case by reworking the pull constants to be a bit mask.
2019-03-26 15:21:23 +11:00
Damien George
ddc934631c esp32/machine_pin: Add new PULL_HOLD pin pull mode. 2019-03-14 07:28:57 +11:00
Damien George
349b54525e esp32/machine_pin: Make it so None as pull value disables pull up/down.
Previously specifying None as the pull value would leave the pull up/down
state unchanged.  This change makes it so -1 leaves the state unchanged and
None makes the pin float, as per the docs.
2019-03-14 07:26:59 +11:00
Damien George
297092a76a esp32/mphalport: Use ets_delay_us for mp_hal_delay_us_fast.
The system provided one is in ROM and is more accurate.
2019-03-12 15:46:44 +11:00
Damien George
fcace26d87 esp32/Makefile: Add some missing IDF source files to bootloader and app.
Functions in these files may be needed when certain features are enabled
(eg dual core mode), even if the linker does not give a warning or error
about unresolved symbols.
2019-03-11 23:17:09 +11:00
Petr Kracík
41e7ad647e esp32/modnetwork: Remove redundant esp_log include. 2019-03-08 23:36:07 +11:00
Petr Kracík
73c48b1b45 esp32/modnetwork: Implement RSSI for WiFi STA via WLAN.status('rssi'). 2019-03-08 23:35:28 +11:00
Damien George
b5f33ac2cb ports: Update to work with new oofatfs version. 2019-03-05 15:56:39 +11:00
Petr Kracík
21f9329d5d esp32/modnetwork: Fix wifi.isconnected to return False after disconnect.
esp_wifi_connect will return ESP_OK for the normal path of execution which
just means the reconnect is started, not that it is actually reconnected.
In such a case wifi.isconnected() should return False until the
reconnection is complete.  After reconnect a GOT_IP event is called and it
will change wifi_sta_connected back to True.
2019-02-26 00:49:40 +11:00
Petr Kracík
5801a003f0 esp32/network_lan: Make power arg to constructor optional.
A value of None for this argument is already supported, so the argument can
be made optional.
2019-02-21 23:29:10 +11:00
Petr Kracík
01c1432e32 esp32/modnetwork: Catch and report Ethernet events. 2019-02-21 23:28:51 +11:00
Petr Kracík
7d8c71c222 esp32/network_lan: Add arg to constructor to set clock mode for ETH PHY.
This optional parameter for network.LAN clock_mode can be used for cases
where the clock source is different from the default GPIO0.  Fixes #4502.
2019-02-21 23:28:17 +11:00
Damien George
303f27f656 esp32/modsocket: Change socket.socket to be socket type rather than fun.
To make all ports consistent.  Addresses issue #4514.
2019-02-18 23:20:13 +11:00
Damien George
ed09e13943 esp32/modsocket: Fix usocket.send to accept anything with buffer proto. 2019-02-18 12:38:38 +11:00
Yonatan Goldschmidt
bc4f8b438b extmod/moduwebsocket: Refactor websocket to uwebsocket.
As mentioned in #4450, `websocket` was experimental with a single intended
user, `webrepl`. Therefore, we'll make this change without a weak
link `websocket` -> `uwebsocket`.
2019-02-14 00:35:45 +11:00
Mike Causer
812969d615 all: Change PYB message prefix to MPY.
Replaces "PYB: soft reboot" with "MPY: soft reboot", etc.

Having a consistent prefix across ports reduces the difference between
ports, which is a general goal.  And this change won't break pyboard.py
because that tool only looks for "soft reboot".
2019-02-12 15:18:33 +11:00
Damien George
6e30f96b0b ports: Convert legacy uppercase macro names to lowercase. 2019-02-12 14:54:51 +11:00
Damien George
c33f538066 esp32/modmachine: Add support for changing the CPU frequency. 2019-02-07 22:51:55 +11:00
Damien George
6a95e74387 esp32: Use SPIRAM in mem-map mode so all of it can be used for uPy heap.
Also enable CONFIG_SPIRAM_IGNORE_NOTFOUND to allow boards with faulty or
missing SPIRAM to still boot.
2019-02-06 00:10:50 +11:00
Damien George
8de17b3d96 esp32/modmachine: Rename machine.sleep to machine.lightsleep.
While keeping machine.sleep as an alias for machine.lightsleep for
backwards compatibility.
2019-01-30 13:00:26 +11:00
Damien George
dadee5fa24 esp32/modsocket: Fix crashes when connect/bind can't resolve given addr.
Fixes issue #4441.
2019-01-30 12:40:50 +11:00
Damien George
f431795caf esp32/boards: Use auto xtal freq config instead of default 40MHz.
Auto-detection of the crystal frequency is convenient and allows for a
single binary for many different boards.  But it can be unreliable in
certain situations so in production, for a given board, it's recommended to
configure the correct fixed frequency.
2019-01-28 20:42:12 +11:00
Damien George
5d88272342 esp32/Makefile: Make sure that directory exists for sdkconfig.h. 2019-01-28 20:41:13 +11:00
Damien George
9ac9aa989c esp32/machine_timer: Deinit all active timers on soft reset.
Otherwise they will keep triggering the callback and access invalid data on
the heap.
2019-01-28 16:16:03 +11:00
Damien George
3d49b157b8 esp32: Update to latest ESP IDF using sdkconfig and new ldgen procedure.
Configuration for the build is now specified using sdkconfig rather than
sdkconfig.h, which allows for much easier configuration with defaults from
the ESP IDF automatically applied.  sdkconfig.h is generated using the new
ESP IDF kconfig_new tool written in Python.  Custom configuration for a
particular ESP32 board can be specified via the make variable SDKCONFIG.

The esp32.common.ld file is also now generated using the standard ESP IDF
ldgen.py tool.
2019-01-28 12:44:03 +11:00
Damien George
f59904f799 esp32/Makefile: Put all IDF compenents in .a libs to use IDF ld script.
When the ESP IDF builds a project it puts all separate components into
separate .a library archives.  And then the esp32.common.ld linker script
references these .a libraries by explicit name to put certain object files
in iRAM.

This patch does a similar thing for the custom build system used here,
putting all IDF .o's into their respective .a.  So a custom linker script
is no longer needed.
2019-01-28 12:41:37 +11:00
Damien George
e7ab475276 esp32: Don't put py/scheduler.o in iRAM, it's no longer needed.
ISR's no longer need to be in iRAM, and the ESP IDF provides an option to
specify that they are in iRAM if an application needs lower latency when
handling them.  But we don't use this feature for user interrupts: both
timer and gpio ISR routines are registered without the ESP_INTR_FLAG_IRAM
option, and so the scheduling code no longer needs to be in iRAM.
2019-01-27 16:15:47 +11:00
Damien George
da72bb6833 esp32/machine_hw_spi: Make HW SPI objects statically allocated.
This aligns more closely with the hardware, that there are two, fixed HW
SPI peripherals.  And it allows to recreate the HW SPI objects without
error, as well as create them again after a soft reset.

Fixes issue #4103.
2019-01-23 23:47:36 +11:00
Damien George
d82f344f61 esp32/machine_hw_spi: Use separate DMA channels for HSPI and VSPI.
Otherwise only one of HSPI or VSPI can be used at a time.  Fixes
issue #4068.
2019-01-23 23:40:06 +11:00
Matt Trentini
cd52d2c691 esp32/modules/neopixel.py: Change NeoPixel to different default timings.
In order to suit the more common 800KHz by default (instead of 400KHz), and
also have the same behaviour as the esp8266 port.

Resolves #4396.

Note! This is a breaking change. Anyone that has previously used the
NeoPixel class on an ESP32 board may be affected.
2019-01-23 14:22:38 +11:00
Damien George
eb446ec227 esp32/Makefile: Use system provided math library rather than uPy one.
The ESP IDF system already provides a math library, and that one is likely
to be better tuned to the Xtensa architecture.  The IDF components are also
tested against its own math library, so best not to override it.  Using the
system provided library also allows to easily switch to double-precision
floating point by changing MICROPY_FLOAT_IMPL to MICROPY_FLOAT_IMPL_DOUBLE.
2019-01-17 16:43:20 +11:00
Damien George
90f86a0197 esp32/machine_pin: Add Pin.off() and Pin.on() methods. 2019-01-16 17:33:56 +11:00
Damien George
f350b640a0 esp32/modsocket: For socket read only release GIL if socket would block.
If there are many short reads to a socket in a row (eg by readline) then
releasing and acquiring the GIL each time will give very poor throughput.
So first poll the socket to see if it has data, and if it does then don't
release the GIL.
2019-01-10 15:46:44 +11:00
Damien George
efe0569c26 esp32/mphalport: When tx'ing to REPL only release GIL if many chars sent
Otherwise, if multiple threads are active, printing data to the REPL may be
very slow because in some cases only one character is output per call to
mp_hal_stdout_tx_strn.
2019-01-10 15:43:47 +11:00
Damien George
da7355e213 esp32/modmachine: Enable machine.sleep() now that the IDF supports it. 2018-12-06 17:23:27 +11:00
Damien George
9c6c32cc51 esp32/machine_pwm: On deinit stop routing PWM signal to the pin.
Fixes issue #4273.
2018-12-06 17:05:16 +11:00
Damien George
287b02d98a esp32/machine_pwm: Support higher PWM freq by auto-scaling timer res. 2018-12-06 16:43:39 +11:00
Damien George
87623082e3 esp32/machine_uart: Implement UART.sendbreak() method.
The uart_write_bytes_with_break() function requires non-zero data to be
sent before the break, so a standalone break must be synthesised.
2018-12-06 15:40:22 +11:00
Damien George
9ddc182ec7 esp32/machine_uart: Add txbuf/rxbuf keyword args to UART construct/init.
As per the machine.UART documentation, these are used to set the length of
the TX and RX buffers.
2018-12-05 16:48:34 +11:00
Damien George
485514f57a esp32: Allocate task TCB and stack from system heap not uPy heap.
This is necessary for two reasons: 1) FreeRTOS still needs the TCB data
structure even after vPortCleanUpTCB has been called, so this latter hook
function cannot free the TCB, and there is no where else to safely delete
it (this behaviour has changed recently in the ESP IDF); 2) when using
external SPI RAM the uPy heap is in this external memory but the task stack
must be allocated from internal SRAM.

Fixes issue #3904.
2018-11-28 15:00:45 +11:00
Damien George
0233049b79 esp32/mpthreadport: Prevent deadlocks when deleting all threads.
vTaskDelete now immediately calls vPortCleanUpTCB, which requires the
thread_mutex mutex, so vTaskDelete must be called after this mutex is
released.
2018-11-28 14:30:11 +11:00
Eric Poulsen
3c6f639aa5 esp32/network_ppp: Add PPPoS functionality.
This commit adds network.PPP(stream) which allows to create a TCP/IP
network interface over a stream object (eg a UART).
2018-10-19 23:32:02 +11:00
Eric Poulsen
5e5aef53fb esp32/modesp32: Add hall_sensor() function. 2018-10-19 17:28:02 +11:00
Damien George
185716514f esp32/machine_rtc: Fix locals dict entry, init qstr points to init meth. 2018-09-20 17:52:16 +10:00
Siarhei Farbotka
e62f59217b esp32: Fix int overflow in machine.sleep/deepsleep functions. 2018-09-14 13:25:45 +10:00
Damien George
48d736f491 esp32: Update to latest ESP IDF.
Among other things, this requires putting bootloader object files in to
their relevant .a archive, so that they can be correctly referenced by the
ESP IDF's linker script.
2018-08-14 16:45:37 +10:00
Eric Poulsen
419eb86074 esp32/modnetwork: Add network.(W)LAN.ifconfig('dhcp') support. 2018-07-18 11:02:11 +10:00
Nicko van Someren
c3c914f4dd esp8266,esp32: Implement high-res timers using new tick_hz argument.
machine.Timer now takes a new argument in its constructor (or init method):
tick_hz which specified the units for the period argument.  The period of
the timer in seconds is: period/tick_hz.

For backwards compatibility tick_hz defaults to 1000.  If the user wants to
specify the period (numerator) in microseconds then tick_hz can be set to
1000000.  The user can also specify a period of an arbitrary number of
cycles of an arbitrary frequency using these two arguments.

An additional freq argument has been added to allow frequencies to be
specified directly in Hertz.  This supports floating point values when
available.
2018-07-17 13:17:23 +10:00
Damien George
a3ba5f127e esp32/modesp32: Use MP_ROM_QSTR and MP_ROM_PTR in const locals dict. 2018-07-16 00:02:35 +10:00
Jérôme Poulin
4f5b435d9b esp32/modesp32: Add raw temperature reading to esp32 module.
Using direct register control as specified by ESP-IDF in
components/esp32/test/test_tsens.c.  Temperature doesn't represent any
particular unit, isn't calibrated and will vary from device to device.
2018-07-16 00:02:26 +10:00
Mitchell Currie
385fa51806 esp32: Implement WLAN.status() return codes.
Resolves #3913: missing esp32 status() implementation.
2018-07-14 16:26:43 +10:00
Damien George
9c8141f07e esp32/modnetwork: Add support for bssid parameter in WLAN.connect(). 2018-07-09 14:01:52 +10:00
Nicko van Someren
14ab81e87a esp32: Reduce latency for handling of scheduled Python callbacks.
Prior to this patch there was a large latency for executing scheduled
callbacks when when Python code is sleeping: at the heart of the
implementation of sleep_ms() is a call to vTaskDelay(1), which always
sleeps for one 100Hz tick, before performing another call to
MICROPY_EVENT_POLL_HOOK.

This patch fixes this issue by using FreeRTOS Task Notifications to signal
the main thread that a new callback is pending.
2018-07-04 10:49:37 +10:00
Damien George
349d8e1324 esp32: Allow to build with uPy floats disabled. 2018-07-03 12:10:03 +10:00
Damien George
8f86fbfd6c ports: Enable ure.sub() on stm32, esp8266 (not 512k) and esp32. 2018-07-02 15:13:18 +10:00
Damien George
82bc4838d2 esp32/mpconfigport.h: Enable ucryptolib module. 2018-06-27 16:44:59 +10:00
Damien George
34b2f6b6fc esp32/modules: Include umqtt library in frozen modules. 2018-06-15 16:39:49 +10:00
Damien George
d61d119c94 esp32: Update to latest ESP IDF. 2018-06-15 16:23:53 +10:00
Damien George
cf1509c911 esp32/fatfs_port: Implement get_fattime so FAT files have a timestamp.
Fixes issue #3859.
2018-06-13 14:13:34 +10:00
Damien George
0501427907 esp32: Remove port-specific uhashlib implementation and use common one.
Now that the common module has mbedtls support for both SHA1 and SHA256 it
can now be used on this port.
2018-06-12 13:50:11 +10:00
Damien George
565f590586 ports: Enable IOBase on unix, stm32, esp8266 and esp32.
It's a core feature, in particular required for user-streams with uasyncio.
2018-06-12 12:29:26 +10:00
Damien George
b2fa1b50ed ports: Call gc_sweep_all() when doing a soft reset.
This calls finalisers of things like files and sockets to cleanly close
them.
2018-06-12 11:56:25 +10:00
Glenn Moloney
039f196c56 esp32/modnetwork: Fix isconnected() when using static IP config.
Currently <WLAN>.isconnected() always returns True if a static IP is set,
regardless of the state of the connection.

This patch introduces a new flag 'wifi_sta_connected' which is set in
event_handler() when GOT_IP event is received and reset when DISCONNECTED
event is received (unless re-connect is successful).  isconnected() now
simply returns the status of this flag (for STA_IF).

The pre-existing flag misleadingly named 'wifi_sta_connected" is also
renamed to 'wifi_sta_connect_requested'.

Fixes issue #3837
2018-06-08 13:13:21 +10:00
Damien George
93150a0d40 ports: Enable descriptors on stm32, esp8266, esp32 ports.
They are now efficient (in runtime performance) and provide a useful
feature that's hard to obtain without them enabled.

See issue #3644 and PR #3826 for background.
2018-06-08 12:23:08 +10:00
Damien George
f35aae366c extmod/vfs_fat: Rename FileIO/TextIO types to mp_type_vfs_fat_XXX.
So they don't clash with other VFS implementations.
2018-06-06 14:28:23 +10:00
Damien George
a90124a9e2 esp32: Add support for building with external SPI RAM.
This patch adds support for building the firmware with external SPI RAM
enabled.  It is disabled by default because it adds overhead (due to
silicon workarounds) and reduces performance (because it's slower to have
bytecode and objects stored in external RAM).

To enable it, either use "make CONFIG_SPIRAM_SUPPORT=1", or add this line
to you custom makefile/GNUmakefile (before "include Makefile"):

    CONFIG_SPIRAM_SUPPORT = 1

When this option is enabled the MicroPython heap is automatically allocated
in external SPI RAM.

Thanks to Angus Gratton for help with the compiler and linker settings.
2018-06-05 13:57:59 +10:00
Angus Gratton
bc92206f89 esp32/Makefile: Extract common C & C++ flags for consistent compilation. 2018-06-05 13:05:12 +10:00
Nick Moore
ef4c8e6e97 esp32: Silence ESP-IDF log messages when in raw REPL mode.
This prevents clients such as ampy, mpy-utils, etc getting confused by
extraneous data.
2018-05-28 20:15:08 +10:00
Damien George
df9b7e8f24 esp32/esp32.custom_common.ld: Put soc code in iram0.
This is what the IDF does, it must be done.
2018-05-23 12:57:50 +10:00
Damien George
20b4b85f72 ports: Enable MICROPY_PY_BUILTINS_ROUND_INT on selected ports. 2018-05-22 14:18:16 +10:00
Damien George
2923671a0c esp32/Makefile: Update to latest ESP IDF version. 2018-05-21 11:28:36 +10:00
Damien George
cdaace1fdf esp32/modnetwork: Fix STA/AP activate/deactivate for new IDF API.
WIFI_MODE_NULL is no longer supported by the ESP IDF, instead one must use
esp_wifi_start/esp_wifi_stop.
2018-05-15 11:50:37 +10:00
Bas Wijnen
67e1a4f8be esp32: Update to latest ESP IDF version.
- Updated supported git hash to current IDF version.
- Added missing targets and includes to Makefile.
- Updated error codes for networking module.
- Added required constant to sdkconfig configuration.
2018-05-14 11:42:46 +10:00
Damien George
12a3fccc7e esp32/modsocket: Check for pending events during blocking socket calls. 2018-05-03 00:09:25 +10:00
Damien George
4fa7d36cee esp32: Use mp_rom_map_elem_t and MP_ROM_xxx macros for const dicts. 2018-05-02 22:33:41 +10:00
Damien George
6681eb809a esp32/modsocket: Correctly handle reading from a peer-closed socket.
If a socket is cleanly shut down by the peer then reads on this socket
should continue to return zero bytes.  The lwIP socket API does not have
this behaviour (it only returns zero once, then blocks on subsequent calls)
so this patch adds explicit checks and logic for peer closed sockets.
2018-05-02 22:31:00 +10:00
Torwag
fb7dabb971 esp32/README: Add --init to submodule update command.
Add --init to the submodule update example, thus, all submodules get
initialised including the nested (--recursive) ones.  Without it there
might not be a submodule init.
2018-05-02 17:24:17 +10:00
Damien George
777e042ab5 esp32/modnetwork: Allow to get ESSID of AP that STA is connected to.
Following the same addition to esp8266 port.
2018-05-01 16:37:08 +10:00
Andreas Valder
298c072433 esp32: Add support for the esp32's ULP.
The ULP is available as esp32.ULP().  See README.ulp.md for basic usage.
2018-05-01 16:19:37 +10:00
Damien George
23e9c3bca7 esp32/modules: Add support scripts for WebREPL.
WebREPL now works on the esp32 in the same way it does on esp8266.
2018-04-27 23:58:51 +10:00
Damien George
c1d4352e65 esp32/mpconfigport: Enable webrepl module and socket events. 2018-04-27 23:57:57 +10:00
Damien George
999c8b9711 esp32/modsocket: Add support for registering socket event callbacks.
The esp8266 uses modlwip.c for its usocket implementation, which allows to
easily support callbacks on socket events (like when a socket becomes ready
for reading).  This is not as easy to do for the esp32 which uses the
ESP-IDF-provided lwIP POSIX socket API.  Socket events are needed to get
WebREPL working, and this patch provides a way for such events to work by
explicitly polling registered sockets for readability, and then calling the
associated callback if the socket is readable.
2018-04-27 23:57:26 +10:00
Damien George
98b05e3614 esp32: Add support for and enable uos.dupterm(). 2018-04-27 23:51:45 +10:00
Damien George
04dc4a5034 esp32/mphalport: Improve mp_hal_stdout_tx_XXX functions.
This makes way for enabling uos.dupterm().
2018-04-27 23:49:21 +10:00
Damien George
4ed5865280 esp32/mphalport: Improve mp_hal_delay_us so it handles pending events.
Thanks to @bboser for the initial idea and implementation.
2018-04-26 20:21:33 +10:00
Damien George
e1fe3abd09 esp32/mphalport: Use esp_timer_get_time instead of gettimeofday.
It's more efficient and improves accuracy.
2018-04-26 20:19:31 +10:00
Shanee Vanstone
b5ee3b2f21 esp32/README.md: Fix typo readme. 2018-04-20 16:23:55 +10:00
Damien George
4ff05ae4e9 esp32/machine_uart: Remove UART event queue object.
This event queue has UART events posted to it and they need to be drained
for it to operate without error.  The queue is not used by the uPy UART
class so it should be removed to prevent the IDF emitting errors.

Fixes #3704.
2018-04-10 15:24:10 +10:00
Damien George
cf31d384f1 py/stream: Switch stream close operation from method to ioctl.
This patch moves the implementation of stream closure from a dedicated
method to the ioctl of the stream protocol, for each type that implements
closing.  The benefits of this are:

1. Rounds out the stream ioctl function, which already includes flush,
   seek and poll (among other things).

2. Makes calling mp_stream_close() on an object slightly more efficient
   because it now no longer needs to lookup the close method and call it,
   rather it just delegates straight to the ioctl function (if it exists).

3. Reduces code size and allows future types that implement the stream
   protocol to be smaller because they don't need a dedicated close method.

Code size reduction is around 200 bytes smaller for x86 archs and around
30 bytes smaller for the bare-metal archs.
2018-04-10 13:41:32 +10:00
Damien George
34e224a4af esp32/machine_uart: Return None from UART read if no data is available.
This is instead of returning an empty bytes object, and matches how other
ports handle non-blocking UART read behaviour.
2018-03-14 13:18:43 +11:00
Damien George
58ebeca6a9 drivers/bus: Pull out software SPI implementation to dedicated driver.
This patch takes the software SPI implementation from extmod/machine_spi.c
and moves it to a dedicated file in drivers/bus/softspi.c.  This allows the
SPI driver to be used independently of the uPy runtime, making it a more
general component.
2018-03-10 00:59:43 +11:00
Lee Seong Per
478ce8f7e3 esp32/modnetwork: Implement status('stations') to list STAs in AP mode.
The method returns a list of tuples representing the connected stations.
The first element of the tuple is the MAC address of the station.
2018-03-05 17:59:19 +11:00
Damien George
d4470af239 esp32: Revert "esp32/machine_touchpad: Swap pins 32 and 33."
This reverts commit 5a82ba8e07.

Touch sensor 8 and 9 have a mismatch in some of their registers and this is
now fixed in software by the ESP IDF.
2018-03-05 14:06:45 +11:00
Damien George
82828340a0 ports: Enable ucollections.deque on relevant ports.
These ports are all capable of running uasyncio.
2018-02-21 22:55:13 +11:00
Damien George
cced43feb8 esp32/modsocket: Allow getaddrinfo() to take up to 6 args.
Currently only the first 2 args are used, but this patch should at least
make getaddrinfo() signature-compatible with CPython and other bare-metal
ports that use the lwip bindings.
2018-02-21 19:09:38 +11:00