summaryrefslogtreecommitdiff
path: root/docs/develop
AgeCommit message (Collapse)Author
2025-07-20docs/develop/natmod: Add notes on Picolibc and natmods.Alessandro Gatti
This commit adds some documentation on what are the limitations of using Picolibc as a standard C library for native modules. This also contains a reference to the "errno" issue when building natmods on RV32 that the PR this commit is part of, as it is not obvious how to approach this issue when encountered for the first time. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-06-04tools/mpy_ld.py: Resolve fixed-address symbols if requested.Alessandro Gatti
This commit lets mpy_ld.py resolve symbols not only from the object files involved in the linking process, or from compiler-supplied static libraries, but also from a list of symbols referenced by an absolute address (usually provided by the system's ROM). This is needed for ESP8266 targets as some C stdlib functions are provided by the MCU's own ROM code to reduce the final code footprint, and therefore those functions' implementation was removed from the compiler's support libraries. This means that unless `LINK_RUNTIME` is set (which lets tooling look at more libraries to resolve symbols) the build process will fail as tooling is unaware of the ROM symbols' existence. With this change, fixed-address symbols can be exposed to the symbol resolution step when performing natmod linking. If there are symbols coming in from a fixed-address symbols list and internal code or external libraries, the fixed-address symbol address will take precedence in all cases. Although this is - in theory - also working for the whole range of ESP32 MCUs, testing is currently limited to Xtensa processors and the example natmods' makefiles only make use of this commit's changes for the ESP8266 target. Natmod builds can set the MPY_EXTERN_SYM_FILE variable pointing to a linkerscript file containing a series of symbols (weak or strong) at a fixed address; these symbols will then be used by the MicroPython linker when packaging the natmod. If a different natmod build method is used (eg. custom CMake scripts), `tools/mpy_ld.py` can now accept a command line parameter called `--externs` (or its short variant `-e`) that contains the path of a linkerscript file with the fixed-address symbols to use when performing the linking process. The linkerscript file parser can handle a very limited subset of binutils's linkerscript syntax, namely just block comments, strong symbols, and weak symbols. Each symbol must be in its own line for the parser to succeed, empty lines or comment blocks are skipped. For an example of what this parser was meant to handle, you can look at `ports/esp8266/boards/eagle.rom.addr.v6.ld` and follow its format. The natmod developer documentation is also updated to reflect the new command line argument accepted by `mpy_ld.py` and the use cases for the changes introduced by this commit. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-03-17tools/mpy_ld.py: Allow linking static libraries.Volodymyr Shymanskyy
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>
2024-12-23tools/mpy_ld.py: Add native modules support for RV32 code.Alessandro Gatti
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>
2024-11-04tests/run-tests.py: Change --target/--device options to --test-instance.Damien George
Previously to this commit, running the test suite on a bare-metal board required specifying the target (really platform) and device, eg: $ ./run-tests.py --target pyboard --device /dev/ttyACM1 That's quite a lot to type, and you also need to know what the target platform is, when a lot of the time you either don't care or it doesn't matter. This commit makes it easier to run the tests by replacing both of these options with a single `--test-instance` (`-t` for short) option. That option specifies the executable/port/device to test. Then the target platform is automatically detected. The `--test-instance` can be passed: - "unix" (the default) to use the unix version of MicroPython - "webassembly" to test the webassembly port - anything else is considered a port/device to pass to Pyboard There are also some shortcuts to specify a port/device, following `mpremote`: - a<n> is short for /dev/ttyACM<n> - u<n> is short for /dev/ttyUSB<n> - c<n> is short for COM<n> For example: $ ./run-tests.py -t a1 Note that the default test instance is "unix" and so this commit does not change the standard way to run tests on the unix port, by just doing `./run-tests.py`. As part of this change, the platform (and it's native architecture if it supports importing native .mpy files) is show at the start of the test run. Signed-off-by: Damien George <damien@micropython.org>
2024-08-01py/py.mk: Add SRC_USERMOD_LIB_ASM to include assembly files.George Hopkins
Introduce SRC_USERMOD_LIB_ASM to allow users to include assembly files as part of their user modules. It could be used to include optimized functions or outputs of other programming languages. Signed-off-by: George Hopkins <george-hopkins@null.net>
2024-04-29docs/develop/optimizations: Fix typo identified in issue 14391.Matt Trentini
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-03-07all: Prune trailing whitespace.Phil Howard
Prune trailing whitespace across the whole project (almost), done automatically with: grep -IUrl --color "[[:blank:]]$" --exclude-dir=.git --exclude=*.exp |\ xargs sed -i 's/[[:space:]]*$//' Exceptions: - Skip third-party code in lib/ and drivers/cc3100/ - Skip generated code in bluetooth_init_cc2564C_1.5.c - Preserve command output whitespace in docs, eg: docs/esp8266/tutorial/repl.rst Signed-off-by: Phil Howard <phil@gadgetoid.com>
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-16py/emitglue: Introduce mp_proto_fun_t as a more general mp_raw_code_t.Damien George
Allows bytecode itself to be used instead of an mp_raw_code_t in the simple and common cases of a bytecode function without any children. This can be used to further reduce frozen code size, and has the potential to optimise other areas like importing. Signed-off-by: Damien George <damien@micropython.org>
2024-01-16docs/develop/porting: Fix argument type of mp_lexer_new_from_file().Damien George
Follow up to 5015779a6f4a180233a78ec8b5fd1ea095057a91. Signed-off-by: Damien George <damien@micropython.org>
2023-10-02docs: Add requirements.txt file with dependencies for Sphinx.Jos Verlinde
Signed-off-by: Jos Verlinde <Jos.Verlinde@Microsoft.com>
2023-08-05docs/develop/gettingstarted: Update ARM package list.Elecia White
Signed-off-by: Elecia White <elecia@logicalelegance.com>
2023-08-04docs/develop/gettingstarted: Clarify submodule initialization.Rene Straub
When building for a specific board this must be specified in make submodules. I.e. make BOARD=STM32F769DISC submodules. Signed-off-by: Rene Straub <rene@see5.ch>
2023-06-08py/builtinimport: Remove weak links.Jim Mussared
In order to keep "import umodule" working, the existing mechanism is replaced with a simple fallback to drop the "u". This makes importing of built-ins no longer touch the filesystem, which makes a typical built-in import take ~0.15ms rather than 3-5ms. (Weak links were added in c14a81662c1df812c0c6b4299f97966302f16477) This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-19docs/develop/porting: Add missing code to example main.c and Makefile.marble
These two missing lines caused the build process to fail when implementing the tutorial example port. Signed-off-by: marble <git@computer-in.love>
2023-04-27all: Fix spelling mistakes based on codespell check.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2022-12-08py: Pass in address to compiled module instead of returning it.Damien George
This change makes it so the compiler and persistent code loader take a mp_compiled_module_t* as their last argument, instead of returning this struct. This eliminates a duplicate context variable for all callers of these functions (because the context is now stored in the mp_compiled_module_t by the caller), and also eliminates any confusion about which context to use after the mp_compile_to_raw_code or mp_raw_code_load function returns (because there is now only one context, that stored in mp_compiled_module_t.context). Reduces code size by 16 bytes on ARM Cortex-based ports. Signed-off-by: Damien George <damien@micropython.org>
2022-11-23examples/usercmodule: Add example of a native C class.Laurens Valk
This shows how ports can add their own custom types/classes. It is part of the unix coverage build, so we can use it for tests too. Signed-off-by: Laurens Valk <laurens@pybricks.com>
2022-11-11docs/develop: Fix mp_compile snippet to match latest code.Damien George
Signed-off-by: Damien George <damien.p.george@gmail.com>
2022-10-11py/py.mk: Make user-C-module handling self-contained in py.mk.Jim Mussared
Removes the need for the port to add anything to OBJS or SRC_QSTR. Also makes it possible for user-C-modules to differentiate between code that should be processed for QSTR vs other files (e.g. helpers and libraries). Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11all: Use += rather than = everywhere for CFLAGS/LDFLAGS/LIBS.Jim Mussared
This avoids a surprise where an = can cancel out an earlier +=. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-30top: Replace upip with mip everywhere.Jim Mussared
Updates all README.md and docs, and manifests to `require("mip")`. Also extend and improve the documentation on freezing and packaging. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-11docs: Update links for Arm GCC toolchain.David Lechner
The separate A and RM toolchains have been discontinued and replaced by a single toolchain. This updates the links to the RM toolchain to the new toolchain. Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18shared/readline: Use MP_REGISTER_ROOT_POINTER().David Lechner
This uses MP_REGISTER_ROOT_POINTER() to register the readline_history root pointer array used by shared/readline.c and removes the registration from all mpconfigport.h files. This also required adding a new MICROPY_READLINE_HISTORY_SIZE config option since not all ports used the same sized array. Signed-off-by: David Lechner <david@pybricks.com>
2022-06-21extmod/extmod.mk: Separate out extmod file list from py.mk to extmod.mk.David Lechner
This separates extmod source files from `py.mk`. Previously, `py.mk` assumed that every consumer of the py/ directory also wanted to include extmod/. However, this is not the case. For example, building mpy-cross uses py/ but doesn't need extmod/. This commit moves all extmod-specific items from `py.mk` to `extmod.mk` and explicitly includes `extmod.mk` in ports that use it. Signed-off-by: David Lechner <david@pybricks.com>
2022-06-02all: Remove third argument to MP_REGISTER_MODULE.Damien George
It's no longer needed because this macro is now processed after preprocessing the source code via cpp (in the qstr extraction stage), which means unused MP_REGISTER_MODULE's are filtered out by the preprocessor. Signed-off-by: Damien George <damien@micropython.org>
2022-05-23py/dynruntime.mk: Add basic support for armv6m architecture.Damien George
The examples/natmod features0 and features1 examples now build and run on ARMv6-M platforms. More complicated examples are not yet supported because the compiler emits references to built-in functions like __aeabi_uidiv. Signed-off-by: Damien George <damien@micropython.org>
2022-02-04docs/develop/porting.rst: Fix build and import problems in the example.Cem Eliguzel
2021-12-18py/runtime: Allow initialising sys.path/argv with defaults.Damien George
If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is enabled (which it is by default) then sys.path and sys.argv will be initialised and populated with default values. This keeps all bare-metal ports aligned. Signed-off-by: Damien George <damien@micropython.org>
2021-12-15docs: Remove trailing spaces and convert tabs to spaces.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-08-13docs: Replace ufoo with foo in all docs.Jim Mussared
Anywhere a module is mentioned, use its "non-u" name for consistency. The "import module" vs "import umodule" is something of a FAQ, and this commit intends to help clear that up. As a first approximation MicroPython is Python, and so imports should work the same as Python and use the same name, to a first approximation. The u-version of a module is a detail that can be learned later on, when the user wants to understand more and have finer control over importing. Existing Python code should just work, as much as it is possible to do that within the constraints of embedded systems, and the MicroPython documentation should match the idiomatic way to write Python code. With universal weak links for modules (via MICROPY_MODULE_WEAK_LINKS) users can consistently use "import foo" across all ports (with the exception of the minimal ports). And the ability to override/extend via "foo.py" continues to work well. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-07-12all: Update to point to files in new shared/ directory.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-05-04docs: Fix some spelling mistakes.Mike Causer
2021-04-02docs/develop: Improve user C modules to properly describe how to build.Damien George
Make and CMake builds are slightly different and these changes help make it clear what to do in each case. Signed-off-by: Damien George <damien@micropython.org>
2021-04-01examples/usercmodules: Simplify user C module enabling.Damien George
It's a bit of a pitfall with user C modules that including them in the build does not automatically enable them. This commit changes the docs and examples for user C modules to encourage writers of user C modules to enable them unconditionally. This makes things simpler and covers most use cases. See discussion in issue #6960, and also #7086. Signed-off-by: Damien George <damien@micropython.org>
2021-03-31docs/develop/cmodules.rst: Document C-modules and micropython.cmake.Phil Howard
Documents the micropython.cmake file required to make user C modules compatible with the CMake build system. Signed-off-by: Phil Howard <phil@pimoroni.com>
2021-03-15all: Add .git-blame-ignore-revs for fixing up git blame output.stijn
Add most formatting-only commits to this file so that when used with git blame, these commits are excluded and the output shows only the interesting bits.
2021-03-12tests: Rename run-tests to run-tests.py for consistency.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-01-30docs/develop/natmod: Fix a small typo, con->can.Samuelson
2021-01-27docs/develop: Add MicroPython Internals chapter.nanjekyejoannah
This commit adds many new sections to the existing "Developing and building MicroPython" chapter to make it all about the internals of MicroPython. This work was done as part of Google's Season of Docs 2020.
2020-10-29docs/develop/cmodules.rst: Add link to source code for user C example.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-10-29examples: Add example code for user C modules, both C and C++.stijn
Add working example code to provide a starting point for users with files that they can just copy, and include the modules in the coverage test to verify the complete user C module build functionality. The cexample module uses the code originally found in cmodules.rst, which has been updated to reflect this and partially rewritten with more complete information.
2020-10-29py/py.mk: Support C++ code for user C modules.stijn
Support C++ code in .cpp files by providing CXX counterparts of the _USERMOD_ flags we have for C already. This merely enables the Makefile of user C modules to use variables specific to C++ compilation, it is still up to each port's main Makefile to also include these in the build.
2020-10-29docs: Fix reference to QSTR_GEN_CFLAGS Makefile flag.stijn
2020-09-25docs/develop: Add notes on prerequisite tools for building native .mpy.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-05-16docs/develop: Fix module/source name in Makefile of native example.Damien George
2020-02-16docs/develop: Detail how to add symbols to mp_fun_table for native mods.Thorsten von Eicken
2020-01-06docs: More consistent capitalization and use of articles in headings.Jason Neal
See issue #3188.
2019-12-19docs/develop: Add documentation on how to build native .mpy modules.Damien George