Commit Graph

144 Commits

Author SHA1 Message Date
Jim Mussared
8a0ee5a5c0 py/objstr: Split mp_obj_str_from_vstr into bytes/str versions.
Previously the desired output type was specified.  Now make the type part
of the function name.  Because this function is used in a few places this
saves code size due to smaller call-site.

This makes `mp_obj_new_str_type_from_vstr` a private function of objstr.c
(which is almost the only place where the output type isn't a compile-time
constant).

This saves ~140 bytes on PYBV11.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-26 16:43:55 +10:00
Jim Mussared
28aaab9590 py/objstr: Add hex/fromhex to bytes/memoryview/bytearray.
These were added in Python 3.5.

Enabled via MICROPY_PY_BUILTINS_BYTES_HEX, and enabled by default for all
ports that currently have ubinascii.

Rework ubinascii to use the implementation of these methods.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-12 12:44:30 +10:00
Damien George
6c67fbc280 zephyr/machine_uart: Use mp_obj_str_get_str to get device name.
This checks that the argument is actually a string.

Signed-off-by: Damien George <damien@micropython.org>
2022-08-11 23:18:02 +10:00
David Lechner
ccda7686a4 zephyr: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register port-specific root
pointers for the zephyr port.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:35 +10:00
David Lechner
81dbea1ce3 shared/readline: Use MP_REGISTER_ROOT_POINTER().
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-07-18 13:48:49 +10:00
Maureen Helm
bada8b3cad zephyr: Upgrade to Zephyr v3.1.0.
Updates the Zephyr port build instructions and CI to use the latest Zephyr
release tag.

Tested on frdm_k64f.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-06-17 16:51:34 +10:00
Maureen Helm
4fd54a4756 zephyr: Update include paths to use the zephyr namespace.
Zephyr v3.1.0 moved all public headers to include/zephyr.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-06-17 16:44:30 +10:00
Damien George
d75892c0b0 zephyr/modusocket: Fix function object wrapper for listen method.
This was missed by 919f696ad2

Signed-off-by: Damien George <damien@micropython.org>
2022-06-15 11:38:09 +10:00
Damien George
efe23aca71 all: Remove third argument to MP_REGISTER_MODULE.
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-06-02 16:31:37 +10:00
Damien George
6e71cde6aa ports: Use default VFS config for import_stat and builtin_open.
For ports with MICROPY_VFS and MICROPY_PY_IO enabled their configuration
can now be simplified to use the defaults for mp_import_stat and
mp_builtin_open.

This commit makes no functional change, except for the following minor
points:
- the built-in "open" is removed from the minimal port (it previously did
  nothing)
- the duplicate built-in "input" is removed from the esp32 port
- qemu-arm now delegates to VFS import/open

Signed-off-by: Damien George <damien@micropython.org>
2022-05-25 13:04:45 +10:00
Damien George
5956466c0e py/builtin: Clean up and simplify import_stat and builtin_open config.
The following changes are made:

- If MICROPY_VFS is enabled then mp_vfs_import_stat and mp_vfs_open are
  automatically used for mp_import_stat and mp_builtin_open respectively.

- If MICROPY_PY_IO is enabled then "open" is automatically included in the
  set of builtins, and points to mp_builtin_open_obj.

This helps to clean up and simplify the most common port configuration.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-25 13:04:45 +10:00
Jim Mussared
ec2fe5d6ca zephyr: Make port-specific modules use MP_REGISTER_MODULE.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-18 20:57:09 +10:00
Jim Mussared
4eab44a1ec extmod: Make extmod modules use MP_REGISTER_MODULE.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-18 20:49:12 +10:00
Jim Mussared
0e7bfc88c6 all: Use mp_obj_malloc everywhere it's applicable.
This replaces occurences of

    foo_t *foo = m_new_obj(foo_t);
    foo->base.type = &foo_type;

with

    foo_t *foo = mp_obj_malloc(foo_t, &foo_type);

Excludes any places where base is a sub-field or when new0/memset is used.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-03 22:28:14 +10:00
Damien George
5c32111fa0 ports: Reformat more C and Python source code.
These files that are reformatted only now fall under the list of files to
apply uncrustify/black formatting to.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-20 16:17:35 +10:00
Damien George
aab005c75b extmod/modusocket: Provide config macro for socket.listen backlog deflt.
To make it possible to change this value for any given port or board.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-11 15:28:56 +10:00
Jon Bjarni Bjarnason
919f696ad2 extmod/modusocket: Implement optional socket.listen backlog argument.
This follows the CPython change: https://bugs.python.org/issue21455

