From fcc485cc7ad0df7600f66cfcf86656a48096360f Mon Sep 17 00:00:00 2001 From: Matias N Date: Mon, 26 Oct 2020 14:54:46 -0300 Subject: [PATCH] nimBLE integration application/library --- wireless/bluetooth/nimble/.gitignore | 2 + wireless/bluetooth/nimble/Kconfig | 15 ++++++ wireless/bluetooth/nimble/Make.defs | 23 +++++++++ wireless/bluetooth/nimble/Makefile | 47 +++++++++++++++++ wireless/bluetooth/nimble/README.md | 75 ++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 wireless/bluetooth/nimble/.gitignore create mode 100644 wireless/bluetooth/nimble/Kconfig create mode 100644 wireless/bluetooth/nimble/Make.defs create mode 100644 wireless/bluetooth/nimble/Makefile create mode 100644 wireless/bluetooth/nimble/README.md diff --git a/wireless/bluetooth/nimble/.gitignore b/wireless/bluetooth/nimble/.gitignore new file mode 100644 index 000000000..e4a9a8ede --- /dev/null +++ b/wireless/bluetooth/nimble/.gitignore @@ -0,0 +1,2 @@ +/mynewt-nimble +/*.tar.gz diff --git a/wireless/bluetooth/nimble/Kconfig b/wireless/bluetooth/nimble/Kconfig new file mode 100644 index 000000000..1ace6b504 --- /dev/null +++ b/wireless/bluetooth/nimble/Kconfig @@ -0,0 +1,15 @@ +config NIMBLE + bool "Apache nimBLE (BLE host-layer)" + default n + depends on !WIRELESS_BLUETOOTH_HOST + ---help--- + Enable Apache nimBLE Bluetooth Low Energy + host-layer stack. + +if NIMBLE + config NIMBLE_REF + string "Version" + default "nuttx" + ---help--- + Git ref name to use when downloading from nimBLE repo +endif diff --git a/wireless/bluetooth/nimble/Make.defs b/wireless/bluetooth/nimble/Make.defs new file mode 100644 index 000000000..c3c321011 --- /dev/null +++ b/wireless/bluetooth/nimble/Make.defs @@ -0,0 +1,23 @@ +############################################################################ +# apps/wireless/bluetooth/nimble/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_NIMBLE),) +CONFIGURED_APPS += $(APPDIR)/wireless/bluetooth/nimble +endif diff --git a/wireless/bluetooth/nimble/Makefile b/wireless/bluetooth/nimble/Makefile new file mode 100644 index 000000000..1edef9b75 --- /dev/null +++ b/wireless/bluetooth/nimble/Makefile @@ -0,0 +1,47 @@ +############################################################################ +# apps/wireless/bluetooth/nimble/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 + +PRIORITY = 255 +STACKSIZE = 16384 + +NIMBLE_ROOT = $(APPDIR)/wireless/bluetooth/nimble/mynewt-nimble + +-include $(NIMBLE_ROOT)/porting/examples/nuttx/Make.defs + +NIMBLE_TAR := $(CONFIG_NIMBLE_REF).tar.gz +NIMBLE_URL := https://github.com/v01d/mynewt-nimble/archive/$(NIMBLE_TAR) + +$(NIMBLE_TAR): + wget $(NIMBLE_URL) -O $(NIMBLE_TAR) + +$(NIMBLE_ROOT): $(NIMBLE_TAR) + tar zxf $(NIMBLE_TAR) + mv mynewt-nimble-$(CONFIG_NIMBLE_REF) mynewt-nimble + +context:: $(NIMBLE_ROOT) + +distclean:: + $(call CLEAN,$(NIMBLE_TAR)) + $(call DELDIR,$(NIMBLE_ROOT)) + + +include $(APPDIR)/Application.mk diff --git a/wireless/bluetooth/nimble/README.md b/wireless/bluetooth/nimble/README.md new file mode 100644 index 000000000..70bcc86f3 --- /dev/null +++ b/wireless/bluetooth/nimble/README.md @@ -0,0 +1,75 @@ +# nimBLE for NuttX + +This application will build nimBLE stack (host-only) as a library/application +in NuttX. + +# Porting Layer + +nimBLE supports being built as part of different OS, not only their mynewt +RTOS. A porting layer was written for NuttX, which was mostly a copy of +the Linux porting layer. + +## Modifying the porting layer + +NuttX is supported in nimBLE by adding an entry in the porting layer +used to support different OSs. However, nimBLE supports each OS +by generating a configuration header (`syscfg.h`) from YAML configuration +files. If you want to modify the porting layer and change its configuration +you will need to regenerate this header. This process is a bit involved since +nimBLE uses its own `newt` build tool to do so and also somewhat assumes it will +be built for their mynewt OS, so it actually may fail to build completely but +it will still get to generate the required files. + +So, first is to get the newt tool: + + $ cd apps/nimble + $ git clone https://github.com/apache/mynewt-newt + $ cd mynewt-newt + +At the moment, you will probably require unstable version +instead of a release so select a known working: + + $ git checkout 0fcf17566c40 + $ ./build.sh + +There should be now a `newt` binary under `mynewt-newt/newt`. +Extend your path so that it is visible: + + $ export PATH=mynewt-newt/newt:$PATH + +Now, create a `newt` project: + + $ newt new foo + +We want latest master version of mynewt OS and stack, so edit +`foo/project.yml` and change the `vers` variable to `0.0.0`. Now +do + + $ cd foo/ + $ newt upgrade + +Under `foo/repos` there will be a clone of both mynewt and nimble +repo. Since this app already downloads nimble repo outside of `foo`, +you can delete `foo/repos/apache-mynewt-nimble` and simply make a +link to the `mynewt-nimble` directory, so that you can work on the +nimBLE code directly. + +Now you can make any changes to the `yml` files such as +`porting/targets/nuttx/syscfg.yml`. Finally, you can build with: + + $ newt build @apache-mynewt-nimble/porting/targets/nuttx + +This will most likely fail to complete but the generated headers +should be there. So now copy them to the appropriate location in +the `nuttx` target directory: + + $ cd foo/ + $ cp bin/@apache-mynewt-nimble/porting/targets/nuttx/generated/include/logcfg/logcfg.h \ + repos/apache-mynewt-nimble/porting/examples/nuttx/include/logcfg + $ cp bin/@apache-mynewt-nimble/porting/targets/nuttx/generated/include/syscfg/syscfg.h \ + repos/apache-mynewt-nimble/porting/examples/nuttx/include/syscfg + +If these changes are done to fix a problem with NuttX porting layer in nimBLE, you +should open a pull-request to nimBLE repository to include the updated header files. +It is recommended to mention the issue in NuttX mailing list first to ensure the change +is needed.