Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more features in the embed port #11430

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Commits on Apr 21, 2024

  1. py/mkrules.mk: Fix 'make submodules' when building out-of-tree.

    When MicroPython is used as a submodule and built from the containing
    project, e.g. for the embed port, `make submodules` fails because it goes
    looking for the sub-sub-module paths in the outer repository instead of in
    the micropython repository. Fix this by invoking git inside the micropython
    submodule.
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    8e8d530 View commit details
    Browse the repository at this point in the history
  2. examples/embedding-full: Add a more full-featured embedding example.

    It compiles and runs in this state, but a lot of functionality is still
    missing, to be extended over the following commits.
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    16db37e View commit details
    Browse the repository at this point in the history
  3. ports/embed: Move text output to the application.

    The implementation of mp_hal_stdout_tx_strn_cooked() does not belong into
    the library, but into the embedding application. Some applications may not
    want Python output to go straight to their stdout, or may not even have
    printf() available.
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    5e1ea0b View commit details
    Browse the repository at this point in the history
  4. ports/embed: Enable use of extmod modules.

    To include extmod and its dependencies in the output, include the word
    "extmod" in make variable EMBED_EXTRA when building the port.
    
    Ideally this would be deduced automatically from the set of modules enabled
    in mpconfigport.h (in a more fine-grained way too), but I can't think of a
    simple way of achieving that.
    
    Change in mphalport.h: fixes compiler error "type name requires a specifier
    or qualifier" in machine_i2c.h, included from machine_i2c.c.
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    1be753f View commit details
    Browse the repository at this point in the history
  5. ports/embed: Enable freezing Python modules.

    Use FROZEN_MANIFEST as documented in docs/reference/manifest.rst.
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    d3656e9 View commit details
    Browse the repository at this point in the history
  6. examples/embedding-full: Add example user C module.

    This works out of the box in the embed port.
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    605493d View commit details
    Browse the repository at this point in the history
  7. examples/embedding-full: Enable os.uname().

    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    124b2db View commit details
    Browse the repository at this point in the history
  8. examples/embedding-full: Enable floating point numbers and math module.

    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    5a16389 View commit details
    Browse the repository at this point in the history
  9. ports/embed: Implement additional time functions.

    Optionally adds gmtime, localtime, mktime, time, time_ns to the time
    module, implemented using mp_hal_time_ns(). This could also be used by
    other ports.
    
    I'm unsure where to put modtime_mphal.h, it could also be in extmod. The
    important thing is that for MICROPY_PY_TIME_INCLUDEFILE to work it must be
    at the same path in both the port build (original source tree) and the
    application build (micropython_embed distribution), therefore not in
    ports/embed/port.
    
    It is named .h, mismatching the corresponding ports/*/modtime.c, because it
    must not be compiled separately, which naming it .c would make harder for
    users of the embed port - they would need to explicitly exclude it, whereas
    this way they can continue to just compile all the .c files found in the
    micropython_embed distribution except those in lib.
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    170ba15 View commit details
    Browse the repository at this point in the history
  10. examples/embedding-full: Enable uctypes module.

    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    e03158d View commit details
    Browse the repository at this point in the history
  11. examples/embedding-full: Enable mphal-backed sys.stdin/out/err.

    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    972938c View commit details
    Browse the repository at this point in the history
  12. ports/embed: Enable use of littlefs.

    To make use of it, as demonstrated in the embedding-full example:
    - Include the word(s) "littlefs1" and/or "littlefs2" in EMBED_EXTRA in
      micropython_embed.mk.
    - Enable the desired MICROPY_*VFS* features in mpconfigport.h.
    - Add include path "$(EMBED_DIR)/lib/littlefs" to your application build
      system.
    
    For demonstration, a block device implementation containing a small
    read-only littlefs2 image is added to the embedding-full example. The block
    device could have been written in C and interface to some external,
    possibly writable storage medium, but was written in Python and frozen for
    simplicity.
    
    What makes this a bit awkward is the fact that the littlefs sources are
    located in lib/ and do need to be compiled into the application, unlike all
    previous .c files from lib/ that are #included by other C files and must
    not be compiled separately. Therefore, introduce a new directory 'libsrc'
    in the embed build output that contains these files and can be added to the
    application build system as usual, while 'lib' can remain excluded. The
    headers need to stay in 'lib' because vfs_lfs.c refers to them under that
    path. I am also not entirely happy about having to add an additional
    include path to the application build, but see no way around that as long
    as vfs_lfs.c refers to "lib/littlefs/lfs2.h" while lfs2.c refers to
    "lfs2.h".
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    3a8f8db View commit details
    Browse the repository at this point in the history
  13. ports/embed: Enable use of POSIX VFS.

    In the embedding-full example, that requires disabling mphal-backed stdio
    again as it conflicts with the implementation brought in by
    vfs_posix_file.c.
    
    Signed-off-by: Christian Walther <cwalther@gmx.ch>
    cwalther committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    ca93048 View commit details
    Browse the repository at this point in the history