Socket listen backlog defaults to 2 if not given, based on most bare metal
targets not having many resources for a large backlog.  On UNIX it defaults
to SOMAXCONN or 128, whichever is less.
2022-04-11 15:26:47 +10:00
Damien George
818be10bb5 zephyr/moduos: Convert module to use extmod version.
This also adds uos.unlink(), for all ports that use extmod/moduos.c.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-09 10:03:23 +11:00
Damien George
926b554daf extmod/moduos: Create general uos module to be used by all ports.
Based on the rp2 port version, with the rp2 port converted to use this
module.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-09 10:03:23 +11:00
Damien George
cced9a0128 zephyr/prj.conf: Enable CONFIG_BUILD_OUTPUT_HEX to generate .hex output.
The .hex file contains more information than .bin, useful for flashing.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-07 16:48:35 +11:00
Maureen Helm
474d288e55 zephyr: Upgrade to Zephyr v3.0.0.
Updates the Zephyr port build instructions and CI to use the latest
Zephyr release tag.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-03-07 16:48:35 +11:00
Maureen Helm
86a4a52670 zephyr: Update include path to disk_access.h.
The disk_access header was moved to a different path in Zephyr v2.6.0.
The old path was deprecated for two releases (v2.6.0 and v2.7.0) and
will no longer be supported after Zephyr v2.7.0.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-03-07 16:48:35 +11:00
Damien George
fbd47fc46c ports: Consolidate inclusion of umachine module in built-ins.
The inclusion of `umachine` in the list of built-in modules is now done
centrally in py/objmodule.c.  Enabling MICROPY_PY_MACHINE will include this
module.

As part of this, all ports now have `umachine` as the core module name
(previously some had only `machine` as the name).

Signed-off-by: Damien George <damien@micropython.org>
2022-02-03 10:08:54 +11:00
Damien George
a49b51b7db zephyr/modbluetooth_zephyr: Provide dummy connect_cancel function.
Signed-off-by: Damien George <damien@micropython.org>
2022-01-13 13:45:55 +11:00
Maureen Helm
c6d26bc524 zephyr: Upgrade to Zephyr v2.7.0.
Updates the Zephyr port build instructions and CI to use the latest
Zephyr release tag.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-01-06 14:09:39 +11:00
Maureen Helm
0cf03bd3b1 zephyr: Use CONFIG_USB_DEVICE_STACK for conditional USB device support.
CONFIG_USB was removed in Zephyr v2.7.0 after some Kconfig rework that
made it sufficient to use CONFIG_USB_DEVICE_STACK only.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-01-06 14:09:39 +11:00
Maureen Helm
1e5df0982a zephyr: Get UART console device from devicetree instead of Kconfig.
Updates the Zephyr port to get the UART console device from devicetree
instead of Kconfig. The Kconfig option CONFIG_UART_CONSOLE_ON_DEV_NAME
was removed in Zephyr v2.7.0.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-01-06 14:09:39 +11:00
Maureen Helm
080a9e906d zephyr: Update include path to reboot.h.
The reboot header was moved to a different path in Zephyr v2.6.0. The
old path was deprecated for two releases (v2.6.0 and v2.7.0) and will no
longer be supported after Zephyr v2.7.0.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-01-06 14:09:39 +11:00
Maureen Helm
ddbbfbed75 zephyr: Increase minimum CMake version to 3.20.0.
As a prerequisite to upgrading to Zephyr v2.7.0, upgrade the minimum
CMake version required for the Zephyr port to 3.20.0.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-01-06 14:09:39 +11:00
Damien George
de43b500bd py/runtime: Allow initialising sys.path/argv with defaults.
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-18 00:08:07 +11:00
Jim Mussared
43467b9c71 extmod/modbluetooth: Add connection interval to gap_connect.
This forwards through directly to the NimBLE and BTStack connect functions.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-10-26 00:16:53 +11:00
Damien George
1083cb2f33 zephyr/mphalport.h: Remove unused and unimplemented C-level pin API.
It gives compile warnings.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Damien George
122d901ef1 extmod/machine_i2c: Make SoftI2C configurable via macro option.
The zephyr port doesn't support SoftI2C so it's not enabled, and the legacy
I2C constructor check can be removed.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Jim Mussared
1d9e489af3 extmod/modbluetooth: Add send_update arg to gatts_write.
This allows the write to trigger a notification or indication, but only to
subscribed clients. This is different to gatts_notify/gatts_indicate,
which will unconditionally notify/indicate.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-14 22:21:55 +10:00
Damien George
136369d72f all: Update to point to files in new shared/ directory.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12 17:08:10 +10:00
Julia
3966f67746 zephyr/machine_spi: Add support for hardware SPI.
Adds support for hardware SPI to the zephyr port.  Consistent with other
ports, such as rp2 and stm32, we only implement the SPI protocol functions
(init and transfer).  Explicit sck/mosi/miso selection is not supported
and new SPI instances are initialized with default values.
2021-07-06 00:00:57 +10:00
Damien George
d00523ba0c zephyr/boards: Enable ubluetooth on nucleo_wb55rg board.
Signed-off-by: Damien George <damien@micropython.org>
2021-06-06 21:57:44 +10:00
Damien George
80e79a777d zephyr: Add initial ubluetooth module integration.
Currently only advertising and scanning are supported, using the ring
buffer for events (ie not synchronous events at this stage).

