summaryrefslogtreecommitdiff
path: root/ports/esp8266
AgeCommit message (Collapse)Author
9 dayspy/formatfloat: Improve accuracy of float formatting code.Yoctopuce dev
Following discussions in PR #16666, this commit updates the float formatting code to improve the `repr` reversibility, i.e. the percentage of valid floating point numbers that do parse back to the same number when formatted by `repr` (in CPython it's 100%). This new code offers a choice of 3 float conversion methods, depending on the desired tradeoff between code size and conversion precision: - BASIC method is the smallest code footprint - APPROX method uses an iterative method to approximate the exact representation, which is a bit slower but but does not have a big impact on code size. It provides `repr` reversibility on >99.8% of the cases in double precision, and on >98.5% in single precision (except with REPR_C, where reversibility is 100% as the last two bits are not taken into account). - EXACT method uses higher-precision floats during conversion, which provides perfect results but has a higher impact on code size. It is faster than APPROX method, and faster than the CPython equivalent implementation. It is however not available on all compilers when using FLOAT_IMPL_DOUBLE. Here is the table comparing the impact of the three conversion methods on code footprint on PYBV10 (using single-precision floats) and reversibility rate for both single-precision and double-precision floats. The table includes current situation as a baseline for the comparison: PYBV10 REPR_C FLOAT DOUBLE current = 364688 12.9% 27.6% 37.9% basic = 364812 85.6% 60.5% 85.7% approx = 365080 100.0% 98.5% 99.8% exact = 366408 100.0% 100.0% 100.0% Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-07-25ports: Eliminate define of {U,}INT_FMT where redundant.Jeff Epler
The default definition in `py/mpconfig.h` for 32-bit architectures is `%u/%d`, so these can be removed. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-09shared/timeutils: Standardize supported date range on all platforms.Yoctopuce dev
This is code makes sure that time functions work properly on a reasonable date range, on all platforms, regardless of the epoch. The suggested minimum range is 1970 to 2099. In order to reduce code footprint, code to support far away dates is only enabled specified by the port. New types are defined to identify timestamps. The implementation with the smallest code footprint is when support timerange is limited to 1970-2099 and Epoch is 1970. This makes it possible to use 32 bit unsigned integers for all timestamps. On ARM4F, adding support for dates up to year 3000 adds 460 bytes of code. Supporting dates back to 1600 adds another 44 bytes of code. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-06-13esp8266/modmachine: Use common machine_time_pulse_us implementation.Damien George
Testing shows that for frequencies which the esp8266 can handle -- up to about 1kHz -- `machine.time_pulse_us()` now gives more accurate results. Prior to this commit it would measure on average about 1us lower, but now the average is much closer to the true value. For example a pulse that is 1000us long, it would measure between 998 and 1000us. Now it measures between 999us and 1001us. Signed-off-by: Damien George <damien@micropython.org>
2025-06-04esp8266/main: Print error information on crash-induced reboots.Alessandro Gatti
This commit adds an optional configuration option for the ESP8266 port that, if the board rebooted due to a crash, will print to stdout some information about the error that triggered the issue. It is not possible using regular SDK functions to intercept errors and print information at that stage, and the only error response from the board is to reboot itself. This is the next best thing, print some error information just once at boot time after the crash - the least invasive option given the situation we're in. This is disabled by default, and can be enabled by enabling MICROPY_HW_HARD_FAULT_DEBUG in the port configuration - obviously with a small increase in the firmware code footprint. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-05-13all: Rename the "NORETURN" macro to "MP_NORETURN".Alessandro Gatti
This commit renames the NORETURN macro, indicating to the compiler that a function does not return, into MP_NORETURN to maintain the same naming convention of other similar macros. To maintain compaitiblity with existing code NORETURN is aliased to MP_NORETURN, but it is also deprecated for MicroPython v2. This changeset was created using a similar process to decf8e6a8bb940d5829ca3296790631fcece7b21 ("all: Remove the "STATIC" macro and just use "static" instead."), with no documentation or python scripts to change to reflect the new macro name. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-03-13esp8266: Rename ROMFS partition config variables to include "part0".Damien George
For consistency with the stm32 port. Signed-off-by: Damien George <damien@micropython.org>
2025-03-06esp8266/boards: Add FLASH_2M_ROMFS variant with 320k ROM partition.Damien George
The same as the 2M flash variant but with a 320KiB ROM partition. Signed-off-by: Damien George <damien@micropython.org>
2025-03-06esp8266: Implement vfs.rom_ioctl with support for external flash.Damien George
Not enabled by default on any board. For a board to enable ROMFS it must: - Add `#define MICROPY_VFS_ROM (1)` to its `mpconfigboard.h` file. - Add a FLASH_ROMFS partition to the linker script and expose the partition with: _micropy_hw_romfs_start = ORIGIN(FLASH_ROMFS); _micropy_hw_romfs_size = LENGTH(FLASH_ROMFS); Signed-off-by: Damien George <damien@micropython.org>
2025-03-05esp8266/network_wlan: Allow enumerating connected stations in AP mode.Alessandro Gatti
This commit introduces the ability to obtain a list of stations connected to the device when in soft-AP mode. A new parameter ("stations") to pass to WLAN.status is supported, returning a tuple of (bssid, ipv4) entries, one per connected station. An empty tuple is returned if no stations are connected, and an exception is raised if an error occurred whilst building the python objects to return to the interpreter. Documentation is also updated to cover the new parameter. This fixes #5395. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-02-28esp8266/machine_pin: Implement Pin.toggle() method.robert-hh
Tested with a generic ESP8266 device. The actual output value is taken from the output register, not by reading the pad level. Signed-off-by: robert-hh <robert@hammelrath.com>
2025-02-07esp8266/network_wlan: Make WLAN.config(channel=x) use wifi_set_channel.Glenn Moloney
Also permits channel option to be used for STA_IF interface. This provides compatibility with esp32 code, especially for espnow users. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2025-02-07esp8266/network_wlan: Make WLAN.config('channel') use wifi_get_channel.Glenn Moloney
Prior to this fix, `WLAN.config('channel')` would return an incorrect channel for AP_IF if STA has connected to an external AP running on a different channel. The esp8266 now has the same behaviour as for esp32 per commit 98d1c50159fe9427d72ec358ba0219eaebb1d991. Fixes issue #11463. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2025-01-22esp8266/Makefile: Fix local toolchain builds on recent Linux systems.Alessandro Gatti
This commit fixes compilation for the ESP8266 port when using a local toolchain on relatively recent Linux systems. The documentation asks the user to delete the esptool instance that comes with the toolchain, in favour of using the one provided by the system. On Linux systems that are at least two years old (looking at the CI Ubuntu image as an example), the version of esptool installed with the package manager isn't called `esptool.py` but just `esptool`. The Makefile didn't take that into account and used `esptool.py` without checking if such a command exists, making builds fail. Now preference is given to the `esptool` command, falling back to `esptool.py` only if the former command does not exist or it is not available to the current user, to maintain compatibility with old setups. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-12-06esp8266/mpconfigport: Enable function attributes.Damien George
This allows `unittest` to work on esp8266 boards. Signed-off-by: Damien George <damien@micropython.org>
2024-11-18ports: Make PWM duty_u16 have an upper value of 65535 across all ports.robert-hh
The following ports used 65536 as the upper value (100% duty cycle) and are changed in this commit to use 65535: esp8266, mimxrt, nrf, samd. Tested that output is high at `duty_u16(65535)` and low at `duty_u16(0)`. Also verified that at `duty_u16(32768)` the high and low pulse have the same length. Partially reverts #10850, commits 9c7ad68165bcd224c94ca6d8f172362cf8000d99 and 2ac643c15bec8c88ece0e944ce58f36d02dfd2dd. Signed-off-by: robert-hh <robert@hammelrath.com>
2024-11-08esp8266: Use the recommended network.WLAN.IF_[AP|STA] constants.Angus Gratton
Removes the deprecated network.[AP|STA]_IF form from the esp8266 port This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-05esp32,esp8266: Use new mp_obj_new_str_from_cstr() function.Damien George
These were missed in the previous commit. Signed-off-by: Damien George <damien@micropython.org>
2024-07-04all: Use new mp_obj_new_str_from_cstr() function.Jon Foster
Use new function mp_obj_new_str_from_cstr() where appropriate. It simplifies the code, and makes it smaller too. Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
2024-06-28esp8266: Rework board variant support to require mpconfigvariant file.Damien George
Following how esp32 has been reworked, each variant now has a corresponding `mpconfigvariant_VARIANT.mk` file associated with it. The base variant also has a `mpconfigvariant.mk` file because it has options that none of the other variants use. Signed-off-by: Damien George <damien@micropython.org>
2024-06-04esp8266/network_wlan: Implement network.ipconfig and WLAN.ipconfig.Felix Dörre
Co-authored-by: robert-hh <robert@hammelrath.com> Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-03-28esp8266/network_wlan: Add interface and security WLAN constants.iabdalkader
Following the same change to extmod network interfaces. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-26esp8266/Makefile: Add support for C++ user C modules.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2024-03-16all: Update extmod, ports, examples to build with new berkeley-db lib.Damien George
This provides a MicroPython-specific berkeley-db configuration in extmod/berkeley-db/berkeley_db_config_port.h, and cleans up the include path for this library. Fixes issue #13092. Signed-off-by: Damien George <damien@micropython.org>
2024-03-15extmod/modmachine: Add MICROPY_PY_MACHINE_RESET configuration option.Damien George
Disabled by default, but enabled on all boards that previously had `MICROPY_PY_MACHINE_BARE_METAL_FUNCS` enabled. Signed-off-by: Damien George <damien@micropython.org>
2024-03-07all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton
The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. The original reason for this was to have the option to define it to nothing so that all static functions become global functions and therefore visible to certain debug tools, so one could do function size comparison and other things. This STATIC feature is rarely (if ever) used. And with the use of LTO and heavy inline optimisation, analysing the size of individual functions when they are not static is not a good representation of the size of code when fully optimised. So the macro does not have much use and it's simpler to just remove it. Then you know exactly what it's doing. For example, newcomers don't have to learn what the STATIC macro is and why it exists. Reading the code is also less "loud" with a lowercase static. One other minor point in favour of removing it, is that it stops bugs with `STATIC inline`, which should always be `static inline`. Methodology for this commit was: 1) git ls-files | egrep '\.[ch]$' | \ xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/" 2) Do some manual cleanup in the diff by searching for the word STATIC in comments and changing those back. 3) "git-grep STATIC docs/", manually fixed those cases. 4) "rg -t python STATIC", manually fixed codegen lines that used STATIC. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-07ports: Use vfs module instead of os.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-01-29esp8266/boards/ESP8266_GENERIC: Disable MICROPY_DEBUG_PRINTERS.Damien George
This is not enabled on any other MCU port, and is essentially unused on esp8266 because mp_verbose_flag is always 0. Disabling saves ~7k of flash. Signed-off-by: Damien George <damien@micropython.org>
2023-12-22ports: Fix sys.stdout.buffer.write() return value.Maarten van der Schrieck
MicroPython code may rely on the return value of sys.stdout.buffer.write() to reflect the number of bytes actually written. While in most scenarios a write() operation is successful, there are cases where it fails, leading to data loss. This problem arises because, currently, write() merely returns the number of bytes it was supposed to write, without indication of failure. One scenario where write() might fail, is where USB is used and the receiving end doesn't read quickly enough to empty the receive buffer. In that case, write() on the MicroPython side can timeout, resulting in the loss of data without any indication, a behavior observed notably in communication between a Pi Pico as a client and a Linux host using the ACM driver. A complex issue arises with mp_hal_stdout_tx_strn() when it involves multiple outputs, such as USB, dupterm and hardware UART. The challenge is in handling cases where writing to one output is successful, but another fails, either fully or partially. This patch implements the following solution: mp_hal_stdout_tx_strn() attempts to write len bytes to all of the possible destinations for that data, and returns the minimum successful write length. The implementation of this is complicated by several factors: - multiple outputs may be enabled or disabled at compiled time - multiple outputs may be enabled or disabled at runtime - mp_os_dupterm_tx_strn() is one such output, optionally containing multiple additional outputs - each of these outputs may or may not be able to report success - each of these outputs may or may not be able to report partial writes As a result, there's no single strategy that fits all ports, necessitating unique logic for each instance of mp_hal_stdout_tx_strn(). Note that addressing sys.stdout.write() is more complex due to its data modification process ("cooked" output), and it remains unchanged in this patch. Developers who are concerned about accurate return values from write operations should use sys.stdout.buffer.write(). This patch might disrupt some existing code, but it's also expected to resolve issues, considering that the peculiar return value behavior of sys.stdout.buffer.write() is not well-documented and likely not widely known. Therefore, it's improbable that much existing code relies on the previous behavior. Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
2023-12-18extmod/modos: Factor os.dupterm_notify() function to common extmod code.Damien George
esp8266 doesn't need ets task because the notify is now scheduled (see commits 7d57037906cf0274af08bd2eccbfffabe0ea66e3 and c60caf19951c8326be9c3b6f3b016a4d21f69276 for relevant history). Signed-off-by: Damien George <damien@micropython.org>
2023-12-08ports: Switch build to use common lib/libm list of source files.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-12-08esp8266: Update port to use new event functions.Angus Gratton
This is necessary to avoid watchdog timeout in long i2c.scan(), as previously machine_i2c.c would call MICROPY_EVENT_POLL_HOOK if MICROPY_EVENT_POLL_HOOK_FAST was not available. Compared to previous implementation, this implementation removes the ets_event_poll() function and calls the SDK function ets_loop_iter() from MICROPY_INTERNAL_EVENT_HOOK instead. This allows using the port-agnostic functions in more places. There is a small behaviour change, which is that the event loop gets iterated in a few more places (i.e. anywhere that mp_event_handle_nowait() is called). However, this looks like maybe only modselect.c - and is probably good to process Wi-Fi events in that polling loop. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-07esp8266: Avoid including ep_mphal.h directly.Angus Gratton
This header has no include guards and is apparently only supposed to be included from py/mphal.h. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-01ports: Move definitions of ATOMIC_SECTION macros to mphalport.h.Damien George
Also move MICROPY_PY_PENDSV_ENTER/REENTER/EXIT to mphalport.h, for ports where these are not already there. This helps separate the hardware implementation of these macros from the MicroPython configuration (eg for renesas-ra and stm32, the IRQ static inline helper functions can now be moved to irq.h). Signed-off-by: Damien George <damien@micropython.org>
2023-11-30esp8266/modmachine: Use common implementation of disable/enable_irq.Damien George
Now that the MICROPY_BEGIN_ATOMIC_SECTION/MICROPY_END_ATOMIC_SECTION macros act the same as disable_irq/enable_irq, it's possible to use the common extmod implementation of these machine functions. Signed-off-by: Damien George <damien@micropython.org>
2023-11-30esp8266/esp_mphal: Make atomic section more atomic.Damien George
By disabling ets_loop_iter when the atomic section is active. Signed-off-by: Damien George <damien@micropython.org>
2023-11-30extmod/modmachine: Provide common bindings for 6 bare-metal functions.Damien George
Minor changes for consistency are: - nrf gains: unique_id(), freq() [they do nothing] - samd: deepsleep() now resets after calling lightsleep() - esp32: lightsleep()/deepsleep() no longer take kw arg "sleep", instead it's positional to match others. also, passing 0 here will now do a 0ms sleep instead of acting like nothing was passed. reset_cause() no longer takes any args (before it would just ignore them) - mimxrt: freq() with an argument and lightsleep() both raise NotImplementedError Signed-off-by: Damien George <damien@micropython.org>
2023-11-30extmod/modmachine: Provide common Python bindings for machine.idle().Damien George
And use it in all ports. The ports are unchanged, except esp8266 which now just returns None from this function instead of the time elapsed (to match other ports), and qemu-arm which gains this function. Signed-off-by: Damien George <damien@micropython.org>
2023-11-30extmod/modmachine: Factor ports' machine module dict to common code.Damien George
This is a code factoring to have the dict for the machine module in one location, and all the ports use that same dict. The machine.soft_reset() function implementation is also factored because it's the same for all ports that did already implement it. Eventually more functions/bindings can be factored. All ports remain functionally the same, except: - cc3200 port: gains soft_reset, mem8, mem16, mem32, Signal; loses POWER_ON (which was a legacy constant, replaced long ago by PWRON_RESET) - nrf port: gains Signal - qemu-arm port: gains soft_reset - unix port: gains soft_reset - zephyr port: gains soft_reset, mem8, mem16, mem32 Signed-off-by: Damien George <damien@micropython.org>
2023-11-30esp8266/machine_spi: Rename machine_hspi to machine_spi.Damien George
This renames the type, functions and file to match other ports. Signed-off-by: Damien George <damien@micropython.org>
2023-11-03ports: Remove SRC_QSTR_AUTO_DEPS from all ports' Makefiles.Jim Mussared
It's unused. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-26extmod/modmachine: Consolidate mem, i2c and spi headers to modmachine.h.Damien George
The contents of machine_mem.h, machine_i2c.h and machine_spi.h have been moved into extmod/modmachine.h. Signed-off-by: Damien George <damien@micropython.org>
2023-10-26extmod/modmachine: Consolidate simple machine headers into modmachine.h.Damien George
The contents of machine_bitstream.h, machine_pinbase.h, machine_pulse.h and machine_signal.h have been moved into extmod/modmachine.h. Signed-off-by: Damien George <damien@micropython.org>
2023-10-26extmod/modmachine: Clean up decls of machine types to use common ones.Damien George
The machine_i2c_type, machine_spi_type and machine_timer_type symbols are already declared in extmod/modmachine.h and should not be declared anywhere else. Also move declarations of machine_pin_type and machine_rtc_type to the common header in extmod. Signed-off-by: Damien George <damien@micropython.org>
2023-10-26extmod/machine_uart: Factor ports' UART Python bindings to common code.Damien George
This is a code factoring to have the Python bindings in one location, and all the ports use those same bindings. For all ports except the two listed below there is no functional change. The nrf port has UART.sendbreak() removed, but this method previously did nothing. The zephyr port has the following methods added: - UART.init(): supports setting timeout and timeout_char. - UART.deinit(): does nothing, just returns None. - UART.flush(): raises OSError(EINVAL) because it's not implemented. - UART.any() and UART.txdone(): raise NotImplementedError. Signed-off-by: Damien George <damien@micropython.org>
2023-10-23extmod/machine_adc: Factor ports' ADC Python bindings to common code.Damien George
No functional change, just code factoring to have the Python bindings in one location, and all the ports use those same bindings. Signed-off-by: Damien George <damien@micropython.org>
2023-10-20extmod/machine_pwm: Remove header file and move decls to .c file.Damien George
With public declarations moved to extmod/modmachine.h. It's now mandatory for a port to define MICROPY_PY_MACHINE_PWM_INCLUDEFILE if it enables MICROPY_PY_MACHINE_PWM. This follows how extmod/machine_wdt.c works. All ports have been updated to work with this modified scheme. Signed-off-by: Damien George <damien@micropython.org>
2023-10-20extmod/machine_wdt: Factor ports' WDT Python bindings to common code.Damien George
There are currently 7 ports that implement machine.WDT and a lot of code is duplicated across these implementations. This commit factors the common parts of all these implementations to a single location in extmod/machine_wdt.c. This common code provides the top-level Python bindings (class and method wrappers), and then each port implements the back end specific to that port. With this refactor the ports remain functionally the same except for: - The esp8266 WDT constructor now takes keyword arguments, and accepts the "timeout" argument but raises an exception if it's not the default value (this port doesn't support changing the timeout). - The mimxrt and samd ports now interpret the argument to WDT.timeout_ms() as signed and if it's negative truncate it to the minimum timeout (rather than it being unsigned and a negative value truncating to the maximum timeout). Signed-off-by: Damien George <damien@micropython.org>
2023-10-12py/builtinevex: Handle invalid filenames for execfile.Jim Mussared
If a non-string buffer was passed to execfile, then it would be passed as a non-null-terminated char* to mp_lexer_new_from_file. This changes mp_lexer_new_from_file to take a qstr instead (as in almost all cases a qstr will be created from this input anyway to set the `__file__` attribute on the module). This now makes execfile require a string (not generic buffer) argument, which is probably a good fix to make anyway. Fixes issue #12522. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-12ports: Make all ports skip execution of main.py if boot.py fails.robert-hh
That can be caused e.g. by an exception. This feature is implemented in some way already for the stm32, renesas-ra, mimxrt and samd ports. This commit adds it for the rp2, esp8266, esp32 and nrf ports. No change for the cc3200 and teensy ports. Signed-off-by: robert-hh <robert@hammelrath.com>