Commit Graph

73 Commits

Author SHA1 Message Date
Maureen Helm 1ae861819d zephyr: Use cmake find_package to locate zephyr.
Updates the zephyr port to use the ZEPHYR_BASE environment variable only to
locate the zephyr cmake package, allowing cmake to cache the variable.
2020-06-12 10:25:16 +10:00
Maureen Helm b1651ff092 zephyr: Increase minimum required cmake version to 3.13.1.
The minimum required cmake version has been 3.13.1 since zephyr 1.14.0.
2020-06-12 10:25:13 +10:00
Maureen Helm 4837b1caa2 zephyr: Convert DT_FLASH_AREA usages to new dts macros.
Converts DT_FLASH_AREA usages in the zephyr port to new device tree macros
introduced in zephyr 2.3.

Tested with littlefs on the reel_board.
2020-06-12 10:25:04 +10:00
Maureen Helm 6aff27ac3c zephyr: Update to new zephyr timeout API.
Updates the zephyr port to use the new timeout api introduced in zephyr
2.3.
2020-06-12 10:24:54 +10:00
Maureen Helm db02cb061d zephyr: Update for refactored zephyr device structures.
Updates the zephyr port to use refactored device structures introduced in
zephyr 2.3.
2020-06-12 10:24:46 +10:00
Maureen Helm 8b061f2d79 zephyr: Fix floating point configuration.
Zephyr renamed CONFIG_FLOAT to CONFIG_FPU to better reflect its semantics
of enabling the hardware floating point unit (FPU) rather than enabling
toolchain-level floating point support (i.e., software floating point for
FPU-less socs).
2020-06-12 10:24:30 +10:00
Maureen Helm 38b4f1569e zephyr: Fix and rename stacks_analyze function in zephyr module.
Zephyr deprecated and then removed its stack_analyze function because it
was unsafe.  Use the new zephyr thread analyzer instead and rename the
MicroPython function to zephyr.thread_analyze() to be more consistent with
the implementation.

Tested on mimxrt1050_evk.

The output now looks like this:

>>> zephyr.thread_analyze()
Thread analyze:
 80004ff4            : unused 400 usage 112 / 512 (21 %)
 rx_workq            : unused 1320 usage 180 / 1500 (12 %)
 tx_workq            : unused 992 usage 208 / 1200 (17 %)
 net_mgmt            : unused 656 usage 112 / 768 (14 %)
 sysworkq            : unused 564 usage 460 / 1024 (44 %)
 idle                : unused 256 usage 64 / 320 (20 %)
 main                : unused 2952 usage 1784 / 4736 (37 %)
2020-06-12 10:24:01 +10:00
Maureen Helm 25434e976b zephyr: Use zephyr build system to merge configurations.
The zephyr build system supports merging application-level board
configurations, so there is no need to reproduce this functionality in
MicroPython.

If CONF_FILE is not explicitly set, then the zephyr build system looks for
prj.conf in the application directory.  Therefore we rename the MicroPython
prj_base.conf to prj.conf.

Furthermore, if the zephyr build system finds boards/$(BOARD).conf in the
application directory, it merges that configuration with prj.conf.
Therefore we rename all the MicroPython board .conf files and move them
into a boards/ directory.

The minimal configuration, prj_minimal.conf, is left in the application
directory because it is used as an explicitly set CONF_FILE in
make-minimal.
2020-05-05 00:48:44 +10:00
stijn 84fa3312cf all: Format code to add space after C++-style comment start.
Note: the uncrustify configuration is explicitly set to 'add' instead of
'force' in order not to alter the comments which use extra spaces after //
as a means of indenting text for clarity.
2020-04-23 11:24:25 +10:00
Jim Mussared def76fe4d9 all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
Maureen Helm 76a5b3a97a zephyr: Update machine.Pin class to use new zephyr gpio api.
Zephyr v2.2 reworked its gpio api to support linux device tree bindings and
pin logical levels.  This commit updates the zephyr port's machine.Pin
class to replace the deprecated gpio api calls with the new supported gpio
api.  This resolves several build warnings.

