Skip to content

pkg/nimble: adapt to nrf51 family#11463

Merged
haukepetersen merged 4 commits into
RIOT-OS:masterfrom
aabadie:nimble_nrf51
Aug 7, 2019
Merged

pkg/nimble: adapt to nrf51 family#11463
haukepetersen merged 4 commits into
RIOT-OS:masterfrom
aabadie:nimble_nrf51

Conversation

@aabadie

@aabadie aabadie commented Apr 29, 2019

Copy link
Copy Markdown
Contributor

Contribution description

This PR is adapting the Nimble package to make it compliant with nrf51 based boards. For the moment it needs a specific branch on my Apache-nimble fork (see apache/mynewt-nimble#429). Some changes were applied on the upstream project, so the package version had to be updated.

I tested examples/nimble_gatt and it worked with nrf51dk. The examples/nimble_scanner doesn't work, maybe because of insufficient memory.

Testing procedure

Build and flash examples/nimble_gatt on an nrf51 based board. It should appear in NRF connect application running on a Phone or using bluetoothctl on a Linux with bluetooth radio enabled.

Issues/PRs references

None

@aabadie aabadie added Area: pkg Area: External package ports Area: BLE Area: Bluetooth Low Energy support labels Apr 29, 2019
@aabadie aabadie requested a review from haukepetersen April 29, 2019 09:16
@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 29, 2019
@haukepetersen

Copy link
Copy Markdown
Contributor

Nice one, wanted to do this for a while now :-)

See my review comments below.

@haukepetersen haukepetersen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just see a problem when (in the near future) building Nimble for non-Nordic platforms. But easy to fix...

Comment thread pkg/nimble/Makefile Outdated

nimble_drivers_nrf52:
"$(MAKE)" -C $(PDIR)/nimble/drivers/nrf52/src/ -f $(TDIR)/drivers.nrf52.mk
nimble_drivers:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave this as NRF specific submodule, as it is only valid for these CPUs at the moment. So how about nimble_drivers_nrf5x?!

Comment thread pkg/nimble/Makefile Outdated
PKG_NAME = nimble
PKG_URL = https://github.com/apache/mynewt-nimble.git
PKG_VERSION = a7b3c939146e735b59d55bff740c906bde6f86f9
PKG_VERSION = 976bb8f84bf9547efdea444ae79a62d5a355a613

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we merge #11273, this line should not be needed, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, because apache/mynewt-nimble@976bb8f was merged this morning so it's more recent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, didn't refresh my page. But the trouble with updating the version holds (see #11273). So I think it makes much sense to merge #11273 first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, this is not urgent.

Comment thread pkg/nimble/Makefile.dep Outdated
ifeq (nrf52,$(CPU_FAM))
USEMODULE += nimble_drivers_nrf52
endif
USEMODULE += nimble_drivers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't drop the ifdef, as the nimble_drivers submodule should only be included for nordic boards...

#endif

#ifdef MODULE_NIMBLE_CONTROLLER
#ifdef CPU_FAM_NRF52

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ifdef needs to stay, and simply be extended with the CPU_FAM_NRF51. Otherwise we get in trouble when building for non Nordic targets (in the future...).

@aabadie

aabadie commented Apr 29, 2019

Copy link
Copy Markdown
Contributor Author

Comments addressed, @haukepetersen !

@haukepetersen

Copy link
Copy Markdown
Contributor

Looks good! However, I would like to wait until the issues from #11273 are resolved. I will look into this, but also have a paper deadline next Friday with a slightly higher prio :-)

@aabadie

aabadie commented May 6, 2019

Copy link
Copy Markdown
Contributor Author

However, I would like to wait until the issues from #11273 are resolved.

No problem, there is no hurry.

I did some more testing on microbit and nrf51dk and there are problems:

  • microbit seems to crash at startup: no output displayed
  • nrf51dk appears in nRFConnect but the connection fails afterwards and I have to reset the board to see it again in the scan results.

@ghost

ghost commented May 17, 2019