The ble_gap_advertise.py multi-test passes (tested on a nucleo_wb55rg
board).

Signed-off-by: Damien George <damien@micropython.org>
2021-06-06 21:57:06 +10:00
Maureen Helm
5cb2ade65b zephyr: Update to Zephyr v2.6.0.
Updates the zephyr port build instructions and CI to use the latest
zephyr release tag.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-06-06 20:17:42 +10:00
Maureen Helm
3331b1811d zephyr: Disable CONFIG_NET_SOCKETS_POSIX_NAMES.
Zephyr's default value for CONFIG_NET_SOCKETS_POSIX_NAMES was changed
from false to true between Zephyr v2.5.0 and v2.6.0. This caused
conflicts in MicroPython, which uses the zsock_ prefixed functions, so
disable it.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-06-06 20:17:42 +10:00
Maureen Helm
f17c0db5f7 zephyr: Update disk access configuration for Zephyr v2.6.0.
Zephyr's Kconfig symbols and defaults for SDHC/SDMMC disk drivers and
the disk access subsystem were reworked between Zephyr v2.5.0 and
v2.6.0. Update MicroPython accordingly.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-06-06 20:17:42 +10:00
Damien George
888664130c zephyr/boards: Add config for nucleo_wb55rg board.
This board does not work with CONFIG_NETWORKING enabled.  And
CONFIG_CONSOLE_SUBSYS is enabled so that ctrl-C works.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:32:16 +10:00
Damien George
b46a033e25 zephyr/modmachine: Add machine.idle().
Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:32:16 +10:00
Damien George
d120859857 zephyr: Run scheduled callbacks at REPL and during mp_hal_delay_ms.
And ctrl-C can now interrupt a time.sleep call.  This uses Zephyr's k_poll
API to wait efficiently for an event signal, and an optional semaphore.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:32:16 +10:00
Damien George
e9e9c76ddf all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt.
To match mp_sched_exception() and mp_sched_schedule().

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
Damien George
5dcc9b3b16 py/py.cmake: Introduce MICROPY_INC_CORE as a list with core includes.
Signed-off-by: Damien George <damien@micropython.org>
2021-04-09 13:08:35 +10:00
Damien George
6129b8e401 tests: Rename run-tests to run-tests.py for consistency.
Signed-off-by: Damien George <damien@micropython.org>
2021-03-12 19:56:09 +11:00
PTH
5cb91afb9b zephyr/modusocket: Fix parameter in calls to net_context_get_XXX().
The following simple usocket example throws an error EINVAL on connect

    import usocket
    s = usocket.socket()
    s.connect(usocket.getaddrinfo('www.micropython.org', 80)[0][-1])

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: [Errno 22] EINVAL

Fixing the context parameter in calls of net_context_get_family() and
net_context_get_type(), the connect works fine.

Tested on a nucleo_h743zi board.
2021-02-17 10:42:43 +11:00
PTH
6c4a5d185d zephyr/boards: Add support for the nucleo_h743zi board. 2021-02-17 10:38:00 +11:00
Maureen Helm
f573e73bae zephyr: Build MicroPython as a cmake target.
Refactors the zephyr build infrastructure to build MicroPython as a
cmake target, using the recently introduced core cmake rules.

This change makes it possible to build the zephyr port like most other
zephyr applications using west or cmake directly. It simplifies building
with extra cmake arguments, such as specifying an alternate conf file or
adding an Arduino shield. It also enables building the zephyr port
anywhere in the host file system, which will allow regressing across
multiple boards with the zephyr twister script.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-02-16 18:49:30 +11:00