Tested on frdm_k64f and mimxrt1050_evk boards.
2020-03-25 00:29:42 +11:00
Maureen Helm 110a610f70 zephyr: Execute main.py file if it exists.
Adds support in the zephyr port to execute main.py if the file system is
enabled and the file exists. Existing support for executing a main.py
frozen module is preserved, since pyexec_file_if_exists() works just
like pyexec_frozen_module() if there's no vfs.
2020-03-11 08:30:42 -05:00
Maureen Helm 78c7e4a859 zephyr: Enable usb mass storage class on mimxrt1050_evk.
Enables the zephyr usb device stack and mass storage class on the
mimxrt1050_evk board. The mass storage class is backed by the sdhc disk
access driver, so it's now possible to browse and modify the contents of
the SD card from a USB host (your PC). This is in preparation to support
writing a main.py script to the SD card, and then executing it after the
next reset.
2020-03-11 07:46:41 -05:00
Maureen Helm 5feb54afbb zephyr: Mount a file system during init.
Adds support in the zephyr port to mount a file system if a block device
(sdhc disk access or flash area) is available. The mount point is either
"/sd" or "/flash" depending on the type of block device.

Tested with an sdhc disk access block device and fatfs on the
mimxrt1050_evk board.

Tested with a flash area block device and littlefs on the reel_board.
2020-03-11 07:46:41 -05:00
Damien George 69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Maureen Helm 7a5752a748 zephyr: Enable littlefs.
Enables the littlefs (v1 and v2) filesystems in the zephyr port.

Example usage with the internal flash on the reel_board or the
rv32m1_vega_ri5cy board:

import os
from zephyr import FlashArea
bdev = FlashArea(FlashArea.STORAGE, 4096)
os.VfsLfs2.mkfs(bdev)
os.mount(bdev, '/flash')
with open('/flash/hello.txt','w') as f:
    f.write('Hello world')
print(open('/flash/hello.txt').read())

Things get a little trickier with the frdm_k64f due to the micropython
application spilling into the default flash storage partition defined
for this board. The zephyr build system doesn't enforce the flash
partitioning when mcuboot is not enabled (which it is not for
micropython). For now we can demonstrate that the littlefs filesystem
works on frdm_k64f by constructing the FlashArea block device on the
mcuboot scratch partition instead of the storage partition. Do this by
replacing the FlashArea.STORAGE constant above with the value 4.
2020-02-07 11:24:06 +11:00
Maureen Helm 86a66960f9 zephyr: Implement block device protocol via zephyr flash map api.
Introduces a new zephyr.FlashArea class that uses the zephyr flash map
api to implement the uos.AbstractBlockDev protocol. The flash driver is
enabled on the frdm_k64f board, reel_board, and rv32m1_vega_ri5cy board.

The standard and extended block device protocols are both supported,
therefore this class can be used with file systems like littlefs which
require the extended interface.
2020-02-07 11:24:06 +11:00
Maureen Helm 2d7ec8e704 zephyr: Enable fatfs.
Enables the fatfs filesystem in the zephyr port.

Example usage with an SD card on the mimxrt1050_evk board:

import zephyr, os
bdev = zephyr.DiskAccess('SDHC')
os.VfsFat.mkfs(bdev)
os.mount(bdev, '/sd')
with open('/sd/hello.txt','w') as f:
    f.write('Hello world')
print(open('/sd/hello.txt').read())
2020-02-07 11:24:06 +11:00
Maureen Helm a0440b01ea zephyr: Enable virtual file system and uos module.
Enables the virtual file system and uos module in the zephyr port.
No concrete file system implementations are enabled yet.
2020-02-07 11:24:06 +11:00
Maureen Helm cc19cf2549 zephyr: Implement block device protocol via zephyr disk access api.
Introduces a new zephyr.DiskAccess class that uses the zephyr disk
access api to implement the uos.AbstractBlockDev protocol. This can be
used with any type of zephyr disk access driver, which currently
includes SDHC, RAM, and FLASH implementations. The SDHC driver is
enabled on the mimxrt1050_evk board.

Only the standard block device protocol (without the offset parameter)
can be supported with the zephyr disk access api, therefore this class
cannot be used with file systems like littlefs which require the
extended interface. In the future it may be possible to implement the
extended interface in a new class using the zephyr flash api.
2020-02-07 11:24:06 +11:00
Maureen Helm bc3ce86a5a zephyr: Remove reference to syscall_macros_h_target.
Zephyr removed the build target syscall_macros_h_target in commit
f4adf107f31674eb20881531900ff092cc40c07f.  Removes reference from
MicroPython to fix build errors in the zephyr port.

This change is not compatible with zephyr v2.1 or earlier.  It will be
compatible with Zephyr v2.2 when released.
2020-02-04 17:10:24 +11:00
Maureen Helm a7663b862e zephyr: Replace deprecated time conversion macro.
The SYS_CLOCK_HW_CYCLES_TO_NS macro was deprecated in zephyr commit
8892406c1de21bd5de5877f39099e3663a5f3af1.  This commit updates MicroPython
to use the new k_cyc_to_ns_floor64 api and fix build warnings in the zephyr
port.

