-
Notifications
You must be signed in to change notification settings - Fork 25
/
README
240 lines (157 loc) · 8.75 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
Panalyzer
This is a Logic Analyzer that runs on the RaspberryPi. The basic idea is that
it disables interrupts for a period, while sampling the GPIO pins once a
microsecond. It then re-enables interupts and displays traces showing what the
relevant GPIO pins were doing. Clearly the RaspberryPi is frozen while data is
being gathered, because interrupts are disabled, but a timeout is implemented
to avoid hanging for ever if a trigger word is not seen.
Panalyzer has features such as specifying trigger patterns, buffer depth, a
pair of cursors for measuring time periods on the trace, etc. In the display
you can click and drag across part of the trace to zoom in on that section.
Not all features are implemented yet, and there is scope to improve
performance. The UI may well be reworked as the idea develops.
Currently it expects you to use the following gpio pins:
Channel 0: GPIO4 (P1-7)
Channel 1: GPIO17 (P1-11)
Channel 2: GPIO18 (P1-12)
Channel 3: GPIO21 (P1-13)
Obviously you should be careful not to damage the RaspberryPi by feeding
signals above 3.3 volts to those pins. Personally I added a 7417 open
collector buffer, driven from 5 volts, but with pullups on the outputs to 3.3
volts. The idea being that I could then monitor 5 volt or 3.3 volt based
circuits safely.
While this project is in very early development, it has been tested monitoring
signals up to 250KHz, and capturing up to 2 seconds worth of data. There is
obviously some sampling error at those speeds, as only it samples at 1000HKz.
Currently you cannot change the sampling frequency; it loops watching a 1MHz
counter in the processor, and takes a sample every time it changes.
The runtime comprises three files:
pandriver.ko is the kernel module that captures the data.
Panalyzer is the user space application that displays the data.
Panalyzer.ui is a Glade generated UI definition, and must be located in
the directory Panalyzer is invoked from.
As of June 16th 2014, the included module should load if you have recently
run rpi-update (and so are running kernel 3.12.22+). Read the comments at the
top of pandriver.c for how to create the /dev/panalyzer file. The included
Panalyzer binary uses gtk-3.0 and should run on Raspbian, at least.
Compiling:
To build the UI (Panalyzer) on Raspbian, you need to
"sudo apt-get install libgtk-3-dev", and the simply "make Panalyzer".
The Makefile is currently set up to cross-compile the kernel module; if you are
building natively remove the ARCH and CROSS_COMPILE settings.
Building the module can be painful because you need matching kernel headers.
Many people run Raspbian (as I do), and by default that ships a packaged kernel
with matching headers, but does not install it. Instead, Raspbian runs a
kernel from the RaspberryPi foundation, for which matching headers are not
available. Also, to compile a kernel against which you can compile Panalyzer
(and get a module that will load), you need to have exactly the right kernel
source.
In theory you can short-circuit some of this process by running some "module
prepare" step rather thana full make, but I haven't had success with that.
In the past I have found that compiling the module on the Pi itself results
in a moduel that does not work; I presume that was due to some compiler bug,
but I've not investigated much, and I don't know if the issue has since been
fixed. However, I cross-compile the module on an Ubuntu host, which avoids
that problem has is many times faster.
The best instructions I have found for compiling the correct kernel source
are here: <http://lnxpps.de/rpie/raspi-anleitung.txt>. I have reproduced them
in full below (with a few extra [rgh] notes), in case that link goes away:
======================== http://lnxpps.de/rpie/raspi-anleitung.txt =============================
How to Build the Modules for adding an mcp251x to a Raspberry Pi
================================================================
Note: The examples shown here were run with Kernel 3.10.24+ from Raspbian 2013-12-20.
Chapter 1: Find your kernel hash and configuration (on the Pi)
--------------------------------------------------------------
- Find your kernel hash using either of the following methods:
> FIRMWARE_HASH=$(zgrep "* firmware as of" /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz | head -1 | awk '{ print $5 }')
> KERNEL_HASH=$(wget https://raw.github.com/raspberrypi/firmware/$FIRMWARE_HASH/extra/git_hash -O -)
> echo $KERNEL_HASH
4bbea92eae6c0792e85a4ba079d367ac6aa77fb5
or, if you got your kernel via rpi-update (scroll down): https://github.com/raspberrypi/linux/issues/486
- Get the configuration of your running kernel:
> cp /proc/config.gz ~
Chapter 2: Setup your build environment (on a different, *very* fast machine)
-----------------------------------------------------------------------------
See http://elinux.org/RPi_Kernel_Compilation for additional basic information.
- Setup a Linux System or VM
- make a folder for compilation:
> mkdir ~/raspi; export BASEDIR=~/raspi; cd $BASEDIR
- Get the kernel sources:
[rgh: --depth 100 below was not enough for me; I used --depth 200]
> cd $BASEDIR
> git clone --depth 100 https://github.com/raspberrypi/linux.git
> export KERNEL_SRC=$BASEDIR/linux
> cd $KERNEL_SRC
> git checkout 4bbea92eae6c0792e85a4ba079d367ac6aa77fb5
[rgh: If that gives you some error about "is not a tree", you probably need a larger --depth value above]
[rgh: I needed a "git pull" after that last "git checkout <hash>"]
Note that the hash value for git checkout is the one you got in Chapter 1.
- Get the Compiler
[rgh: I run Ubuntu, so just installed the cross compiler from their repositories, as per http://elinux.org/RPi_Kernel_Compilation]
> cd $BASEDIR
> git clone git://github.com/raspberrypi/tools.git
> export CCDIR=$BASEDIR/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin
> export CCPREFIX=$CCDIR/arm-bcm2708-linux-gnueabi-
Chapter 3: Compile the Kernel modules
-------------------------------------
- Prime the Kernel sources with the old configuration
> cd $BASEDIR
> scp pi@raspberry:config.gz .
> cd $KERNEL_SRC
> zcat $BASEDIR/config.gz > .config
> ARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig
[rgh: You can skip the menuconfig command below]
- Add the CAN modules and drivers to the configuration.
> ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig
For what options to select, see http://elinux.org/RPi_CANBus
Note that when an option is selected to be compiled into the kernel (shows a *), you do *not* need to change that to module!
- Compile the kernel
> ARCH=arm CROSS_COMPILE=${CCPREFIX} make
This will take a while. If you have multiple cores available in your VM, speed up compilation by using "-j <numcors+1>". So for my VM with 3 cores available, I use
> ARCH=arm CROSS_COMPILE=${CCPREFIX} make -j 4
[rgh: At this point fix the path in Panalyzer/Makefile to point at your kernel, and "make pandriver.ko". Job done.]
- Create a directory to temporarily deploy the modules in
> mkdir $BASEDIR/modules
> export MODULES_TEMP=$BASEDIR/modules
- Deploy the modules:
> ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} make modules_install
- Get the source for the spi-config module
> cd $BASEDIR
> git clone https://github.com/msperl/spi-config
> cd spi-config
- Build the spi-config module
> ARCH=arm CROSS_COMPILE=${CCPREFIX} make KDIR=$KERNEL_SRC
- Deploy the spi-config module
> ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} make KDIR=$KERNEL_SRC install
- Pack all necessary modules into one tar file:
> cd $MODULES_TEMP
> tar -cjf rpi-can-modules.tar.bz2 \
lib/modules/3.10.24+/kernel/net/can/can.ko \
lib/modules/3.10.24+/kernel/net/can/can-raw.ko \
lib/modules/3.10.24+/kernel/net/can/can-gw.ko \
lib/modules/3.10.24+/kernel/net/can/can-bcm.ko \
lib/modules/3.10.24+/kernel/drivers/net/can/mcp251x.ko \
lib/modules/3.10.24+/kernel/drivers/net/can/can-dev.ko \
lib/modules/3.10.24+/kernel/drivers/spi/spi-bcm2708.ko \
lib/modules/3.10.24+/extra/spi-config.ko
- Copy the resulting archive to the Pi
> scp rpi-can-modules.tar.bz2 pi@raspberrypi:
Chapter 4: Deploy the modules on the Pi (on the Pi, obviously)
--------------------------------------------------------------
- Exctract the modules
> cd /
> sudo tar -xjf ~/rpi-can-modules.tar.bz2
> sudo depmod -a
- Test-load the modules
> sudo modprobe spi-bcm2708
> sudo modprobe can
> sudo modprobe can-dev
> sudo modprobe can-raw
> sudo modprobe can-bcm
> sudo modprobe spi-config devices=\
bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
If you see "mcp251x spi0.0: probed", it worked.
================== End of http://lnxpps.de/rpie/raspi-anleitung.txt =========================
Feedback welcome.
Richard Hirst <richardghirst@gmail.com> June 16th 2014
['rgh' on the RaspberryPi forum]