Skip to content

Commit 50e8e28

Browse files
committed
zephyr/Makefile: Add minimal port.
1 parent f59465d commit 50e8e28

4 files changed

Lines changed: 116 additions & 1 deletion

File tree

zephyr/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SRC_QSTR += $(SRC_C)
5454
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
5555

5656
CFLAGS = $(KBUILD_CFLAGS) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \
57-
-std=gnu99 -DNDEBUG -DMICROPY_HEAP_SIZE=$(MICROPY_HEAP_SIZE) $(INC)
57+
-std=gnu99 -DNDEBUG -DMICROPY_HEAP_SIZE=$(MICROPY_HEAP_SIZE) $(CFLAGS_EXTRA) $(INC)
5858

5959
include ../py/mkrules.mk
6060

@@ -83,6 +83,9 @@ $(Z_SYSGEN_H):
8383
rm -f $(LIBMICROPYTHON)
8484
-$(MAKE) -f Makefile.zephyr BOARD=$(BOARD) CONF_FILE=$(CONF_FILE)
8585

86+
minimal:
87+
$(MAKE) BOARD=$(BOARD) CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' FROZEN_DIR=
88+
8689
# Clean Zephyr things too
8790
clean: z_clean
8891

zephyr/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,22 @@ starts from 0). You will need to adjust it for another board (using board's
7474
reference materials). To execute the above sample, copy it to clipboard, in
7575
MicroPython REPL enter "paste mode" using Ctrl+E, paste clipboard, press
7676
Ctrl+D to finish paste mode and start execution.
77+
78+
79+
Minimal build
80+
-------------
81+
82+
MicroPython is committed to maintain minimal binary size for Zephyr port
83+
below 128KB, as long as Zephyr project is committed to maintain stable
84+
minimal size of their kernel (which they appear to be). Note that at such
85+
size, there is no support for any Zephyr features beyond REPL over UART,
86+
and only very minimal set of builtin Python modules. Thus, this build
87+
is more suitable for code size control and quick demonstrations even on
88+
smaller systems. It's also suitable for careful enabling of features one
89+
by one to achieve needed functionality and code size. This is in contrast
90+
to the "default" build, which may get more and more features enabled by
91+
default over time.
92+
93+
To make a minimal build:
94+
95+
make BOARD=<board> minimal

zephyr/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ int real_main(void) {
7272
#endif
7373
mp_init();
7474
MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
75+
#if MICROPY_MODULE_FROZEN
7576
pyexec_frozen_module("main.py");
77+
#endif
7678
#if MICROPY_REPL_EVENT_DRIVEN
7779
pyexec_event_repl_init();
7880
for (;;) {

zephyr/mpconfigport_minimal.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Linaro Limited
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#include <alloca.h>
27+
28+
// Include Zephyr's autoconf.h, which should be made first by Zephyr makefiles
29+
#include "autoconf.h"
30+
31+
// Usually passed from Makefile
32+
#ifndef MICROPY_HEAP_SIZE
33+
#define MICROPY_HEAP_SIZE (16 * 1024)
34+
#endif
35+
36+
#define MICROPY_STACK_CHECK (1)
37+
#define MICROPY_ENABLE_GC (1)
38+
#define MICROPY_HELPER_REPL (1)
39+
#define MICROPY_REPL_AUTO_INDENT (1)
40+
#define MICROPY_CPYTHON_COMPAT (0)
41+
#define MICROPY_PY_ASYNC_AWAIT (0)
42+
#define MICROPY_PY_ATTRTUPLE (0)
43+
#define MICROPY_PY_BUILTINS_ENUMERATE (0)
44+
#define MICROPY_PY_BUILTINS_FILTER (0)
45+
#define MICROPY_PY_BUILTINS_MIN_MAX (0)
46+
#define MICROPY_PY_BUILTINS_PROPERTY (0)
47+
#define MICROPY_PY_BUILTINS_RANGE_ATTRS (0)
48+
#define MICROPY_PY_BUILTINS_REVERSED (0)
49+
#define MICROPY_PY_BUILTINS_SET (0)
50+
#define MICROPY_PY_BUILTINS_SLICE (0)
51+
#define MICROPY_PY_ARRAY (0)
52+
#define MICROPY_PY_COLLECTIONS (0)
53+
#define MICROPY_PY_CMATH (0)
54+
#define MICROPY_PY_IO (0)
55+
#define MICROPY_PY_STRUCT (0)
56+
#define MICROPY_PY_SYS_MODULES (0)
57+
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
58+
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
59+
#define MICROPY_PY_BUILTINS_COMPLEX (0)
60+
61+
// Saving extra crumbs to make sure binary fits in 128K
62+
#define MICROPY_COMP_CONST_FOLDING (0)
63+
#define MICROPY_COMP_CONST (0)
64+
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (0)
65+
66+
#ifdef CONFIG_BOARD
67+
#define MICROPY_HW_BOARD_NAME "zephyr-" CONFIG_BOARD
68+
#else
69+
#define MICROPY_HW_BOARD_NAME "zephyr-generic"
70+
#endif
71+
72+
#ifdef CONFIG_SOC
73+
#define MICROPY_HW_MCU_NAME CONFIG_SOC
74+
#else
75+
#define MICROPY_HW_MCU_NAME "unknown-cpu"
76+
#endif
77+
78+
typedef int mp_int_t; // must be pointer size
79+
typedef unsigned mp_uint_t; // must be pointer size
80+
81+
typedef void *machine_ptr_t; // must be of pointer size
82+
typedef const void *machine_const_ptr_t; // must be of pointer size
83+
typedef long mp_off_t;
84+
85+
#define BYTES_PER_WORD (sizeof(mp_int_t))
86+
87+
#define MP_STATE_PORT MP_STATE_VM
88+
89+
#define MICROPY_PORT_ROOT_POINTERS \
90+
mp_obj_t mp_kbd_exception; \
91+
const char *readline_hist[8];

0 commit comments

Comments
 (0)