This change is compatible with Zephyr v2.1 and later.
2020-02-04 17:09:59 +11:00
Maureen Helm c25e12d0dd zephyr: Update include paths for Zephyr v2.0.
Zephyr restructured its includes in v2.0 and removed compatibility shims
after two releases in commit 1342dadc365ee22199e51779185899ddf7478686.
Updates include paths in MicroPython accordingly to fix build errors in
the zephyr port.

These changes are compatible with Zephyr v2.0 and later.
2020-02-04 17:09:19 +11:00
Kamil Klimek 53f3cbc2c4 zephyr/main: Use mp_stack API instead of local pointer for stack top.
The MP_STATE_THREAD(stack_top) is always available so use it instead of
creating a separate variable.  This also allows gc_collect() to be used as
an independent function, without real_main() being called.
2019-10-29 23:05:07 +11:00
Damien George d2384efa80 py: Automatically provide weak links from "foo" to "ufoo" module name.
This commit implements automatic module weak links for all built-in
modules, by searching for "ufoo" in the built-in module list if "foo"
cannot be found.  This means that all modules named "ufoo" are always
available as "foo".  Also, a port can no longer add any other weak links,
which makes strict the definition of a weak link.

It saves some code size (about 100-200 bytes) on ports that previously had
lots of weak links.

Some changes from the previous behaviour:
- It doesn't intern the non-u module names (eg "foo" is not interned),
  which saves code size, but will mean that "import foo" creates a new qstr
  (namely "foo") in RAM (unless the importing module is frozen).
- help('modules') no longer lists non-u module names, only the u-variants;
  this reduces duplication in the help listing.

Weak links are effectively the same as having a set of symbolic links on
the filesystem that is searched last.  So an "import foo" will search
built-in modules first, then all paths in sys.path, then weak links last,
importing "ufoo" if it exists.  Thus a file called "foo.py" somewhere in
sys.path will still have precedence over the weak link of "foo" to "ufoo".

See issues: #1740, #4449, #5229, #5241.
2019-10-22 15:30:52 +11:00
Paul Sokolovsky c4a6d9c631 zephyr: Switch back to enabling I2C in board-specific configs.
I2C can't be enabled in prj_base.conf because it's a board-specific
feature.  For example, if a board doesn't have I2C but CONFIG_I2C=y then
the build will fail (on Zephyr build system side).  The patch here gets the
qemu_cortex_m3 build working again.
2019-05-24 15:33:02 +10:00
Paul Sokolovsky b88bf42793 zephyr/README: Reorder content related to recently added I2C.
So it fits better with existing narrative.
2019-05-24 15:29:29 +10:00
Damien George 647b27d028 zephyr/machine_i2c: Update to support new C-level I2C API. 2019-05-20 15:04:29 +10:00
Damiano Mazzella 3c9f78b048 zephyr/CMakeLists.txt: Set AR to point to the Zephyr toolchain exe. 2019-04-11 12:24:05 +10:00
Maureen Helm 2befcb8a9d zephyr/i2c: Add support for hardware i2c.
Adds support for hardware i2c to the zephyr port. Similar to other ports
such as stm32 and nrf, we only implement the i2c protocol functions
(readfrom and writeto) and defer memory operations (readfrom_mem,
readfrom_mem_into, and writeto_mem) to the software i2c implementation.
This may need to change in the future because zephyr is considering
deprecating its i2c_transfer function in favor of i2c_write_read; in this
case we would probably want to implement the memory operations directly
using i2c_write_read.

