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

Running RF24 library on Orange PI #146

Closed
mtiutiu opened this issue Oct 15, 2015 · 2 comments
Closed

Running RF24 library on Orange PI #146

mtiutiu opened this issue Oct 15, 2015 · 2 comments
Labels

Comments

@mtiutiu
Copy link

mtiutiu commented Oct 15, 2015

Hello,
I managed to run this library(which is really great btw) on a Orange PI device using an older branch with no issues at all. I used the BBB arch as a template with spidev as this matches perfectly with this board. After using the latest updates I noticed something strange happening: the spidev device is opened infinitely and the system runs out of file descriptors resulting in program crash after a while.

Now what I did to partially fix this issue was to make sure that in the init method for spi the file descriptor(if it's valid) gets closed before doing an open again.

Modified spi.cpp file from arch/BBB subfolder:

void SPI::init()
{
    int ret;

    // close fd if it's already open
    if(this->fd > 0) {
        close(this->fd);
    }

    this->fd = open(this->device.c_str(), O_RDWR);
    if (this->fd < 0)
    {
        perror("can't open device");
        abort();
    }
...

I guess that somewhere the spidev device is initialized again and again in some method from the library where it shouldn't be. I'm using the python wrapper in my application btw. I checked my application and I don't call the init method in an infinite loop so I'm assuming that there may be an implementation problem in the library - I see that the init method is called now at each spi transfer.

This is just a partial fix I would say as it doesn't really fix the root cause and I don't have too much time to investigate more. Maybe this will help someone with a similar issue or maybe it can be added as an enhancement to the library. As a side note: I'm not an experienced programmer and I'm still learning - this is my first issue published on github so please don't be too harsh on me:).

@TMRh20
Copy link
Member

TMRh20 commented Oct 16, 2015

this is my first issue published on github so please don't be too harsh on me

Hehe, specifically identifying the issue and providing a workaround is a pretty good first try.

Kind of sounds like a case of fix one thing break another. I have a feeling this issue is related to: #138

In short there seems to have been some changes to kernel driven SPI using spidev on RPi. I haven't been able to look into it further myself, but it looks like your workaround fixes the workaround I implemented for it initially...

TMRh20 added a commit that referenced this issue Oct 31, 2015
- For some reason, calling printf before cout results in a hang when
using SPIDEV with RPi
- Add fix for spidev per @mtiutiu #146 & #138
@TMRh20 TMRh20 added the bug label Oct 31, 2015
@TMRh20
Copy link
Member

TMRh20 commented Oct 31, 2015

Fix/workaround added to master branch, to be added in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants