From 23af383f199530529f9009a74877833b07c863a3 Mon Sep 17 00:00:00 2001 From: McKay Ransom Date: Fri, 18 Jun 2021 20:10:46 -0600 Subject: [PATCH 1/4] interpreters/micropython: Add support for Micorpython interpreter --- Application.mk | 2 +- interpreters/micropython/Kconfig | 22 ++++++++ interpreters/micropython/Make.defs | 30 ++++++++++ interpreters/micropython/Makefile | 90 ++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 interpreters/micropython/Kconfig create mode 100644 interpreters/micropython/Make.defs create mode 100644 interpreters/micropython/Makefile diff --git a/Application.mk b/Application.mk index d592d4dbdce..d3ad254805d 100644 --- a/Application.mk +++ b/Application.mk @@ -84,7 +84,7 @@ MAINCXXOBJ = $(MAINCXXSRCS:=$(SUFFIX)$(OBJEXT)) MAINCOBJ = $(MAINCSRCS:=$(SUFFIX)$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC) -OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) +OBJS += $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) ifneq ($(BUILD_MODULE),y) OBJS += $(MAINCOBJ) $(MAINCXXOBJ) diff --git a/interpreters/micropython/Kconfig b/interpreters/micropython/Kconfig new file mode 100644 index 00000000000..2ea6b5468c9 --- /dev/null +++ b/interpreters/micropython/Kconfig @@ -0,0 +1,22 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config INTERPRETERS_MICROPYTHON + tristate "Micropython Interpreter" + default n + select SERIAL_TERMIOS + select ARCH_SETJMP_H + +if INTERPRETERS_MICROPYTHON + +config INTERPRETERS_MICROPYTHON_PRIORITY + int "Micropython interpreter priority" + default 100 + +config INTERPRETERS_MICROPYTHON_STACKSIZE + int "Micropython interpreter stack size" + default 8192 + +endif diff --git a/interpreters/micropython/Make.defs b/interpreters/micropython/Make.defs new file mode 100644 index 00000000000..7477ed92b51 --- /dev/null +++ b/interpreters/micropython/Make.defs @@ -0,0 +1,30 @@ +############################################################################ +# interpreters/duktape/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifneq ($(CONFIG_INTERPRETERS_MICROPYTHON),) +CONFIGURED_APPS += $(APPDIR)/interpreters/micropython + +# It allows `` import. +# CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + # $(APPDIR)/interpreters/duktape/duktape/src-noline} +# CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + # $(APPDIR)/interpreters/duktape/duktape/src-noline} + +endif diff --git a/interpreters/micropython/Makefile b/interpreters/micropython/Makefile new file mode 100644 index 00000000000..17adf76c697 --- /dev/null +++ b/interpreters/micropython/Makefile @@ -0,0 +1,90 @@ +############################################################################ +# interpreters/micropython +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +#DUKTAPE_VERSION = 2.5.0 +#DUKTAPE_UNPACK = duktape +#DUKTAPE_TARBALL = duktape-$(DUKTAPE_VERSION).tar.xz +#DUKTAPE_URL_BASE = https://github.com/svaarala/duktape/releases/download/ +#DUKTAPE_URL = $(DUKTAPE_URL_BASE)v$(DUKTAPE_VERSION)/$(DUKTAPE_TARBALL) + +MPY_DIR = ../../../micropython +MPY_PORT_DIR = $(MPY_DIR)/ports/unix +MPY_PORT_VARIANT_DIR = $(MPY_PORT_DIR)/variants/nuttx +#TOP = $(MICROPYTHON_DIR) +BUILD=$(MPY_PORT_DIR)/build-nuttx + +#include $(MICROPYTHON_DIR)/py/mkenv.mk + +#include $(APP_MICROPYTHON_DIR)/Makefile +#$(MAKE) -C $(APP_MICROPYTHON_DIR) +#include $(MICROPYTHON_UNIX_DIR)/variants/minimal/mpconfigvariant.mk + +UNAME_S := NuttX +PROGNAME = micropython +PRIORITY = $(CONFIG_INTERPRETERS_MICROPYTHON_PRIORITY) +STACKSIZE = $(CONFIG_INTERPRETERS_MICROPYTHON_STACKSIZE) +MODULE = $(CONFIG_INTERPRETERS_MICROPYTHON) + + +####################################### +# BEGIN MICROPYTHON MAKE +####################################### + + +VPATH += \ + $(MPY_PORT_DIR) + +INC += -I$(MPY_PORT_DIR) \ + -I$(MPY_PORT_VARIANT_DIR) \ + -I$(TOP) \ + -I$(BUILD) \ + +CFLAGS += $(INC) + +OBJS += $(wildcard *.o) + +#MAINSRC = main.c + +CFLAGS += -Wno-undef + +export CFLAGS + +#ifneq ($(CONFIG_NET),y) # DOESN'T override so does nothing +#export MICROPY_PY_SOCKET = 0 +#endif + +.PHONY: micropython +micropython: + @echo "Calling MPY Make" + $(MAKE) -C $(MPY_PORT_DIR) lib VARIANT=nuttx CROSS_COMPILE=$(CROSSDEV) PROG="" \ + MICROPY_PY_SOCKET=0 MICROPY_SSL_AXTLS=0 MICROPY_PY_USSL=0 + $(CROSSDEV)ar -x $(MPY_PORT_DIR)/libmicropython.a + +context:: micropython + +#$(MPY_PORT_DIR)/libmicropython.a: micropython + +##################################### +# END MICROPYTHON MAKE +##################################### + +include $(APPDIR)/Application.mk From f28d920748391b801ee4c5602fc3fabb1cea061a Mon Sep 17 00:00:00 2001 From: McKay Ransom Date: Fri, 20 Aug 2021 16:26:45 -0600 Subject: [PATCH 2/4] Makefile working with github and add gitignore --- interpreters/micropython/.gitignore | 2 ++ interpreters/micropython/Makefile | 49 +++++++++++------------------ 2 files changed, 21 insertions(+), 30 deletions(-) create mode 100644 interpreters/micropython/.gitignore diff --git a/interpreters/micropython/.gitignore b/interpreters/micropython/.gitignore new file mode 100644 index 00000000000..7ee19ad8965 --- /dev/null +++ b/interpreters/micropython/.gitignore @@ -0,0 +1,2 @@ + +micropython* diff --git a/interpreters/micropython/Makefile b/interpreters/micropython/Makefile index 17adf76c697..dc6dac6cb05 100644 --- a/interpreters/micropython/Makefile +++ b/interpreters/micropython/Makefile @@ -26,65 +26,54 @@ include $(APPDIR)/Make.defs #DUKTAPE_URL_BASE = https://github.com/svaarala/duktape/releases/download/ #DUKTAPE_URL = $(DUKTAPE_URL_BASE)v$(DUKTAPE_VERSION)/$(DUKTAPE_TARBALL) -MPY_DIR = ../../../micropython +MPY_DIR = micropython MPY_PORT_DIR = $(MPY_DIR)/ports/unix MPY_PORT_VARIANT_DIR = $(MPY_PORT_DIR)/variants/nuttx #TOP = $(MICROPYTHON_DIR) -BUILD=$(MPY_PORT_DIR)/build-nuttx +#BUILD=$(MPY_PORT_DIR)/build-nuttx #include $(MICROPYTHON_DIR)/py/mkenv.mk -#include $(APP_MICROPYTHON_DIR)/Makefile -#$(MAKE) -C $(APP_MICROPYTHON_DIR) -#include $(MICROPYTHON_UNIX_DIR)/variants/minimal/mpconfigvariant.mk - UNAME_S := NuttX PROGNAME = micropython PRIORITY = $(CONFIG_INTERPRETERS_MICROPYTHON_PRIORITY) STACKSIZE = $(CONFIG_INTERPRETERS_MICROPYTHON_STACKSIZE) MODULE = $(CONFIG_INTERPRETERS_MICROPYTHON) - -####################################### -# BEGIN MICROPYTHON MAKE -####################################### - - -VPATH += \ - $(MPY_PORT_DIR) - -INC += -I$(MPY_PORT_DIR) \ - -I$(MPY_PORT_VARIANT_DIR) \ - -I$(TOP) \ - -I$(BUILD) \ - -CFLAGS += $(INC) - OBJS += $(wildcard *.o) -#MAINSRC = main.c - CFLAGS += -Wno-undef +# Micropython will use the CFLAGS that we export export CFLAGS #ifneq ($(CONFIG_NET),y) # DOESN'T override so does nothing #export MICROPY_PY_SOCKET = 0 #endif -.PHONY: micropython micropython: + $(Q) git clone https://github.com/mransom-campbell/micropython.git -b nuttx + $(MAKE) -C $(MPY_PORT_DIR) submodules VARIANT=nuttx + # build mpy-cross + $(MAKE) -C $(MPY_DIR)/mpy-cross + + +.PHONY: micropython_make +micropython_make: micropython @echo "Calling MPY Make" $(MAKE) -C $(MPY_PORT_DIR) lib VARIANT=nuttx CROSS_COMPILE=$(CROSSDEV) PROG="" \ MICROPY_PY_SOCKET=0 MICROPY_SSL_AXTLS=0 MICROPY_PY_USSL=0 + $(CROSSDEV)ar -x $(MPY_PORT_DIR)/libmicropython.a -context:: micropython +context:: micropython_make -#$(MPY_PORT_DIR)/libmicropython.a: micropython +clean:: + $(Q) test ! -d $(MPY_PORT_DIR) || make -C $(MPY_PORT_DIR) clean VARIANT=nuttx + +distclean:: + $(call DELDIR, micropython) -##################################### -# END MICROPYTHON MAKE -##################################### +#$(MPY_PORT_DIR)/libmicropython.a: micropython include $(APPDIR)/Application.mk From aa6a0b1afccf1ffe3826ea4fd9858757fd30a784 Mon Sep 17 00:00:00 2001 From: McKay Ransom Date: Tue, 24 Aug 2021 11:41:55 -0600 Subject: [PATCH 3/4] config and Makefile cleanup --- interpreters/micropython/Kconfig | 24 +++++++++++++++++++-- interpreters/micropython/Make.defs | 9 +------- interpreters/micropython/Makefile | 34 +++++++++++++++--------------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/interpreters/micropython/Kconfig b/interpreters/micropython/Kconfig index 2ea6b5468c9..4d1d909a7c9 100644 --- a/interpreters/micropython/Kconfig +++ b/interpreters/micropython/Kconfig @@ -3,7 +3,7 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -config INTERPRETERS_MICROPYTHON +menuconfig INTERPRETERS_MICROPYTHON tristate "Micropython Interpreter" default n select SERIAL_TERMIOS @@ -19,4 +19,24 @@ config INTERPRETERS_MICROPYTHON_STACKSIZE int "Micropython interpreter stack size" default 8192 -endif +config INTERPRETERS_MICROPYTHON_SOCKET + bool "Enable Micropython sockets" + default n + +config INTERPRETERS_MICROPYTHON_USSL + bool "Enable Micropython encryption" + default n + +if INTERPRETERS_MICROPYTHON_USSL + +config INTERPRETERS_MICROPYTHON_MBEDTLS + bool "Switch to MBEDTLS library for Micropython encryption" + default n + ---help--- + By default Micropython uses the AXTLS library uses less code space but + does not support all modern algorithms + The MBEDTLS library supports more algorithms but takes lots of code space + +endif # INTERPRETERS_MICROPYTHON_USSL + +endif # INTERPRETERS_MICROPYTHON diff --git a/interpreters/micropython/Make.defs b/interpreters/micropython/Make.defs index 7477ed92b51..c01298ceb70 100644 --- a/interpreters/micropython/Make.defs +++ b/interpreters/micropython/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# interpreters/duktape/Make.defs +# interpreters/micropython/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -20,11 +20,4 @@ ifneq ($(CONFIG_INTERPRETERS_MICROPYTHON),) CONFIGURED_APPS += $(APPDIR)/interpreters/micropython - -# It allows `` import. -# CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ - # $(APPDIR)/interpreters/duktape/duktape/src-noline} -# CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ - # $(APPDIR)/interpreters/duktape/duktape/src-noline} - endif diff --git a/interpreters/micropython/Makefile b/interpreters/micropython/Makefile index dc6dac6cb05..26ac7526039 100644 --- a/interpreters/micropython/Makefile +++ b/interpreters/micropython/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# interpreters/micropython +# interpreters/micropython/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -20,19 +20,9 @@ include $(APPDIR)/Make.defs -#DUKTAPE_VERSION = 2.5.0 -#DUKTAPE_UNPACK = duktape -#DUKTAPE_TARBALL = duktape-$(DUKTAPE_VERSION).tar.xz -#DUKTAPE_URL_BASE = https://github.com/svaarala/duktape/releases/download/ -#DUKTAPE_URL = $(DUKTAPE_URL_BASE)v$(DUKTAPE_VERSION)/$(DUKTAPE_TARBALL) - MPY_DIR = micropython MPY_PORT_DIR = $(MPY_DIR)/ports/unix MPY_PORT_VARIANT_DIR = $(MPY_PORT_DIR)/variants/nuttx -#TOP = $(MICROPYTHON_DIR) -#BUILD=$(MPY_PORT_DIR)/build-nuttx - -#include $(MICROPYTHON_DIR)/py/mkenv.mk UNAME_S := NuttX PROGNAME = micropython @@ -47,9 +37,20 @@ CFLAGS += -Wno-undef # Micropython will use the CFLAGS that we export export CFLAGS -#ifneq ($(CONFIG_NET),y) # DOESN'T override so does nothing -#export MICROPY_PY_SOCKET = 0 -#endif +# Tell micropython to use the correct compiler +MPY_OVERRIDES = "CROSS_COMPILE=$(CROSSDEV)" + +ifneq ($(CONFIG_INTERPRETERS_MICROPYTHON_SOCKET),y) +MPY_OVERRIDES += "MICROPY_PY_SOCKET=0" +endif + +ifeq ($(CONFIG_INTERPRETERS_MICROPYTHON_USSL),y) +ifeq ($(CONFIG_INTERPRETERS_MICROPYTHON_MBEDTLS),y) +MPY_OVERRIDES += "MICROPY_PY_MBEDTLS=1" +endif +else +MPY_OVERRIDES += "MICROPY_PY_USSL=0" +endif micropython: $(Q) git clone https://github.com/mransom-campbell/micropython.git -b nuttx @@ -61,9 +62,7 @@ micropython: .PHONY: micropython_make micropython_make: micropython @echo "Calling MPY Make" - $(MAKE) -C $(MPY_PORT_DIR) lib VARIANT=nuttx CROSS_COMPILE=$(CROSSDEV) PROG="" \ - MICROPY_PY_SOCKET=0 MICROPY_SSL_AXTLS=0 MICROPY_PY_USSL=0 - + $(MAKE) -C $(MPY_PORT_DIR) lib VARIANT=nuttx $(MPY_OVERRIDES) $(CROSSDEV)ar -x $(MPY_PORT_DIR)/libmicropython.a context:: micropython_make @@ -74,6 +73,7 @@ clean:: distclean:: $(call DELDIR, micropython) +# doesn't work for some reason #$(MPY_PORT_DIR)/libmicropython.a: micropython include $(APPDIR)/Application.mk From 787ac90600c28b0edd52067e8a21a54635459f4e Mon Sep 17 00:00:00 2001 From: McKay Ransom Date: Thu, 9 Sep 2021 11:56:20 -0600 Subject: [PATCH 4/4] Micropython config updates and cleanup --- interpreters/micropython/Kconfig | 7 +++++++ interpreters/micropython/Makefile | 2 ++ 2 files changed, 9 insertions(+) diff --git a/interpreters/micropython/Kconfig b/interpreters/micropython/Kconfig index 4d1d909a7c9..f6922e7fa81 100644 --- a/interpreters/micropython/Kconfig +++ b/interpreters/micropython/Kconfig @@ -19,6 +19,13 @@ config INTERPRETERS_MICROPYTHON_STACKSIZE int "Micropython interpreter stack size" default 8192 +config INTERPRETERS_MICROPYTHON_HEAPSIZE + int "Micropython interpreter default heap size" + default 65536 + ---help--- + Default heapsize of Micropython. Heapsize can be overriden on the command line. + + config INTERPRETERS_MICROPYTHON_SOCKET bool "Enable Micropython sockets" default n diff --git a/interpreters/micropython/Makefile b/interpreters/micropython/Makefile index 26ac7526039..44873dc29cd 100644 --- a/interpreters/micropython/Makefile +++ b/interpreters/micropython/Makefile @@ -33,6 +33,8 @@ MODULE = $(CONFIG_INTERPRETERS_MICROPYTHON) OBJS += $(wildcard *.o) CFLAGS += -Wno-undef +CFLAGS += -DMICROPY_UNIX_STACKLIMIT=$(CONFIG_INTERPRETERS_MICROPYTHON_STACKSIZE) +CFLAGS += -DMICROPY_UNIX_DEFAULT_HEAPSIZE=$(CONFIG_INTERPRETERS_MICROPYTHON_HEAPSIZE) # Micropython will use the CFLAGS that we export export CFLAGS