Copy link
Copy Markdown

So, now that #11273 is merged, please rebase.

@aabadie

aabadie commented May 17, 2019

Copy link
Copy Markdown
Contributor Author

now that #11273 is merged, please rebase.

Done!

@ghost

ghost commented May 24, 2019

Copy link
Copy Markdown

I had multiple errors on calliope-mini (nRF51822). I got adviced by @haukepetersen on compiling.

  1. I tried compiling tests/nimble_l2cap but had overflow of 48kB. We tried to fit it in anyway by lowering APP_MTU ?= 1000, MYNEWT_VAL_MSYS_1_BLOCK_COUNT=7 and MYNEWT_VAL_MSYS_1_BLOCK_SIZE=110, but without success.
  2. I tried examples/nimble_gatt, it does compile and it fits, yet I was not able to connect to the calliope from my phone for unknown reason.

Sadly we dont have a nrf52dk here to verify this PR atm.

@ghost ghost self-requested a review May 24, 2019 08:46
@aabadie

aabadie commented May 24, 2019

Copy link
Copy Markdown
Contributor Author

Sadly we dont have a nrf52dk here to verify this PR atm.

Do you mean nrf51dk ? If yes try one on IoT-LAB :)

@ghost

ghost commented May 24, 2019

Copy link
Copy Markdown

Sadly we dont have a nrf52dk here to verify this PR atm.

Do you mean nrf51dk ? If yes try one on IoT-LAB :)

Yes, sorry for the confusion ;)

@janosbrodbeck

janosbrodbeck commented May 29, 2019

Copy link
Copy Markdown
Member

We found a problem with the xtimer module with this adaption. We used an airfy-beacon board (nrf51822) for testing.

xtimer functions without the nimble package are working properly. But if we just add the nimble pkg into our project/makefile xtimer does not work anymore.
xtimer_now_usec() returns 0 everytime.

xtimer_sleep therefore no longer behaves in a comprehensible way. Sometimes the device wakes up after a short time, sometimes it takes minutes or probably infinite .

nimble itself seems to work properly. Advertising, scanning works.

@haukepetersen

Copy link
Copy Markdown
Contributor

I can confirm the issue using the examples/nimble_scanner application for both microbit and calliope-mini. I re-checked the nimble configuration regarding timers, but couldn't find anything there: nimble's controller is using NRF_RTC0, while xtimer is using NRF_TIMER0, so no clash there.

This will need more investigation :-)

@haukepetersen

Copy link
Copy Markdown
Contributor

I might have found something interesting (still using the nimble_scanner example):
a) the perih timer 0 (used by xtimer) is stopped when the main() function is executed -> this should not be, so might be that Nimble disables it somehow()
b) enabling the periph timer manually (calling timer_start(0)), will allow to use xtimer_sleep() before starting the shell. But when calling e.g. the scan 100, the periph timer ends up triggering its ISR in an endless loop.

So it seems to me, that something regarding interrupt handling is clashing between RIOT and Nimble on the nrf51. So more debugging :-)

@haukepetersen

Copy link
Copy Markdown
Contributor

found it: Nimbles radio driver is also using NRF_TIMER0, hard-coded in nimble/drivers/nrf52/src/ble_phy.c. This explains of course, why both xtimer and Nimble are not working in parallel and the timer is disabled...

Quick fix: mapping xtimer to use timer 1 seems to fix the issue at hand. But caution: timer 1 runs in 16-bit mode, so one has to define custom values for all XTIMER_DEV, XTIMER_WIDTH, and XTIMER_CHAN.

So I guess we need to include some nimble specific xtimer configuration?!

@aabadie

aabadie commented May 29, 2019

Copy link
Copy Markdown
Contributor Author

Good catch @haukepetersen :)

Quick fix: mapping xtimer to use timer 1 seems to fix the issue at hand. But caution: timer 1 runs in 16-bit mode, so one has to define custom values for all XTIMER_DEV, XTIMER_WIDTH, and XTIMER_CHAN

