Coder Social home page Coder Social logo

mciupak / nrf24 Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 13.0 68 KB

nrf24l01 linux device driver

License: GNU General Public License v3.0

Makefile 0.62% C 99.04% Shell 0.34%
nrf24l01 linux nrf24 kernel-module device-driver kernel-driver module raspberry-pi rapsberrypi raspberry-pi-3 linux-kernel-module nordic

nrf24's Issues

Rasbian Setup

I'm not seeing any /dev devices created on a Raspberry Pi 3. Here are my installation steps and system. Any tips?

git clone https://github.com/mciupak/nrf24.git
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential raspberrypi-kernel-headers
sudo reboot
ln -s /usr/src/linux-headers-$(uname -r)/ linux
cd nrf24
make
../linux/scripts/dtc/dtc -@ -I dts -O dtb -o nrf24-spi0.dtbo devicetree/nrf24-spi0-overlay.dts
cp nrf24-spi0.dtbo /boot/overlays
sed -i "s/dtparam=spi=on/#dtparam=spi=on/" /boot/config.txt
echo "dtparam=nrf24-spi0-overlay" >> /boot/config.txt
sudo reboot
sudo insmod nrf24/nrf24.ko

uname -a:
Linux wgct 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

dmesg | tail:
[ 1574.700708] nrf24: loading out-of-tree module taints kernel.

cat /proc/modules:

nrf24 27901 0 - Live 0x7f032000 (O)
ftdi_sio 32963 0 - Live 0x7f01e000
usbserial 29943 1 ftdi_sio, Live 0x7f00f000
spi_bcm2835 7596 0 - Live 0x7f00a000
i2c_bcm2835 7167 1 - Live 0x7f005000
i2c_dev 6913 2 - Live 0x7f000000

Comunications with the driver

Hi mciupak, I'd like to use your driver for RF24 radios.
How can I communicate with the driver from a c program running in user space?
Do you have any example code?
Thanks, Andrea

Driver is constantly logging

Hi, there is another issue. After sending a simple packet using "echo "evwvnwoipvniowvwv" > /dev/nrf0.0" the driver starts logging the same message (see below):

[ 160.490229] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 160.561829] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 160.633431] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 160.705030] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 160.822172] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 160.893786] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 160.965387] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.036987] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.108583] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.180183] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.251782] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.323381] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.394982] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.466579] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.538176] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.609782] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0
[ 161.681401] nrf24 nrf0: nrf24_isr_work_handler: MAX_RT, tx req: 0, rx act: 0

From the code I see that "nrf24_isr_work_handler()" function is called multiple times. Does this mean that NRF is constantly interrupting us ?

Write procedure can't be interrupted by any signal

Dear Marcin,

I'm afraid, your write procedure can't be interrupted (via CTRL+C or sending any signal) in case of any hardware problems.
The reason is that you do not check the result of wait_event_interruptible in line:

wait_event_interruptible(p->write_wait_queue, p->write_done);

You should interrupt the write loop and report an error here.

With best regards,
Wojtek

Armbian kernel 4.14 rc7 banana pi m2

Hello,
I am testing your driver on my bananapi m2 Armbian kernel 4.14. It seems to load fine and I can see 5 devices in /dev/*. But dmesg shows a strange error, see below. My question: do you have any raspberry-specific code in your driver ? Any ideas why does this error happen ?

dmesg output

[ 7.943861] nrf24: loading out-of-tree module taints kernel.
[ 7.948638] nrf24 nrf0: nrf24_create_device: device created: major(245), minor(0)
[ 7.948844] nrf24 nrf0: nrf24_create_device: device created: major(245), minor(1)
[ 7.949005] nrf24 nrf0: nrf24_create_device: device created: major(245), minor(2)
[ 7.949189] nrf24 nrf0: nrf24_create_device: device created: major(245), minor(3)
[ 7.949345] nrf24 nrf0: nrf24_create_device: device created: major(245), minor(4)
[ 7.949565] nrf24 nrf0: nrf24_create_device: device created: major(245), minor(5)
[ 7.956710] Unable to handle kernel NULL pointer dereference at virtual address 0000004d
[ 7.956763] nrf24 nrf0: nrf24_tx_thread: waiting for new messages
[ 7.966041] pgd = c0004000
[ 7.968749] [0000004d] *pgd=00000000
[ 7.972345] Internal error: Oops: 5 [#1] SMP THUMB2
[ 7.977220] Modules linked in: sun6i_drc nrf24(O) sun4i_codec snd_soc_core snd_pcm_dmaengine snd_pcm snd_timer sun4i_ts snd soundcore sun4i_gpadc sun4i_ss sun4i_tcon uio_pdrv_genirq cpufreq_dt uio thermal_sys bonding brcmfmac brcmutil cfg80211 rfkill ip_tables x_tables i2c_sun6i_p2wi pwrseq_simple realtek
[ 8.004281] CPU: 3 PID: 379 Comm: nrf0_rx_thread Tainted: G O 4.14.0-rc7-sunxi #3
[ 8.012889] Hardware name: Allwinner sun6i (A31) Family
[ 8.018112] task: ee3da700 task.stack: ed89e000
[ 8.022642] PC is at __dev_printk+0x10/0x60
[ 8.026822] LR is at dev_printk+0x21/0x2c
[ 8.030825] pc : [] lr : [] psr: 20010033
[ 8.037082] sp : ed89fee0 ip : ed89e03c fp : 00000000
[ 8.042299] r10: ef401860 r9 : ef3f1860 r8 : 00000000
[ 8.047515] r7 : ed8f0218 r6 : ed8f0200 r5 : bfa3d438 r4 : ed89ff00
[ 8.054032] r3 : ed89ff1c r2 : ed89ff00 r1 : 00000001 r0 : bfa3d438
[ 8.060551] Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA Thumb Segment none
[ 8.067849] Control: 50c5387d Table: 6e21806a DAC: 00000051
[ 8.073587] Process nrf0_rx_thread (pid: 379, stack limit = 0xed89e210)
[ 8.080190] Stack: (0xed89fee0 to 0xed8a0000)
[ 8.084546] fee0: ed8e0000 00600011 00000006 bfa3d654 ed89fefc c0545e29 ee2fbca8 ed89ff1c
[ 8.092715] ff00: bfa3d654 ed89fefc ed8e0000 ed8e0000 00000000 bfa3a93b bfa3d654 00000000
[ 8.100883] ff20: 00000000 bfa3d668 00000000 00000003 00000000 c0149d0f ef0f0000 00000000
[ 8.109050] ff40: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 8.117218] ff60: ed89ff78 ee357400 ee3573c0 00000000 ed89e000 ed8e0000 bfa3a73d ee2fbca8
[ 8.125386] ff80: ee35741c c012fa2d ffffffff ee3573c0 c012f931 00000000 00000000 00000000
[ 8.133553] ffa0: 00000000 00000000 00000000 c0106589 00000000 00000000 00000000 00000000
[ 8.141721] ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 8.149889] ffe0: 00000000 00000000 00000000 00000000 00000013 00000000 6fffd861 6fffdc61
[ 8.158070] [] (__dev_printk) from [] (dev_printk+0x21/0x2c)
[ 8.165479] [] (dev_printk) from [] (nrf24_rx_thread+0x1fe/0x244 [nrf24])
[ 8.174026] [] (nrf24_rx_thread [nrf24]) from [] (kthread+0xfd/0x104)
[ 8.182201] [] (kthread) from [] (ret_from_fork+0x11/0x28)
[ 8.189419] Code: eb04 4605 4614 b1e9 (6ccb) 7840
[ 8.194301] ---[ end trace e13b3e22e6f9c21d ]---


My overlay:

/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun6i-a31s";

fragment@0 {
            target = <&pio>;
            __overlay__ {
                    nrf1_pins: nrf1_pins {
                            pins = "PE7", "PE6";	/* pins 38,36 on 40-pin GPIO connector */
                            function = "gpio_in", "gpio_out";
                    };
            };
    };

fragment@1 {
	target = <&spi1>;
	__overlay__ {
		#address-cells = <1>;
		#size-cells = <0>;
		status = "okay";

		nrf1: nrf1@0 {
			compatible = "nordic,nrf24";
			reg = <0>; /* CS0 */
			pinctrl-names = "default";
			pinctrl-0 = <&nrf1_pins>;
			#interrupt-cells = <2>;
			interrupt-parent = <&pio>;
			interrupts = <4 7 2>;		/* PE7, falling edge */
			irq-gpio = <&pio 4 7 0>;
			ce-gpio = <&pio 4 6 0>;		/* PE6 */
			spi-max-frequency = <5000000>;
			status = "okay";
		};
	};
};
  };

No errors happen during echo'ing text into the devices.

Unable to compile for aarch64

CC [M] /home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.o
In file included from /home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:21:0:
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c: In function ‘nrf24_tx_thread’:
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:226:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘ssize_t {aka long int}’ [-Wformat=]
dev_dbg(&device->dev, "tx %d bytes", n);
^
./include/linux/device.h:1364:30: note: in definition of macro ‘dev_dbg’
dev_printk(KERN_DEBUG, dev, format, ##arg)
^~~~~~
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c: In function ‘nrf24_rx_thread’:
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:309:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘ssize_t {aka long int}’ [-Wformat=]
"%s: get pipe failed (err: %d)",
^
./include/linux/device.h:1364:30: note: in definition of macro ‘dev_dbg’
dev_printk(KERN_DEBUG, dev, format, ##arg)
^~~~~~
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:328:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘ssize_t {aka long int}’ [-Wformat=]
"%s: could not read pload (err = %d)",
^
./include/linux/device.h:1364:30: note: in definition of macro ‘dev_dbg’
dev_printk(KERN_DEBUG, dev, format, ##arg)
^~~~~~
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:334:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘ssize_t {aka long int}’ [-Wformat=]
dev_dbg(p->dev, "rx %d bytes", length);
^
./include/linux/device.h:1364:30: note: in definition of macro ‘dev_dbg’
dev_printk(KERN_DEBUG, dev, format, ##arg)
^~~~~~
In file included from /home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:33:0:
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c: In function ‘nrf24_read’:
./include/linux/kfifo.h:636:27: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
unsigned int *__copied = (copied);
^
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:420:6: note: in expansion of macro ‘kfifo_to_user’
n = kfifo_to_user(&p->rx_fifo, buf, size, &copied);
^~~~~~~~~~~~~
In file included from /home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:21:0:
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c: In function ‘nrf24_write’:
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:439:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
dev_dbg(p->dev, "write (%d)", size);
^
./include/linux/device.h:1364:30: note: in definition of macro ‘dev_dbg’
dev_printk(KERN_DEBUG, dev, format, ##arg)
^~~~~~
In file included from /home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:33:0:
./include/linux/kfifo.h:608:27: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
unsigned int __copied = (copied);
^
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:454:6: note: in expansion of macro ‘kfifo_from_user’
n = kfifo_from_user(&device->tx_fifo,
^~~~~~~~~~~~~~~
In file included from ./include/linux/spi/spi.h:21:0,
from /home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:23:
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c: In function ‘nrf24_probe’:
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:818:39: error: passing argument 1 of ‘kthread_create_on_node’ from incompatible pointer type [-Werror=incompatible-pointer-types]
device->rx_task_struct = kthread_run(nrf24_rx_thread,
^
./include/linux/kthread.h:27:25: note: in definition of macro ‘kthread_create’
kthread_create_on_node(threadfn, data, NUMA_NO_NODE, namefmt, ##arg)
^~~~~~~~
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:818:27: note: in expansion of macro ‘kthread_run’
device->rx_task_struct = kthread_run(nrf24_rx_thread,
^~~~~~~~~~~
./include/linux/kthread.h:10:21: note: expected ‘int (
)(void )’ but argument is of type ‘ssize_t ()(void ) {aka long int ()(void *)}’
struct task_struct *kthread_create_on_node(int (*threadfn)(void data),
^~~~~~~~~~~~~~~~~~~~~~
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:828:39: error: passing argument 1 of ‘kthread_create_on_node’ from incompatible pointer type [-Werror=incompatible-pointer-types]
device->tx_task_struct = kthread_run(nrf24_tx_thread,
^
./include/linux/kthread.h:27:25: note: in definition of macro ‘kthread_create’
kthread_create_on_node(threadfn, data, NUMA_NO_NODE, namefmt, ##arg)
^~~~~~~~
/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.c:828:27: note: in expansion of macro ‘kthread_run’
device->tx_task_struct = kthread_run(nrf24_tx_thread,
^~~~~~~~~~~
./include/linux/kthread.h:10:21: note: expected ‘int (
)(void )’ but argument is of type ‘ssize_t ()(void ) {aka long int ()(void *)}’
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
^~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
scripts/Makefile.build:316: recipe for target '/home/sergey/Projects/orpaltech/drivers/nordic/nrf24/nrf24_if.o' failed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.