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

Bluetooth Low Energy #5

Closed
AhmedHussein534 opened this issue Feb 26, 2018 · 18 comments
Closed

Bluetooth Low Energy #5

AhmedHussein534 opened this issue Feb 26, 2018 · 18 comments
Labels
feature request New features of the framework, new peripheral models, boards etc

Comments

@AhmedHussein534
Copy link

AhmedHussein534 commented Feb 26, 2018

I have been trying to run the zephyr bluetooth samples but with no luck. Does renode support BLE peripheral?

@mgielda
Copy link
Member

mgielda commented Apr 11, 2018

Hi Ahmed, this is a matter of supporting a specific radio model for a given Bluetooth-enabled platform. Which Bluetooth platform (board/SoC) were you interested in specifically, and what sample would you like to run - could you describe the use case in more detail, this would help us with setting our priorities.

@AhmedHussein534
Copy link
Author

AhmedHussein534 commented Apr 12, 2018 via email

@mgielda
Copy link
Member

mgielda commented May 9, 2018

Hi Ahmed, we do not at this point support any Bluetooth peripherals, but it's definitely something we'd like to do if there is enough need for it. I'll mark this as a feature request.

@mgielda mgielda added the feature request New features of the framework, new peripheral models, boards etc label May 9, 2018
@mchodzikiewicz
Copy link

mchodzikiewicz commented Sep 23, 2019

Hi, I am interested in testing nrf52 as well but unfortunately not via Zephyr's bluetooth stack, but NRF SDK.

Since the bluetooth stack is a binary blob in nRF SDK, perhaps a way of work is to mock supervisor calls instead of actual peripheral beneath it?
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s02s07.html

Is it supported somehow? I guess it would enable Renode in the uglier projects, where you are dependent on vendor's impl

@Citrullin
Copy link

I am interested in this as well. Especially with the NimBLE stack.

@jain0nikhil
Copy link

Is Bluetooth peripheral support enable for nRF52840DK if yes, can you share some sample code?

@PiotrZierhoffer
Copy link
Member

@jain0nikhil while we do have the nRF52840 chip supported, it does not yet have radio connectivity.

@jain0nikhil
Copy link

@PiotrZierhoffer is there any plan for supporting Bluetooth Peripheral.
One more question: I am trying to run one custom FW on emulator in which FLASH changed to 0x27000 from 0x00 but nothing happen in emulator after loading binary. Do I need to specify some extra value for that ?

@jain0nikhil
Copy link

is there any board which support radio connectivity in renode which I can refer for adding support for nRF?

@PiotrZierhoffer
Copy link
Member

PiotrZierhoffer commented Feb 19, 2021

We have some 802.15.4 radios you can look at, for example CC2538 or CC2520. The communication layer will be similar, but we have no bt radios at the moment.

nRF52840 BT is not in the nearest scope, so I can't give you any specifics.

Regarding your other question: you need to adjust the flash location in the repl file and in your linker scripts. That's not enough information to say anything specific though.

@grifcj
Copy link

grifcj commented Oct 20, 2021

As of very recently, I was able to get a simulation going with zephyr on nrf52840 using the heart-rate samples and have a connection between a central and peripheral. See this PR in infrastructure repo. Wasn't sure if I could hijack this issue, or if I should open another one for that PR, given this seems to be about zephyr bluetooth samples with renode.

Haven't tried any soft-devices yet with renode, but ultimately would be interested in that too as a I have a few projects using them. However, to get simulations going, a completely open source implementation has been indispensable for education and troubleshooting. Was hoping that experience with zephyr might transfer well to simulations with soft-devices.

@grifcj
Copy link

grifcj commented Nov 5, 2021

Was able to get a softdevice-based peripheral advertising. Used the Nordic SDK 17.1.0 and SD 7.2.0. Based on the ble_app_hrs demo with some modifications to disable the security related features as peripheral models don't currently support. Quickly tried connection with the central from same example set, but that unfortunately didn't work.

