Documentation about float - #1
Open
massimosala wants to merge 4166 commits into
Open
Conversation
The `MP_SEEK_xxx` constants are defined in `py/stream.h` exactly for use by `py/stream.c` so that it doesn't depend on the C library. Signed-off-by: Damien George <damien@micropython.org>
Instead of magic numbers + a comment. Signed-off-by: Damien George <damien@micropython.org>
They are no longer needed. Signed-off-by: Damien George <damien@micropython.org>
This helper function is used only by the C stack control functions (in `py/cstack.c` and `py/stackctrl.c`) and not by pystack. Similarly the qstr message is only used by this `mp_raise_recursion_depth()` function. (`mp_raise_recursion_depth()` is also used by the VM in strict stacless mode when pystack is disabled, but for that configuration one should anyway be enabling C stack checking.) Signed-off-by: Damien George <damien@micropython.org>
This variable does nothing in mpy-cross because: - `MICROPY_DEBUG_PRINTERS` is not enabled, so the relevant code in `py/compile.c` that uses `mp_verbose_flag` is unused. - Even if `MICROPY_DEBUG_PRINTERS` was enabled, nothing happens because mpy-cross has `MP_PLAT_PRINT_STRN` defined to do nothing. - `MICROPY_PY_MICROPYTHON_MEM_INFO` is not enabled. So remove it. But keep the `-v` CLI option to not break existing uses of mpy-cross, and keep it compatible with the CLI options of the unix port. Signed-off-by: Damien George <damien@micropython.org>
This stray global variable doesn't really belong in `py/emitglue.c` because it's currently only used by `py/compile.c`. So move it to the state context struct alongside the related compiler settings. Signed-off-by: Damien George <damien@micropython.org>
So ports can support strings if they want to. Signed-off-by: Damien George <damien@micropython.org>
On the stm32 port, `machine.WDT()` now accepts `id=0` and `id="IWDG"` to access the independent watchdog. Signed-off-by: Damien George <damien@micropython.org>
This adds support for the STM32 WWDG peripheral, through the standard `machine.WDT()` class interface. It's accessed as peripheral id "WWDG". The maximum timeout is quite limited on this watchdog due to the limited prescale values, for example: - STM32F4 at 168MHz: 49ms max timeout (at 96MHz it's 87ms max) - STM32F7 at 216MHz: 38ms max timeout - STM32N6 at 800MHz: 167ms max timeout - STM32WB at 64MHz: 524ms max timeout Signed-off-by: Damien George <damien@micropython.org>
Dual-core H7 MCUs have 2x IWDG and 2x WWDG peripherals, and this commit adds support for them all. Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Add documentation for callable Signal objects and their usage. Signed-off-by: Howard Lovatt <howard.lovatt@gmail.com>
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
Previously the default TX/RX pins for each UART were hard-coded in a switch statement, so a board could not change them. This is inconsistent with machine.SPI and machine.I2C, which already take board-level defaults via MICROPY_HW_SPIn_* and MICROPY_HW_I2Cn_*, and with the rp2 and stm32 ports, which already use MICROPY_HW_UARTn_TX/RX. Move the default pins into machine_uart.h as MICROPY_HW_UARTn_TX/RX (and MICROPY_HW_LP_UART0_TX/RX) defines that a board can override in its mpconfigboard.h, and replace the switch with a table indexed by the UART number. The existing default pin values are unchanged, so behaviour is the same for all current boards. In addition: - UART3 and UART4 (e.g. on the ESP32-P4) now get default pins instead of being left uninitialised, and can be assigned from a board. - The LP UART default pins are taken from the IDF (LP_U0TXD_GPIO_NUM / LP_U0RXD_GPIO_NUM), which is correct on all chips (for example 14/15 on the ESP32-P4 rather than 5/4). Signed-off-by: Pavel Revak <pavelrevak@gmail.com>
A bug was exposed by commit 2757acf ("py/nlr: Implement jump callbacks.") which added nlr_call_jump_callbacks() to MP_NLR_JUMP_HEAD. The arm64 backend fixed this in commit b02a5fa ("py/nlraarch64: Fix dangerous use of input register."). Fix powerpc nlr_jump to use r4 as the base register in the asm block, which avoids GCC choosing a register for %0 that will be overwritten. This fixes both the ppc64 and ppc32 nlr_jump variants. Signed-off-by: Joel Stanley <joel@jms.id.au>
nlr_push uses r4 as a scratch register but did not declare it clobbered. GCC was free to place one of the input operands (%0 or %1) in r4. No bug was observed due to this so the fix is for correctness and to guard against future bugs. Signed-off-by: Joel Stanley <joel@jms.id.au>
The linker scripts exclude py/gc.c, py/vm.c and py/parse.c from flash so they execute from faster SRAM, but the EXCLUDE_FILE patterns used a ".obj" suffix whereas CMake names objects "<src>.c.o". The patterns matched nothing, so these files silently ran from XIP flash and the optimisation had no effect. Use the correct ".o" suffix, anchored with "py/" so that "py/gc.c.o" does not also match "py/modgc.c.o". On RP2350 this relocates ~10 KB of .text into SRAM and improves perfbench by ~16% (mean). Signed-off-by: Phil Howard <github@gadgetoid.com>
Signed-off-by: eng33 <eng33@waveshare.com>
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v6...v7) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com>
Bumps [actions/cache](https://github.com/actions/cache) from 5 to 6. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](actions/cache@v5...v6) --- updated-dependencies: - dependency-name: actions/cache dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com>
This commit updates the cache flushing logic for AArch32 targets. Before these changes, when running on Linux the instruction and data caches would be cleared only for AArch32 targets. However, said checks did not trigger properly when running an AArch32 binary on certain AArch64 machines. For example, the Unix port - when built using a 32-bits hard-float toolchain - would work just fine on a Raspberry Pi 3B+ running a 64-bits OS, but the very same binary all of a sudden becomes flaky when handling generated code on a Raspberry Pi 4. These changes aim to generalise cache flushing on Linux, enabling that unconditionally whenever the target binary is built for either AArch32, or for RISC-V. Doing this for RISC-V acts both as a preventative measure for the wide variety of RISC-V chips out there, and may also help explaining some rare crashes seen when testing native modules on certain MilkV-Duo RV64 boards. If a binary targeting Linux is built with a compiler that is either not compatible with GCC's builtins, or it does not provide `__builtin___clear_cache` (too old or just broken), you'll have to provide your own `MP_HAL_CLEAN_DCACHE` implementation. See the cacheflush(2) man page for why a generic fallback solution is not provided. This refactoring also made it required to provide a cache flush callback for QEMU/SABRELITE, which has been generalised to cover all AArch32 targets. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Use NUM_BANK0_GPIOS to size the pin IRQ array, avoiding a potential leak using IRQs on pins > 30. Signed-off-by: Phil Howard <github@gadgetoid.com>
The RP2350 watchdog supports a 16777ms period vs the RP2040s 8388ms. Signed-off-by: Phil Howard <github@gadgetoid.com>
Move mod_network_init() before boot.py execution so that network interfaces can be instantiated in boot.py. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Replace the blocking PHY init and autonegotiation wait in eth_mac_init() with background link polling via eth_phy_link_status_poll(), called from the LWIP poll loop. This allows active(True) to return immediately regardless of cable state, and handles cable hot-plug by detecting link changes, reconfiguring MAC speed/duplex after autonegotiation completes, and restarting DHCP as needed. PHY_BSR is read twice when sampling link status so the IEEE 802.3 latched-low link bit reflects the current state. If autoneg fails to complete within 5s the MAC falls back to 10Mbps Half-Duplex and prints a warning so the symptom is visible. On link-down in DHCP mode the netif's DHCP-assigned IP is cleared before dhcp_stop() so that the link-up restart path triggers a fresh DHCP exchange. Static IPs are preserved since dhcp_supplied_address() gates the clear. The netif is now registered once during eth_init() so status() returns the physical link state before active(True) is called. The active() method returns the interface enabled state rather than link status; use status() for link/cable state. Tested on NUCLEO_H563ZI (LAN8742A, 100Mb RMII) point-to-point with AX88179 USB NIC, and OPENMV_N6 (RTL8211, 1000Mb RGMII). Builds clean on NUCLEO_H563ZI, NUCLEO_F429ZI, NUCLEO_H743ZI, NUCLEO_N657X0. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
N6 is basically the same as H7 with respect to the FDCAN peripheral, and it is configured to use the same buffer settings as H7. That allows a second CAN peripheral to work (eventually, once support is added), with one CAN allocated 50% of buffer resources. Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com> Signed-off-by: Damien George <damien@micropython.org>
Specifically, either a debug build or a non-stripped release build. Default build config is stripped, so it's redundant to generate debug info and then strip it from the final binary. This saves about 10% compile time compared to passing -g, and more than 10% compared to passing -ggdb3. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Requires a tweak in makeqstrdefs to not enable debug output from the preprocessor, as -g3 adds a lot of extra macro definitions - some of which are picked up by makeqstrdefs otherwise. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
This variant has the smallest application partition in flash. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
The board's on-board SPI flash chip footprint shares pins with the side gpio headers, but the README only mentioned this in general terms. Add an explicit "Pin notes" subsection that lists which pins are used by SPI1 / FLASH_* per variant, calls out the SPI3 conflict on v2.0, and documents the empirical PB4 behaviour on v3.1 reported in issue #18432. Fixes #18432. Signed-off-by: Andrii Anoshyn <anoshyn.andrii@gmail.com>
Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
Set a flag in the link-up transition and MAC-reconfig branches of eth_phy_link_status_poll(), then call eth_dhcp_restart_if_needed() once at the end of the function guarded by the flag. Avoids the back-to-back stop/start that occurred when both branches ran in the same poll iteration. Reported by @dpgeorge in the PR review of the original hot-plug support. Signed-off-by: Andrew Leech <andrew@alelec.net>
The transition block just above unconditionally assigns self->last_link_status = current_link_status, and the surrounding if condition already tested current_link_status true. So by the time this check runs, last_link_status is always true here and the early return can never fire. Signed-off-by: Andrew Leech <andrew@alelec.net>
BUTTON was renamed to SW in 64c7045. Signed-off-by: Damien George <damien@micropython.org>
This allows devices to support partial update of the ROM segments. Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
This uses the new GET_MIN_PREPARE ioctl to support incremental preparation of the ROM partition. On very large partitions the preparation can take a long time (eg due to the erase time of many blocks) and this can lead to a timeout of mpremote. Using incremental preparation prevents the timeout and gives better feedback to the user as to the progress. Signed-off-by: Damien George <damien@micropython.org>
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 6 to 7. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](actions/setup-python@v6...v7) --- updated-dependencies: - dependency-name: actions/setup-python dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
external_call_depth is only read back (to detect the top-level call
boundary) when MICROPY_GC_SPLIT_HEAP_AUTO is enabled. The "standard"
variant does not enable this option, so its build was failing with:
main.c:50:15: error: variable 'external_call_depth' set but not
used [-Werror,-Wunused-but-set-global]
Fix by guarding the variable's declaration, increment, and decrement
all under the same #if, instead of leaving the decrement outside the
guard while the increment and declaration were inside/outside
inconsistently.
Fixes regression introduced by cdaf2de.
Signed-off-by: Harris <harrisjan06@gmail.com>
This commit allows scheduling a KeyboardInterrupt to be raised "very soon"
in the main thread.
Calling the C function `mp_sched_keyboard_interrupt()` directly won't work
as expected, because that will raise the exception almost immediately, even
if running within a scheduled context. So that call is pretty much
equivalent to raise KeyboardInterrupt from the Python side.
Instead, this commit adds a way to schedule a call to
`mp_sched_keyboard_interrupt()`, so that the exception is never raised
within a schedule context, but rather always in the main thread context.
To reduce code size existing functions are reused:
micropython.schedule(micropython.kbd_intr, None)
Addresses #19424.
Signed-off-by: Damien George <damien@micropython.org>
pow(0, 0, m) returned 0 instead of 1 because mpz_pow3_inpl() folded the zero-base check into the guard that returns 0, without looking at the exponent. Move that check below the zero-exponent early return, where the exponent is already known to be non-zero. This keeps the existing short-circuit for a zero base with a large exponent, and does not change the code size. Signed-off-by: Jeongseop Lim <jseoplim@gmail.com>
pow(x, 0, m) returned 1 for every modulus, but in Python the result of a 3-arg pow() takes the sign of the modulus, so pow(3, 0, -5) is -4 and not 1. mpz_pow3_inpl() sets the accumulator to 1 and returns straight away when the exponent is zero, which skips the square-and-multiply loop and with it the mpz_divmod_inpl() calls that are the only place the modulus is ever applied. A non-zero exponent is therefore already correct. Reduce the accumulator before that early return. The entry guard has already rejected abs(mod) == 1, so 1 % mod is exactly 1 + mod for a negative modulus and a single mpz_add_inpl() is enough. This adds 40 bytes to the unix x64 build-standard firmware. Signed-off-by: Jeongseop Lim <jseoplim@gmail.com>
This commit updates the native code generator to use a different
registers set when emitting code for unary negations and bitwise
inversions on integers.
Originally, the native emitter would perform an in-place operation on
the value and thus clobber the register holding the value for further
operations. This meant that code like
@micropython.viper
def f() -> int:
x = -1
x1 = -x
print(x1, x)
return x1
would print the same value twice, as x would get updated with the
negated value and then assigned to x1.
With these changes, the value is placed in the return register directly
whenever possible, and away from potential registers that may be reused
later. This is performed in a way that is compatible with the NEG and
NOT implementations of all currently implemented emitters.
Additional validation of this new behaviour is provided with an
extension to the `micropython/viper_unop` test, performing additional
checks on whether clobbering did take place or not.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This allows short-circuiting the gc_get_ptr_area() call for values which aren't in the overall range of any of the GC areas. Without this, scanning of buffers is walking the linked list of areas for every value (including all zeros, etc). Splits the gc_get_ptr_area() function into two - gc_verify_ptr_get_area() which inlines "fast path" cases for non-pointer data, and gc_get_ptr_area() where the pointer is expected to be valid. This might be something we can revert if we later on add "no scan" allocations for byte arrays, etc. as that will preempt the need to scan most of these structures. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Update rp2/general.rst to include detailed technical specifications for the RP2350 microcontroller Extend rp2/tutorial/pio.rst to cover RP2350 PIO enhancements Signed-off-by: Tomasz Cwik <tomaszcwik2@gmail.com>
Expanded the micropython.const() documentation in library/micropython.rst to address gaps identified through investigation of GitHub issues and user confusion: - Added explicit scope requirement (module-level only) with explanation of why using const() in functions/classes causes confusing behavior - Added import syntax requirement warning (must use bare name "const", not "micropython.const()" or aliased imports) - Clarified storage and visibility differences between underscore and non-underscore prefixed constants, with RAM quantification - Added complete list of valid expression types (integers, floats, strings, bytes, booleans, None, tuples) - Documented cross-module mutability behavior and typing.Final alternative - Added limitations section covering all known issues including type hint incompatibility - Added substitution rules explaining when values are not substituted - Expanded examples section Fixed inconsistency in reference/speed_python.rst that incorrectly claimed const() only accepts integers. Updated to correctly state it accepts any compile-time constant. Added cross-references from all const documentation locations (speed_python.rst, constrained.rst, optimizations.rst) back to the comprehensive micropython.const() documentation. These changes address confusion reported in GitHub issues #573, #11929, #15246, #15608, and #17453. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au> Signed-off-by: Andrew Leech <andrew@alelec.net>
Add link and example to os.dupterm. Add link and example for building from source. Co-authored-by: Angus Gratton <gus@projectgus.com> Signed-off-by: MarcelloTheArcane <marcellothearcane-git@outlook.com>
Issue #15955 reports the impression that ``mpremote run /path/to/main.py`` runs the device's own ``main.py`` instead of the local file. In practice ``run`` reads the local file as bytes and executes them in raw REPL after a soft reset, so the local filename has no special meaning and the device's ``main.py`` is not executed beforehand. Add a short Note that spells this out, since the existing description does not mention the soft-reset / raw-REPL execution flow. Fixes #15955. Signed-off-by: Andrii Anoshyn <anoshyn.andrii@gmail.com>
The behaviour of the two constructors have a subtle difference that is worth documenting. Signed-off-by: Howard Lovatt <howard.lovatt@gmail.com>
Signed-off-by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi
Please see
micropython#11735
The official page
https://docs.micropython.org/en/latest/genrst/builtin_types.html#float
should be updated about the different result of
(and eventually other inconsistencies) between Python and MicroPython.