Tested with the accelerometer on frdm_k64f and bbc_microbit boards.
2019-03-26 16:16:26 +11:00
Maureen Helm 493ee7df18 zephyr/prj_frdm_kw41z.conf: Add new board configuration.
Adds a new board configuration for the frdm_kw41z board, including support
for the fxos8700 accelerometer/magnetometer/die temperature sensor.
2019-03-12 17:12:13 +11:00
Maureen Helm 7748375b6e zephyr/prj_frdm_k64f.conf: Add fxos8700 sensor.
Adds the fxos8700 accelerometer/magnetometer/die temperature sensor to the
frdm_k64f board configuration.
2019-03-12 17:12:00 +11:00
Paul Sokolovsky 6d82499a48 zephyr/Makefile: Proxy ram_report, rom_report targets from Zephyr. 2019-03-12 17:11:52 +11:00
Paul Sokolovsky 755b0b807b zephyr/prj_minimal.conf: Switch to CONFIG_STDOUT_CONSOLE.
Prompted by code size analysis, after arduino_101 build overflowing ROM.
2019-03-12 17:11:46 +11:00
Paul Sokolovsky 21fc0c448e zephyr/modzsensor: Rename "TEMP" sensor channel to "DIE_TEMP".
I.e. on-die temperature sensor.  Upstream made more fine-grained channels
for different kinds of temperature.
2019-03-12 17:11:30 +11:00
Paul Sokolovsky a42c1d9fd5 zephyr/modzephyr: Revamp stacks_analyze() call.
Underlying k_call_stacks_analyze() was gone in Zephyr, reimplement using
k_thread_foreach().
2019-03-12 17:11:09 +11:00
Damien George 6e30f96b0b ports: Convert legacy uppercase macro names to lowercase. 2019-02-12 14:54:51 +11:00
Paul Sokolovsky 2f5d113fad py/warning: Support categories for warnings.
Python defines warnings as belonging to categories, where category is a
warning type (descending from exception type). This is useful, as e.g.
allows to disable warnings selectively and provide user-defined warning
types.  So, implement this in MicroPython, except that categories are
represented just with strings.  However, enough hooks are left to implement
categories differently per-port (e.g. as types), without need to patch each
and every usage.
2019-01-31 16:48:30 +11:00
Paul Sokolovsky 5a91fce9f8 py/objstr: Make str.count() method configurable.
Configurable via MICROPY_PY_BUILTINS_STR_COUNT.  Default is enabled.
Disabled for bare-arm, minimal, unix-minimal and zephyr ports.  Disabling
it saves 408 bytes on x86.
2018-10-22 22:49:05 +11:00
Paul Sokolovsky 0bce110872 zephyr/CMakeLists: Update for latest Zephyr CMake usage refactorings.
Added cmake_minimum_required and updated target_link_libraries directives.
2018-09-14 13:21:13 +10:00
Paul Sokolovsky ed1a5bc88e zephyr/prj_base.conf: Update for net_config subsys refactor.
net_config subsystem was split off from net_app, and as a result, settings
need renaming from CONFIG_NET_APP_* to CONFIG_NET_CONFIG_*.
2018-09-14 13:21:13 +10:00
Damien George 05e0103e9e zephyr: Rename CONFIG_CONSOLE_PULL to CONFIG_CONSOLE_SUBSYS.
Following a similar change in the Zephyr Project.
2018-06-27 15:33:59 +10:00
Paul Sokolovsky 735358bcf4 zephyr/prj_qemu_x86.conf: Remove outdated CONFIG_RAM_SIZE.
Target RAM size is no longer set using Kconfig options, but instead using
DTS (device tree config). Fortunately, the default is now set to a high
value, so we don't need to use DTS fixup.
2018-06-27 14:59:17 +10:00
Paul Sokolovsky 543352ac21 zephyr/prj_base.conf: Remove outdated CONFIG_NET_NBUF_RX_COUNT option.
CONFIG_NET_NBUF_RX_COUNT no longer exists in Zephyr, for a while. That
means we build with the default RX buf count for a while too, and it works,
so just remove it (instead of switching to what it was renamed to,
CONFIG_NET_PKT_RX_COUNT).
2018-06-27 14:58:54 +10:00
Paul Sokolovsky 478410b409 zephyr/Makefile: Add kobj_types_h_target to Z_EXPORTS.
New generated Zephyr header file, without it build breaks.
2018-05-21 10:35:16 +10:00
Paul Sokolovsky 5a023372df zephyr: Add prj_disco_l475_iot1.conf with sensor drivers. 2018-05-21 10:35:16 +10:00
Paul Sokolovsky 7afbc49863 zephyr/prj_base.conf: Enable DHCP and group static IPs together.
Add CONFIG_NET_DHCPV4, which, after
https://github.com/zephyrproject-rtos/zephyr/pull/5750 works as follows:
static addresses are configured after boot, and DHCP requests are sent
at the same time. If valid DHCP reply is received, it overrides static
addresses.

This setup works out of the box for both direct connection to a
workstation (DHCP server usually is not available) and for connection
to a router (DHCP is available and required).
2018-05-21 10:35:16 +10:00
Paul Sokolovsky 0e52ee957d zephyr/modzsensor: Zephyr sensor subsystem bindings. 2018-05-21 10:35:16 +10:00
Paul Sokolovsky 080b0be1c8 zephyr/mpconfigport.h: Enable uhashlib and ubinascii modules.
To be able to use data integrity checks in various tests.
2018-05-21 10:35:16 +10:00
Paul Sokolovsky 9480c188e8 zephyr/main: After builtin testsuite, drop to REPL.
It makes sense to make even testsuite-enabled builds be suitable for
interactive use.
2018-05-21 10:35:16 +10:00