Requires a few simple fixes to peripheral models, which I did on top of existing bluetooth PR here in branch bluetooth-softdevice. Wasn't sure if changes should stack on top of existing PR, as it might redundantly contain the existing PR's commits.

I attach the modified ble_app_hrs main.c and *.resc for reference. Can go in a bit more detail on building with that SDK or just supply the binaries if desired.
example.zip

One other important caveat is that simulation seems to need to run at 1 us quantum. Anything more, and the peripheral will advertise once, but then effectively halts with WFE as scheduling with timer0 gets messed up. Compare values to drive timer events seem to be somewhat aware of time passing.

Overall, trying to workout issues with no source code (i.e. just the soft device binary) is unsurprisingly a bit tricky. Given Nordic seems to be moving on to open source Zephyr based solutions for the future anyways, probably turn my attention to enabling more features (e.g. security) with that SDK.

Screenshot from 2021-11-05 01-06-58

@Citrullin
Copy link

Overall, trying to workout issues with no source code (i.e. just the soft device binary) is unsurprisingly a bit tricky. Given Nordic seems to be moving on to open source Zephyr based solutions for the future anyways, probably turn my attention to enabling more features (e.g. security) with that SDK.

If you have time you can give NimBLE a try. It is used as the BLE stack in RIOT and MyNewt. Espressif also uses a fork for their ESP32 with FreeRTOS. So, I guess you can also use it in FreeRTOS.

@grifcj
Copy link

grifcj commented Nov 7, 2021

Would like to cross-check models against another stack. So far, basics seem to work with zephyr and at least advertising with softdevice. If NimBLE hardware implementation is similar enough, it might already function as well.

Spent an hour or so with MyNewt, unfortunately wasn't able to get it to build an acceptable elf of the blehr sample in nimble repo targeting the nrf52840. Have any direction there? Didn't try RIOT. Perhaps have better luck with their getting started docs. Doesn't matter if RIOT or MyNewt, whichever one is easiest, but need some sample apps, preferably a central and peripheral that implements hr, like the sample apps for Zephyr.

With that, it could be assessed whether or not NimBLE functions on renode with the PR branch

Unfortunately, my time is limited for platform ramp up / education in near term. Would probably prefer spending effort in near term towards expanding out zephyr-based solutions since I already have a foothold there.

@Citrullin
Copy link

Citrullin commented Nov 8, 2021

Spent an hour or so with MyNewt, unfortunately wasn't able to get it to build an acceptable elf of the blehr sample in nimble repo targeting the nrf52840. Have any direction there? Didn't try RIOT. Perhaps have better luck with their getting started docs. Doesn't matter if RIOT or MyNewt, whichever one is easiest, but need some sample apps, preferably a central and peripheral that implements hr, like the sample apps for Zephyr.

I also don't have any experience with MyNewt. I can help you with RIOT though, if you want to. If you give me your contact, I can probably make some time in order to help you with this.
I only used the IPv6 over BLE stack though. But I guess if that works fine, the rest shouldn't be an issue.
I would recommend a Linux though. I tried to make it work on Windows, but it makes it very complicated to get it running due to the not proper USB support in WSL2. Mac also makes some issues in my experience. Linux (at least Debian based) is very straight forward, since the build system of RIOT is just a couple of Makefiles.
The RIOT documentation though... Let's say developer don't really like to write a lot of documentation, I guess :D
/e Ahh, I see in your screenshots you are already using a Linux. Judging from the background color, Ubuntu, I guess. So, that shouldn't be an issue to get it running.
I wrote this guide for the w3c wot wg once. Maybe that is a straight forward starting point. Not the most recent dev branch, but it should give you a good starting point, I think.
https://github.com/w3c/wot-testing/tree/main/events/2020.09.Online/prototypes/RIOT-OS
There are a lot of example which should work in a similar way
https://github.com/RIOT-OS/RIOT/tree/master/examples

If you point me into a direction how I can run the elf with the BLE implementation, I am happy to give it a try.

@grifcj
Copy link

grifcj commented Nov 9, 2021

