summaryrefslogtreecommitdiffstatshomepage
path: root/examples
Commit message (Collapse)AuthorAge
* py/dynruntime.mk: Enable single-precision float by default on armv6/7m.Damien George6 days
| | | | | | Soft float now works on these ARM targets thanks to the parent commit. Signed-off-by: Damien George <damien@micropython.org>
* examples/natmod/btree: Fix build for Xtensa.Alessandro Gatti11 days
| | | | | | | | | | | | | This commit provides the appropriate external symbol addresses to let the "btree" example natmod build for the Xtensa platform. On the ESP8266, unsigned integer division code isn't provided as part of libgcc.a, libm.a, or libc.a, but it is instead provided by the ROM. Regular builds inject the appropriate symbol addresses as part of the linking process (see eagle.rom.addr.v6.ld), but natmods need this information brought in from somewhere else. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* examples/natmod/deflate: Fix build for Xtensa.Alessandro Gatti11 days
| | | | | | | | | | | | | | | | | | | | This commit provides the appropriate external symbol addresses to let the "deflate" example natmod build for the Xtensa platform. Unlike other natmods that require an external symbol list to build without bringing in the whole runtime libraries set, this natmod is referencing the `__modsi3` symbol which was removed from the ESP8266's SDK but not present in ROM. The latter only has a `__umodsi3` implementation that only operates on unsigned values, and thus unable to handle this natmod. Thus, the extended library resolution process is enabled for this natmod as a `__modsi3` implementation is made available that way (still using ROM symbols whenever possible). This also means that symbols that appear in both ROM and external libraries sort of co-exist in the final MPY file, with ROM symbols being used by natmod code but the implementation from the library still exists in the final MPY file, unused. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* examples/natmod/framebuf: Fix build for Xtensa.Alessandro Gatti11 days
| | | | | | | | | | | | | This commit provides the appropriate external symbol addresses to let the "framebuf" example natmod build for the Xtensa platform. On the ESP8266, integer division code isn't provided as part of libgcc.a, libm.a, or libc.a, but it is instead provided by the ROM. Regular builds inject the appropriate symbol addresses as part of the linking process (see eagle.rom.addr.v6.ld), but natmods need this information brought in from somewhere else. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* examples/natmod/random: Fix build for Xtensa.Alessandro Gatti11 days
| | | | | | | | | | | | | This commit provides the appropriate external symbol addresses to let the "random" example natmod build for the Xtensa platform. On the ESP8266, signed integer division code isn't provided as part of libgcc.a, libm.a, or libc.a, but it is instead provided by the ROM. Regular builds inject the appropriate symbol addresses as part of the linking process (see eagle.rom.addr.v6.ld), but natmods need this information brought in from somewhere else. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* extmod/modframebuf: Add support for blit'ing read-only data.Damien George12 days
| | | | | | | | | | | | | | | | | | | | | | Currently the `FrameBuffer.blit(buf, x, y)` method requires the `buf` argument to be another `FrameBuffer`, which is quite restrictive because it doesn't allow blit'ing read-only memory/data. This commit extends `blit()` to allow the `buf` argument to be a tuple or list of the form: (buffer, width, height, format[, stride]) where `buffer` can be anything with the buffer protocol and may be read-only, eg `bytes`. Also, the palette argument to `blit()` may be of the same form. The form of this tuple/list was chosen to be the same as the signature of the `FrameBuffer` constructor (that saves quite a bit of code size doing it that way). Signed-off-by: Damien George <damien@micropython.org>
* tools/mpy_ld.py: Allow linking static libraries.Volodymyr Shymanskyy2025-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit introduces an additional symbol resolution mechanism to the natmod linking process. This allows the build scripts to look for required symbols into selected libraries that are provided by the compiler installation (libgcc and libm at the moment). For example, using soft-float code in natmods, whilst technically possible, was not an easy process and required some additional work to pull it off. With this addition all the manual (and error-prone) operations have been automated and folded into `tools/mpy_ld.py`. Both newlib and picolibc toolchains are supported, albeit the latter may require a bit of extra configuration depending on the environment the build process runs on. Picolibc's soft-float functions aren't in libm - in fact the shipped libm is nothing but a stub - but they are inside libc. This is usually not a problem as these changes cater for that configuration quirk, but on certain compilers the include paths used to find libraries in may not be updated to take Picolibc's library directory into account. The bare metal RISC-V compiler shipped with the CI OS image (GCC 10.2.0 on Ubuntu 22.04LTS) happens to exhibit this very problem. To work around that for CI builds, the Picolibc libraries' path is hardcoded in the Makefile directives used by the linker, but this can be changed by setting the PICOLIBC_ROOT environment library when building natmods. Signed-off-by: Volodymyr Shymanskyy <vshymanskyi@gmail.com> Co-authored-by: Alessandro Gatti <a.gatti@frob.it>
* all: Upgrade codespell to v2.4.1.Christian Clauss2025-02-25
| | | | | | | This commit upgrades from codespell==2.2.6 to the current codespell==2.4.1, adding emac to the ignore-words-list. Signed-off-by: Christian Clauss <cclauss@me.com>
* examples/natmod/re: Fix build on RV32 with alloca.Alessandro Gatti2024-12-23
| | | | | | | | | | | | This fixes compilation of the `re` natmod example when built with Picolibc in the CI environment. Ubuntu 22.04's combination of its bare metal RISC-V toolchain and its version of Picolibc makes the `alloca` symbol more elusive than it should be. This commit makes the `re` natmod try harder to get an `alloca` implementation. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* tools/mpy_ld.py: Add native modules support for RV32 code.Alessandro Gatti2024-12-23
| | | | | | | | This commit adds support for RV32IMC native modules, as in embedding native code into a self-contained MPY module and and make its exported functions available to the MicroPython environment. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* examples/natmod: Fix URL links in README.md.Matt Trentini2024-09-17
| | | | Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
* examples/network: Support full URLs in HTTP(S) client examples.Damien George2024-08-28
| | | | | | | Not just the domain name. This gives better HTTP 1.0 examples if someone wants to copy them. Signed-off-by: Damien George <damien@micropython.org>
* examples/network: Use SSLContext instead of old ssl.wrap_socket.Damien George2024-08-28
| | | | | | | `ssl.wrap_socket()` is deprecated in CPython, so use `SSLContext` instead, so the example is a good example to copy. Signed-off-by: Damien George <damien@micropython.org>
* examples/network: Support IPv4 and IPv6 in HTTP client examples.Damien George2024-08-28
| | | | | | | | | | | | | | | The main changes here are to pass the address family and socket type to `getaddrinfo()`, and then use the result of the address lookup when creating the socket, so it has the correct address family. This allows both IPv4 and IPv6 to work, because the socket is created with the correct AF_INETx type for the address. Also add some more comments to the examples to explain what's going on. Fixes issue #15580. Signed-off-by: Damien George <damien@micropython.org>
* py: Add new cstack API for stack checking, with limit margin macro.Angus Gratton2024-08-14
| | | | | | | | | | | | | | | | | | | | Currently the stack limit margin is hard-coded in each port's call to `mp_stack_set_limit()`, but on threaded ports it's fiddlier and can lead to bugs (such as incorrect thread stack margin on esp32). This commit provides a new API to initialise the C Stack in one function call, with a config macro to set the margin. Where possible the new call is inlined to reduce code size in thread-free ports. Intended replacement for `MP_TASK_STACK_LIMIT_MARGIN` on esp32. The previous `stackctrl.h` API is still present and unmodified apart from a deprecation comment. However it's not available when the `MICROPY_PREVIEW_VERSION_2` macro is set. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* examples/usercmodule/cexample: Add more advanced native class.Laurens Valk2024-07-25
| | | | | | | This adds a separate `AdvancedTimer` class that demonstrates a few more advanced concepts usch as custom handlers for printing and attributes. Signed-off-by: Laurens Valk <laurens@pybricks.com>
* examples/natmod/btree: Make btree.open use mp_arg_parse_all for kwargs.Damien George2024-05-24
| | | | | | | Python code is no longer needed to implement keyword arguments in `btree.open()`, it can now be done in C. Signed-off-by: Damien George <damien@micropython.org>
* examples/natmod/features4: Create custom FactorialError as exc example.Damien George2024-05-23
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/usb: Add README that points out the alternative usb modules.Angus Gratton2024-05-15
| | | | | | | If someone starts from this directory then they won't know they exist, otherwise. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* examples/network: Add example of HTTPS client using non-blocking socket.Damien George2024-05-13
| | | | | | | Non-blocking SSL streams can be difficult to get right, so provide a working example, of a HTTPS client. Signed-off-by: Damien George <damien@micropython.org>
* examples/network: Rename SSL examples to start with https.Damien George2024-05-13
| | | | | | | It's better for discoverability to have these examples named `https_xxx.py` rather than `http_xxx_ssl.py`. Signed-off-by: Damien George <damien@micropython.org>
* examples/usb: Add a USBDevice example implementing the DFU protocol.Damien George2024-05-13
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/usb: Add a very simple USBDevice example with host.Damien George2024-05-13
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/natmod/framebuf: Enable FrameBuffer.poly method.Damien George2024-03-28
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Update extmod, ports, examples to build with new berkeley-db lib.Damien George2024-03-16
| | | | | | | | | | 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>
* all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton2024-03-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* embed: Improve stack top estimation.YAMAMOTO Takashi2024-02-15
| | | | | | | | | | Obtaining the stack-top via a few function calls may yield a pointer which is too deep within the stack. So require the user to obtain it from a higher level (or via some other means). Fixes issue #11781. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
* examples/embedding: Add -fno-common to the sample compiler flags.Angus Gratton2024-01-31
| | | | | | | | | | | | | | | This makes no difference when files are linked directly into a target application, but on macOS additional steps are needed to index common symbols in static libraries. See https://stackoverflow.com/a/26581710 By not creating any common symbols, this problem is bypassed. This will also trigger linker errors if there are cases where the same symbol is defined in the host application. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/obj: Fix mp_obj_is_type compilation with C++.stijn2023-11-17
| | | | | | Fixes issue #12951. Signed-off-by: stijn <stijn@ignitron.net>
* examples/pins.py: Remove this pins printing example.Jim Mussared2023-11-03
| | | | | | | | | | | | It's not supported on all ports, adds complexity to the build to generate pins_af.py, and can mostly be replicated just by printing the pin objects. Remove support for generating pins_af.py from all ports (nrf, stm32, renesas-ra, mimxrt, rp2). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modframebuf: Remove FrameBuffer1 from natmod build.Jim Mussared2023-10-16
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Fix various spelling mistakes found by codespell 2.2.6.Damien George2023-10-03
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/unix/machine_bios.py: Fix typo.Thomas2023-09-29
| | | | Signed-off-by: Thomas <th.acker.0302@gmail.com>
* examples/natmod: Add features4 as a class definition example.Jim Mussared2023-09-02
| | | | | | | | Also provide a basic README.md for dynamic native modules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/bluetooth: Link to aioble in BLE examples.Jim Mussared2023-09-01
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/bluetooth: Raise ValueError when advertising data is too large.Alexander Wilde2023-09-01
| | | | Signed-off-by: Alexander Wilde <alexander.wilde87@gmail.com>
* examples/hwapi: Add missing import for 96Boards Carbon example.Angus Gratton2023-08-16
| | | | | | Found by Ruff checking F821. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* all: Add missing imports for micropython.const.Angus Gratton2023-08-16
| | | | | | Found by Ruff checking F821. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* examples: Mark asm, pio, etc. as noqa: F821 (undefined-name).Angus Gratton2023-08-16
| | | | | | | | | | | These files all use decorators (@asm_thumb, @asm_pio) that add names to the function scope, that the linter cannot see. It's useful to clear them in the file not in pyproject.toml as example code will be copied and adapted elsewhere, and those developers may also use Ruff (we hope!) Signed-off-by: Angus Gratton <angus@redyak.com.au>
* examples/natmod/deflate: Add deflate as a dynamic native module.Jim Mussared2023-07-21
| | | | | | | | This replaces the previous zlib version. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Remove the zlib module.Jim Mussared2023-07-21
| | | | | | | | | | | | This will be replaced with a new deflate module providing the same functionality, with an optional frozen Python wrapper providing a replacement zlib module. binascii.crc32 is temporarily disabled. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/hwapi: Rename uasyncio to asyncio.Jim Mussared2023-06-19
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Replace all uses of umodule in Python code.Jim Mussared2023-06-08
| | | | | | | | Applies to drivers/examples/extmod/port-modules/tools. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/natmod: Rename umodule to module.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename *umodule*.c to remove the "u" prefix.Jim Mussared2023-06-08
| | | | | | | | | | | Updates any includes, and references from Makefiles/CMake. This essentially reverts what was done long ago in commit 136b5cbd7669e8318f8455fc2706da97a5b7994c This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename UMODULE to MODULE in preprocessor/Makefile vars.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename mod_umodule*, ^umodule* to remove the "u" prefix.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere.Jim Mussared2023-06-08
| | | | | | | | | This renames the builtin-modules, such that help('modules') and printing the module object will show "module" rather than "umodule". This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/usercmodule: Add a sub-package example.Jim Mussared2023-06-01
| | | | | | | | | | | This demonstrates how to add a sub-package in a user c module, as well as how to define the necessary qstrs and enable the feature in the build. This is used by the unix coverage build to test this feature. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Fix cases of Python variable assigned but never used.Christian Clauss2023-05-02
| | | | This fixes ruff rule F841.