Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

WIP: feat: rubble-nrf51/nRF51 support #59

Closed
wants to merge 10 commits into from

Conversation

fmckeogh
Copy link
Collaborator

@fmckeogh fmckeogh commented May 10, 2019

Closes #25.

Following must be complete before we can merge:

@fmckeogh fmckeogh changed the title Feat: rubble-nrf51/nRF51 support WIP: feat: rubble-nrf51/nRF51 support May 10, 2019
Copy link
Owner

@jonas-schievink jonas-schievink left a comment

Choose a reason for hiding this comment

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

Looks pretty good, nice to support these chips again! Would be nice to share more code between the nrf51 and nrf52 implementations though :/

rubble-nrf51/src/lib.rs Outdated Show resolved Hide resolved
rubble-nrf51/src/timer.rs Show resolved Hide resolved
rubble/src/lib.rs Outdated Show resolved Hide resolved
rubble/Cargo.toml Outdated Show resolved Hide resolved
rubble-nrf51/src/timer.rs Outdated Show resolved Hide resolved
rubble-nrf51/src/timer.rs Outdated Show resolved Hide resolved
@jonas-schievink
Copy link
Owner

Another thing to do before merging: Test the demo on actual nRF51 hardware, making sure that connection and service enumeration works.

@fmckeogh
Copy link
Collaborator Author

fmckeogh commented Jun 11, 2019

Another thing to do before merging: Test the demo on actual nRF51 hardware, making sure that connection and service enumeration works.

Doing that now, CI should also be testing that it builds on thumbv6 targets

@jonas-schievink jonas-schievink added area: hal Code Area: Radio hardware interfacing code hardware: nordic Things specific to Nordic nRF5x devices status: blocked Blocked on other work (either another issue in this repo, or work in another repo) labels Jun 12, 2019
@fmckeogh
Copy link
Collaborator Author

So I modified the demo slightly for the nRF51, rubble-demo-nrf51.

There appear to be 2 issues.

The first is that logging does not appear to be working. Serial works, as <<< INIT >>> appears, but this line is never called.

The second is that connecting hangs, but due to issue number 1, I don't really know how to go about diagnosing it.

IMG_0286

IMG_0287

@jonas-schievink
Copy link
Owner

<< INIT >> is printed via semihosting, while the log messages use the UART

@fmckeogh
Copy link
Collaborator Author

fmckeogh commented Jun 13, 2019

Sorry I meant --- INIT ---, which gets printed after setting up the serial interface. Angle brackets INIT is printed over semihosting.

@jonas-schievink
Copy link
Owner

Maybe there's a bug in jamesmunns/bbqueue#27 that causes all data put in a bbqueue to get lost? Just a guess though.

@fmckeogh
Copy link
Collaborator Author

fmckeogh commented Jun 13, 2019

Removed all the cfg's for logging, and now I get:

--- INIT ---
INFO - Logger ready
6.025ms -

Progress?

Still appears in nRF connect, connecting still hangs.

@jonas-schievink
Copy link
Owner

I'm pretty sure all those Relaxed orderings aren't strong enough. heapless puts a compiler_fence with the correct ordering between all ops.

@fmckeogh
Copy link
Collaborator Author

But log::info!("Logger ready"); is working using the bbqueue? Or is it that one message could work, several would fail?

@fmckeogh
Copy link
Collaborator Author

I'll make those changes in my fork and see what happens :)

@jonas-schievink
Copy link
Owner

jonas-schievink commented Jun 13, 2019

Well, it would probably cause a data race and thus undefined behavior, so the program can do anything. How is the RAM usage? IIRC the log buffer is quite large. Do you have 32 or 16 KiB RAM on the chip? You could be running out of stack space.

EDIT: Okay, the incorrect atomics wouldn't immediately be UB on their own, but bbqueue also manages the queue memory unsafely, and I can see that blowing up when the atomics don't always work correctly.

@fmckeogh
Copy link
Collaborator Author

The nRF51822 I have has 32K RAM, 256K flash. Maybe I should try that stack size tool?

@jonas-schievink
Copy link
Owner

No, the nRF52810 we were using only has 24K of RAM, so it can't be that

@fmckeogh
Copy link
Collaborator Author

https://www.adafruit.com/product/2267

As of July 29th, 2015 we're selling an updated version with a black PCB and the nRF51822 module with 32KB of SRAM.

@fmckeogh
Copy link
Collaborator Author

Release build has interesting output:

Reading symbols from target/thumbv6m-none-eabi/release/rubble-demo-nrf51...
Target voltage: unknown
Available Targets:
No. Att Driver
 1      Nordic nRF51
0x0002d730 in ?? ()
Loading section .vector_table, size 0xa8 lma 0x0
Loading section .text, size 0xd97a lma 0xa8
Loading section .rodata, size 0x55c8 lma 0xda40
Loading section .data, size 0xc8 lma 0x13008
Start address 0xd9c8, load size 78002
Transfer rate: 26 KB/sec, 951 bytes/write.

<< INIT >>

panicked at 'called `Result::unwrap()` on an `Err` value: WouldBlock', src/libcore/result.rs:997:5

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0000ac6c in __bkpt ()
(gdb)

@fmckeogh
Copy link
Collaborator Author

<< INIT >>

panicked at 'there is no such thing as an acquire/release load', src/libcore/sync/atomic.rs:2127:19

????

https://doc.rust-lang.org/core/sync/atomic/enum.Ordering.html#variant.AcqRel

Has the effects of both Acquire and Release together: For loads it uses Acquire ordering. For stores it uses the Release ordering.

@jonas-schievink
Copy link
Owner

This ordering is only applicable for operations that combine both loads and stores.

@fmckeogh
Copy link
Collaborator Author

🤦‍♂

@fmckeogh
Copy link
Collaborator Author

--- INIT ---
INFO - Logger ready
6.037ms -

Putting compiler fences everywhere doesn't appeared to have worked :(

@jonas-schievink
Copy link
Owner

Hmm, then I'm not sure what could cause this. I do remember seeing this myself, however (on a nRF52810). Not sure why it happened or how it got fixed.

@jonas-schievink
Copy link
Owner

The advertisement is showing up continuously though? Then there's definitely something wrong with the log queue not being filled/drained properly (once it's full it should panic). Or is the UART going silent?

@fmckeogh
Copy link
Collaborator Author

Updated to log 0.4.7 after Jonas's changes were merged :)

@jonas-schievink
Copy link
Owner

Superseded by #97

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: hal Code Area: Radio hardware interfacing code hardware: nordic Things specific to Nordic nRF5x devices status: blocked Blocked on other work (either another issue in this repo, or work in another repo)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support nRF51/thumbv6 targets (again)
2 participants