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

interpreters/micropython: Add Micropython support to NuttX (WIP) #840

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions interpreters/micropython/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

micropython*
49 changes: 49 additions & 0 deletions interpreters/micropython/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

menuconfig 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

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

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
23 changes: 23 additions & 0 deletions interpreters/micropython/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# interpreters/micropython/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
endif
81 changes: 81 additions & 0 deletions interpreters/micropython/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
############################################################################
# interpreters/micropython/Makefile
#
# 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

MPY_DIR = micropython
MPY_PORT_DIR = $(MPY_DIR)/ports/unix
MPY_PORT_VARIANT_DIR = $(MPY_PORT_DIR)/variants/nuttx

UNAME_S := NuttX
PROGNAME = micropython
PRIORITY = $(CONFIG_INTERPRETERS_MICROPYTHON_PRIORITY)
STACKSIZE = $(CONFIG_INTERPRETERS_MICROPYTHON_STACKSIZE)
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

# 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
$(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 $(MPY_OVERRIDES)
$(CROSSDEV)ar -x $(MPY_PORT_DIR)/libmicropython.a

context:: micropython_make

clean::
$(Q) test ! -d $(MPY_PORT_DIR) || make -C $(MPY_PORT_DIR) clean VARIANT=nuttx

distclean::
$(call DELDIR, micropython)

# doesn't work for some reason
#$(MPY_PORT_DIR)/libmicropython.a: micropython

include $(APPDIR)/Application.mk