Attempts with RIOT went a little better. Setting up was just cloning the repo, putting arm toolchain on path and calling make BOARD=nrf52840dk -C examples/nimble_heart_rate_sensor.

Screenshot from 2021-11-09 00-55-08

There was at least one issue in the RTC model. IRQ was being gated on event enable, and that's not how the hardware works as can be seen in the nrf52840 product spec, so that needs to be fixed and pushed to PR.

image

So advertising seems to work, but connection with central not quite working yet. Didn't see a central example in riot repo, so was just using the zephyr central to try to connect. Central sees advertising from riot peripheral, and sends a connect request, but things don't get established. Will have to investigate more.

If you'd like to try hacking some yourself, the build docs are here. Which is basically just install pre-reqs and run build.sh from cloned renode repo. The current bluetooth capabilities require build from source, since it's ongoing PR. You'll need the bluetooth-work branch from my forks of renode and renode-infrastructure.

Attaching script file I used. You would need to update paths to bins to where they are on your system.
bluetooth.zip

If that's way too brief to be of much use, you can try dropping me a line at grifcj@gmail.com.

@Citrullin
Copy link

If you'd like to try hacking some yourself, the build docs are here. Which is basically just install pre-reqs and run build.sh from cloned renode repo. The current bluetooth capabilities require build from source, since it's ongoing PR. You'll need the bluetooth-work branch from my forks of renode and renode-infrastructure.

Great that the build process works. I am not so much into the low level Bluetooth stack. I will give it eventually a try. Thanks for the pointer to the resources.

@PiotrZierhoffer
Copy link
Member

With the BLE support for nRF52840 we released (with enormous help from @grifcj) I believe I can close this issue. If any other issues related to BLE are encountered, let's track them separately

https://antmicro.com/blog/2022/04/developing-and-testing-ble-on-nrf52840-with-renode-and-zephyr/

alefminus pushed a commit to greenvibe-io/renode that referenced this issue Feb 8, 2024
radio not emulated well at all, but if we raise an interrupt we
can get progress:

#0  PowerCC26XX_standbyPolicy () at dpl/PowerCC26X2_nortos.c:104
renode#1  0x00004f10 in SemaphoreP_pend (handle=handle@entry=0x200006c8 <rfObject+80>, timeout=timeout@entry=4294967295) at dpl/SemaphoreP_nortos.c:234
renode#2  0x00003628 in RF_pendCmd (bmEvent=8070450532247928842, ch=1, h=0x20000678 <rfObject>) at /project/source/ti/drivers/rf/RFCC26X2_multiMode.c:5156
renode#3  RF_pendCmd (h=0x20000678 <rfObject>, ch=<optimized out>, bmEvent=<optimized out>) at /project/source/ti/drivers/rf/RFCC26X2_multiMode.c:5090
renode#4  0x0000104a in EasyLink_init (params=0x200056d0) at ../easylink/EasyLink_nortos.c:1081
renode#5  0x00000458 in mainThread (arg0=0x0 <resetVectors>) at ../rfEasyLinkEchoRx_nortos.c:138
renode#6  0x000015a2 in main () at ../main_nortos.c:61

waiting on "wfi" instruction

(machine-0) cpu DisassembleBlock 0x5a80
Executing: cpu DisassembleBlock 23168
0x00005a80:   8000      strh    r0, [r0]
0x00005a82:   bf30      wfi
0x00005a84:   f3af8000  nop.w
0x00005a88:   4628      mov     r0, r5

then issue
  sysbus.nvic SetPendingIRQ 1

oops - seems I just issued a reset ; not very helpful (can see localProgramStart symbol)

# causes continuation
sysbus.nvic Reset

Could not yet understand where to place a break point.

logFile @examples.log

 - does not capture the console interaction, so harder to understand at
   what point I injected an interrupt via the console.

some problem with ccTask, resulted in using dotnet build (add --net
everywhere).

but mono seems to be fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New features of the framework, new peripheral models, boards etc
Projects
None yet
Development

No branches or pull requests

7 participants