All nrf51 based boards share the same xtimer defines (in board_common.h) and, except microbit and calliope-mini, the same timer peripherals configuration. So this is doable without too many changes. We could also have some conditional macros to use timer 1 if nimble pkg is loaded and timer 0 otherwise.

@haukepetersen

Copy link
Copy Markdown
Contributor

We could also have some conditional macros to use timer 1 if nimble pkg is loaded and timer 0 otherwise.

+1! I was thinking the same thing. We should just put a comment to it, stating that with nimble xtimer falls back to a 16-bit timer -> more wakeups...

@aabadie

aabadie commented Jun 3, 2019

Copy link
Copy Markdown
Contributor Author

I was thinking the same thing. We should just put a comment to it, stating that with nimble xtimer falls back to a 16-bit timer -> more wakeups...

Do you want this in another PR or I can just update this one ?

@haukepetersen

Copy link
Copy Markdown
Contributor

Do you want this in another PR or I can just update this one ?

Definitely in this PR. Wanted to PR something against your branch, but couldn't find the time so far. So just go ahead, I will happlily review it then :-)

@haukepetersen

Copy link
Copy Markdown
Contributor

I will look into refactoring the code accordingly right now, so please wait for a PR from my side before addressing this issue.

@janosbrodbeck

Copy link
Copy Markdown
Member

Well, I've found a new bug :)

The random module makes problem. Compiled together with the package nimble the board does not react anymore after flashing. Tested on airfy-beacon and nrf51dk (iotlab).

It works on nrf52dk!

@haukepetersen

Copy link
Copy Markdown
Contributor

@j-brodbeck the random module issue seems to be caused by both NimBLE and RIOT using the nRFs hwrng peripheral, interfering with each other. I have not looked into the complete details, but the solutions is probably somewhere in one of both falling back to using the other ones implementation...

So as roadmap for this PR I would like to proceed as follows:

@haukepetersen

Copy link
Copy Markdown
Contributor

Alright, all dependencies have been merged to nimble master and the nimble package version has been bumped -> #11949

@aabadie would you mind to rebase this PR?!

@aabadie

aabadie commented Aug 4, 2019

Copy link
Copy Markdown
Contributor Author

would you mind to rebase this PR?

Done :)

@haukepetersen haukepetersen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected and code looks good -> ACK

Note: so far, this PR does not enable the ble_nimble feature for any nrf51-based board. I think we should leave it like this and I/we can do this an a separate PR...

@haukepetersen haukepetersen added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Aug 5, 2019
@haukepetersen

Copy link
Copy Markdown
Contributor

oh, and please squash :-)

@aabadie

aabadie commented Aug 5, 2019

Copy link
Copy Markdown
Contributor Author

this PR does not enable the ble_nimble feature for any nrf51-based board

I'll update this PR otherwise the adaption for nrf51 is not built by Murdock for nrf51 based boards.

@haukepetersen

Copy link
Copy Markdown
Contributor

true, makes sense.

@haukepetersen

Copy link
Copy Markdown
Contributor

made a PR against your branch, fixing the nimble_l2cap test application. Maybe you have a better idea how to do this a little nicer? -> aabadie#13

@aabadie

aabadie commented Aug 7, 2019

Copy link
Copy Markdown
Contributor Author

@haukepetersen, I applied your commit directly, squashed and rebased. Let's now see how Murdock behaves.

@haukepetersen

Copy link
Copy Markdown
Contributor

thanks! Go Murdock, go :-)

@aabadie

aabadie commented Aug 7, 2019

Copy link
Copy Markdown
Contributor Author

It's all green @haukepetersen, ok to merge ?

@haukepetersen

Copy link
Copy Markdown
Contributor

yes. -> go :-)

@haukepetersen haukepetersen merged commit 4a75d0b into RIOT-OS:master Aug 7, 2019
@aabadie aabadie deleted the nimble_nrf51 branch August 8, 2019 18:45
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BLE Area: Bluetooth Low Energy support Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants