Development questions from a beginner.

Hello,

I would appreciate some help getting started with embedded Linux. My
previous experience is with microcontrollers and basic windows
programming (both of these using commercial IDEs). My goal is to use
the beagleboard to control devices connected through SPI. To do this I
think I will have to write a module to communicate with my SPI devices
and provide access from userspace programs.

My first question is, how do I find the most up to date documentation,
specific to the image that I am using? Up to now I have been using the
image available at http://www.angstrom-distribution.org/demo/beagleboard/
and would like to avoid compiling the kernel from source if I don't
have to. From what I have read though, most of the documentation is in
the kernel sources. Is there a way to download just the documentation
and header files? I have read the guides that walk you through
building the Angstrom image and they use openembedded to download the
sources, can I download these sources without doing the full build? I
don't have experience with git, but I am willing to learn if this is
the best way to do it.

My second question relates to how the development process works. I
have played around with writing programs on the beagleboard and then
compiling them with gcc. I can see however that this is probably not
the most efficient method. I have found the tutorial for gumstix
development ( http://www.gumstix.net/Software/view/Build-system-overview/Hello-world-tutorial/111.html
) and will try to follow that with the beagleboard. Are there any
other examples of how to develop using openembedded that would be good
for me to read? Remember that I have only used IDEs before so whole
development process is new to me.

My third question is about SPI on the beagleboard. I have been able to
write a script to do simple things like blinking LEDs by writing to /
sys/class/gpio/. I would like to communicate with SPI devices this
easily, (read and write from a file). To do this I believe I need to
write a driver to set up the SPI port and to preform initalization of
my SPI hardware. I would like to use built in modules as much as
possible, but I will probably have to write some of my own code for
hardware specific things like initalizing and formatting information.
Could someone share experience with using SPI on the beagleboard, or
at least point me in the right direction?

Thanks for any help you can give me,
Greg

Hello,

My first question is, how do I find the most up to date documentation,
specific to the image that I am using? Up to now I have been using the
image available at http://www.angstrom-distribution.org/demo/beagleboard/
and would like to avoid compiling the kernel from source if I don't
have to. From what I have read though, most of the documentation is in
the kernel sources. Is there a way to download just the documentation
and header files? I have read the guides that walk you through
building the Angstrom image and they use openembedded to download the
sources, can I download these sources without doing the full build? I
don't have experience with git, but I am willing to learn if this is
the best way to do it.

Angstrom demo images are not intended to be used as a main day-to-day
thing (I think), it's just a demonstration of Beagle capabilities (and
OpenEmbedded/Angstrom too). I think you should try to build your image
by yourself. It shouldn't be *too* hard. Plus you can build your own
toolchains with OpenEmbedded too (just type 'bitbake meta-toolchain',
wait for several hours - and you have SDK ready to be used).
For kernel documentation, you can browse Linus git tree there:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=tree
The directory you are maybe interested in is "Documentation". You can
browse it with your browser or create local git copy.

My second question relates to how the development process works. I
have played around with writing programs on the beagleboard and then
compiling them with gcc. I can see however that this is probably not
the most efficient method. I have found the tutorial for gumstix
development ( http://www.gumstix.net/Software/view/Build-system-overview/Hello-world-tutorial/111.html
) and will try to follow that with the beagleboard. Are there any
other examples of how to develop using openembedded that would be good
for me to read? Remember that I have only used IDEs before so whole
development process is new to me.

For OpenEmbedded toolchain, you just unpack it into your system, open
terminal from which you will do your development work, run 'source
/usr/local/angstrom/arm/environment-setup', and you're done. For IDEs,
maybe you will need to specify some binary names/paths in
configuration menus (don't know). It depends. There is also arm
emulation possibility (with qemu) though I think it's not a newbie
thing.

See comments below…

Hello,

I would appreciate some help getting started with embedded Linux. My
previous experience is with microcontrollers and basic windows
programming (both of these using commercial IDEs). My goal is to use
the beagleboard to control devices connected through SPI. To do this I
think I will have to write a module to communicate with my SPI devices
and provide access from userspace programs.

You can control SPI devices directly from userspace using “spidev” so you won’t necessarily have to write a kernel module.

My first question is, how do I find the most up to date documentation,
specific to the image that I am using? Up to now I have been using the
image available at http://www.angstrom-distribution.org/demo/beagleboard/
and would like to avoid compiling the kernel from source if I don’t
have to. From what I have read though, most of the documentation is in
the kernel sources. Is there a way to download just the documentation
and header files? I have read the guides that walk you through
building the Angstrom image and they use openembedded to download the
sources, can I download these sources without doing the full build? I
don’t have experience with git, but I am willing to learn if this is
the best way to do it.

Yes, you could just download the source (which is what that git clone command would do). You can read lots of kernel source / git stuff online (not sure about Angstrom’s GIT repo though :slight_smile: So, if you want to browse the 2.6.29 kernel Documentation tree look here: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=tree;f=Documentation

Click on directories to enter them, to view files click on the “blob” or “raw” links to the right. As an example, “spidev” is explained in Documentation/spi/spidev

My second question relates to how the development process works. I
have played around with writing programs on the beagleboard and then
compiling them with gcc. I can see however that this is probably not
the most efficient method. I have found the tutorial for gumstix
development ( http://www.gumstix.net/Software/view/Build-system-overview/Hello-world-tutorial/111.html
) and will try to follow that with the beagleboard. Are there any
other examples of how to develop using openembedded that would be good
for me to read? Remember that I have only used IDEs before so whole
development process is new to me.

There are plenty of IDEs that you can use to develop your code. Do a quick Google if you think an IDE will make you feel more comfortable. However, if you need to compile code from scratch then typically it comes in a couple of flavours, so its worth getting used to them…! “./configure ; make ; make install” for example is so famous you can buy T-shirts with it on…

My third question is about SPI on the beagleboard. I have been able to
write a script to do simple things like blinking LEDs by writing to /
sys/class/gpio/. I would like to communicate with SPI devices this
easily, (read and write from a file). To do this I believe I need to
write a driver to set up the SPI port and to preform initalization of
my SPI hardware. I would like to use built in modules as much as
possible, but I will probably have to write some of my own code for
hardware specific things like initalizing and formatting information.
Could someone share experience with using SPI on the beagleboard, or
at least point me in the right direction?

Take a look at “spidev” and see if it works for you…

Actually, they are intended for that :slight_smile: And I personally use it that way.

regards,

Koen

Angstrom demo images are not intended to be used as a main day-to-day
thing

Actually, they are intended for that :slight_smile: And I personally use it that way.

Ok :slight_smile: It depends.

I have spent today reading the documentation from kernel.org and the
threads here relating to MCSPI. I have a few more questions that I
would appreciate some help with.

I used the guides on the elinux.org wiki and was able to successfully
bitbake an image. I found the thread titled "MCSPI3 working, both
ways", but I am not sure where to apply the patches given in that
thread. Do I apply it to the source that OE downloads, or does OE
apply the patch automatically. Also, how do I find out what the patch
is modifying, I opened the patch in a text editor but I don't
understand it. I want to try to understand what I am doing so that I
can learn.

Also, I believe that I need to register the spidev driver. I am not
sure how to do this, is it something I have to do before I build the
system image?

Thanks for taking the time to help out a beginner.

I have spent today reading the documentation from kernel.org and the
threads here relating to MCSPI. I have a few more questions that I
would appreciate some help with.

I used the guides on the elinux.org wiki and was able to successfully
bitbake an image. I found the thread titled "MCSPI3 working, both
ways", but I am not sure where to apply the patches given in that
thread. Do I apply it to the source that OE downloads, or does OE
apply the patch automatically. Also, how do I find out what the patch
is modifying, I opened the patch in a text editor but I don't
understand it. I want to try to understand what I am doing so that I
can learn.

Also, I believe that I need to register the spidev driver. I am not
sure how to do this, is it something I have to do before I build the
system image?

Thanks for taking the time to help out a beginner.

I've been thinking of submitting patches for OE to turn on SPI3 and 4
by default.

What do people think of this idea?

Philip

Does anyone have a recommendation for a good JTAG emulator for the beagle board?

I have a XDS5100 USB but it says it is 3/5V, where beagleboard requires 1.8?

I would appreciate that!

I would also appreciate that.

I think it would be a bad idea if you mean patching U-boot. IMO -
Since Angstrom is becoming the distro people are using, the Uboot should
either be consistant with the SRM (i.e by default, select the set of signals
in one column shown in the SRM) OR it should default to setting things in a
safe state. Just enabling the SPI's by default does neither. It'd either
confuse people more possible cause damage.

Enabling SPI means some lines are driven and may cause electrical conflicts.
Unless there is something special about the OMAP that prevents conflicting
lines from getting damaged...

I'd prefer to see all this enabling/pinmux done within the kernel and the
U-boot default to for the expansion connector either the default power
on/reset state per the TRM (i.e. untouched) or at least match the SRM.
Chances are if you are going to use SPI, you will have to patch the kernel
anyways. spidev is not enabled by default (nor should it) and there are
internal kernel users of the SPI bus. This way, at least there is some intent
going on rather then randomly frying things as the pinmux gets changed
underneath them (i.e. as result of running a git pull).

I agree… I would want all pixmuxes and expansion headers to be in a default safe mode. That said it should be trivial inside linux to set a pinmux mode and lock it to then keep things safe. That second bit is what is probably needed and missing at the moment…

As an example, I’ve been merrily pinmuxing the TWL4030 and setting I2C registers knowing happily that there’s nothing else in the kernel going to break (coz I checked). That said, it could easily change on me in the future :frowning:

Does anyone have a recommendation for a good JTAG emulator for the
beagle board?

I have had luck using:
1) Spectrum Digital XDS560 PCI
2) Blackhawk USB560BP
3) Blackhawk USB560m

I have a XDS5100 USB but it says it is 3/5V, where beagleboard requires
1.8?

I assume you mean XDS510 USB
(http://www.spectrumdigital.com/product_info.php?products_id=29)?
In that case you can get a 1.8V level converter from Spectrum Digital:
http://www.spectrumdigital.com/product_info.php?cPath=22_49&products_id=32&o
sCsid=092ce953bf0a2eb575dc0129b4ae6f2c

I haven't tried this setup, but since they claim support for OMAP and Cortex
for XDS510 USB, I would assume it to work, but better ask them before buying
in order to be 100% sure :slight_smile:

Good luck
  Søren

Hi

Could someone please still answer Greg's question about how to
register the spidev driver and also how to apply the patches from the
"MCSPI3 working, both ways" thread, in the OE environment? This thread
rightfully turned into a discussion on whether to turn SPI on by
default, but I can still not figure out how to do this properly.
Thank you,
John

I have been able to setup SPI device but I am trying to use the SPI
interface to connect to an external ADC and have it stream to a
file. If anyone has done this or knows how, please help. An example
will be perfect. Here are the changes I made to get to this point:

1. Changes to uboot: (board/omap3/beagle/beagle.h):
  MUX_VAL(CP(MMC1_DAT6), (IEN | PTU | EN | M0)) /*MMC1_DAT6*/\
  MUX_VAL(CP(MMC1_DAT7), (IEN | PTU | EN | M0)) /*MMC1_DAT7*/\
  /*Wireless LAN */\
- MUX_VAL(CP(MMC2_CLK), (IEN | PTU | EN | M4)) /*GPIO_130*/\
- MUX_VAL(CP(MMC2_CMD), (IEN | PTU | EN | M4)) /*GPIO_131*/\
- MUX_VAL(CP(MMC2_DAT0), (IEN | PTU | EN | M4)) /*GPIO_132*/\
+ MUX_VAL(CP(MMC2_CLK), (IEN | PTU | DIS | M1)) /*MCSPI3_CLK*/\
+ MUX_VAL(CP(MMC2_CMD), (IEN | PTU | DIS | M1)) /*MCSPI3_SIMO*/\
+ MUX_VAL(CP(MMC2_DAT0), (IEN | PTU | EN | M1)) /*MCSPI3_SOMI*/\
  MUX_VAL(CP(MMC2_DAT1), (IEN | PTU | EN | M4)) /*GPIO_133*/\
  MUX_VAL(CP(MMC2_DAT2), (IEN | PTU | EN | M4)) /*GPIO_134*/\
- MUX_VAL(CP(MMC2_DAT3), (IEN | PTU | EN | M4)) /*GPIO_135*/\
+ MUX_VAL(CP(MMC2_DAT3), (IEN | PTU | EN | M1)) /*MCSPI3_CS0*/\

2. Changes to kernel: (tmp/work/beagleboard-angstrom-linux-gnueabi/
linux-omap-2.6.29*/git/.config):

  CONFIG_OMAP_MUX=y
  CONFIG_SPI_OMAP24XX=y
  CONFIG_SPI_SPIDEV=y

3. Add to arch/arm/mach-omap2/board-omap3beagle.c

#include <linux/spi/spi.h>

// For McSPI3
static struct spi_board_info beagle_spi_board_info[] = {
  {
    .modalias = "spidev",
    .max_speed_hz = 48000000, //48 Mbps
    .bus_num = 3,
    .chip_select = 0,
    .mode = SPI_MODE_1,
  },
};

// For McSPI4
static struct spi_board_info beagle_spi_board_info2[] = {
  {
    .modalias = "spidev",
    .max_speed_hz = 48000000, //48 Mbps
    .bus_num = 4,
    .chip_select = 0,
    .mode = SPI_MODE_1,
  },
};

Add to function : static void __init omap3_beagle_init(void) {
  ...
  printk("Debug ================> register SLAVE DEVICES using
[spidev] protocol driver >>> start\n");
  spi_register_board_info(beagle_spi_board_info, ARRAY_SIZE
(beagle_spi_board_info));
  spi_register_board_info(beagle_spi_board_info2, ARRAY_SIZE
(beagle_spi_board_info2));
  printk("Debug ================> register SLAVE DEVICES using
[spidev] protocol driver >>> end\n");

4. Rebuild uboot
   Rebuild Kernel

I hope it helps.

Thanks,
Saladino.

saladino wrote:

I have been able to setup SPI device but I am trying to use the SPI
interface to connect to an external ADC and have it stream to a
file. If anyone has done this or knows how, please help. An example
will be perfect. Here are the changes I made to get to this point:

1. Changes to uboot: (board/omap3/beagle/beagle.h):
  MUX_VAL(CP(MMC1_DAT6), (IEN | PTU | EN | M0)) /*MMC1_DAT6*/\
  MUX_VAL(CP(MMC1_DAT7), (IEN | PTU | EN | M0)) /*MMC1_DAT7*/\
  /*Wireless LAN */\
- MUX_VAL(CP(MMC2_CLK), (IEN | PTU | EN | M4)) /*GPIO_130*/\
- MUX_VAL(CP(MMC2_CMD), (IEN | PTU | EN | M4)) /*GPIO_131*/\
- MUX_VAL(CP(MMC2_DAT0), (IEN | PTU | EN | M4)) /*GPIO_132*/\
+ MUX_VAL(CP(MMC2_CLK), (IEN | PTU | DIS | M1)) /*MCSPI3_CLK*/\
+ MUX_VAL(CP(MMC2_CMD), (IEN | PTU | DIS | M1)) /*MCSPI3_SIMO*/\
+ MUX_VAL(CP(MMC2_DAT0), (IEN | PTU | EN | M1)) /*MCSPI3_SOMI*/\
  MUX_VAL(CP(MMC2_DAT1), (IEN | PTU | EN | M4)) /*GPIO_133*/\
  MUX_VAL(CP(MMC2_DAT2), (IEN | PTU | EN | M4)) /*GPIO_134*/\
- MUX_VAL(CP(MMC2_DAT3), (IEN | PTU | EN | M4)) /*GPIO_135*/\
+ MUX_VAL(CP(MMC2_DAT3), (IEN | PTU | EN | M1)) /*MCSPI3_CS0*/\

If this does work, do you like to add it in 'Example' section of

http://elinux.org/BeagleBoardPinMux#Examples

?

2. Changes to kernel: (tmp/work/beagleboard-angstrom-linux-gnueabi/
linux-omap-2.6.29*/git/.config):

  CONFIG_OMAP_MUX=y

Be careful with this. It might (wrongly) overwrite some pin mux
(correctly) done in U-Boot.

Best regards

Dirk

Thanks Saladino,

I will try your suggestion this afternoon. One question though. I
think what I need to do is to first bitbake the base-image, so that it
downloads the source. Then modify the source, and re-do the bitbake.
Is this the correct way to directly modify the source using bitbake?
Or do I have to put my changes into a patch file.

I tried applying the patch presented in Philip Balister's thread where
he has SPI working. Unfortunately the patch is for kernel version
2.6.28 and openembedded seems to now be using 2.6.29. I manually added
everything in the patch to the 2.6.29 files, and used the patch file
to create the spi-test.patch file inside linux/linux-omap-2.6.29/
beagleboard. When I bitbake now, I get an error applying the patch to
arch/arm/plat-omap/include/mach/mux.h

Here is part of the output of bitbake:
Applying patch spi-test.patch
patching file arch/arm/mach-omap2/board-omap3beagle.c
Hunk #2 succeeded at 465 (offset 153 lines).
Hunk #3 succeeded at 533 with fuzz 2 (offset 153 lines).
patching file arch/arm/mach-omap2/mux.c
Hunk #1 succeeded at 245 with fuzz 2 (offset -227 lines).
Hunk #2 succeeded at 589 (offset 14 lines).
Hunk #3 succeeded at 636 (offset 14 lines).
patching file arch/arm/plat-omap/include/mach/mux.h
Hunk #1 FAILED at 795.
1 out of 1 hunk FAILED -- rejects in file arch/arm/plat-omap/include/
mach/mux.h
Patch spi-test.patch does not apply (enforce with -f)
ERROR: Task 347 (/home/elex/oe/openembedded/recipes/linux/linux-
omap_2.6.29.bb, do_patch) failed
NOTE: Waiting for 1 active tasks to finish
NOTE: 1: /home/elex/oe/openembedded/recipes/alsa/alsa-lib_1.0.18.bb,
do_populate_staging (27333)
NOTE: package alsa-lib-1.0.18-r0: task do_populate_staging: completed
NOTE: Tasks Summary: Attempted 928 tasks of which 873 didn't need to
be rerun and 1 failed.
ERROR: '/home/elex/oe/openembedded/recipes/linux/linux-omap_2.6.29.bb'
failed
NOTE: build 200906111033: completed

I think I found the mux.h file that it had problems with. I do not see
anything that looks like patch rejects.
Has anyone had success in modifying Philip Balister's patch file for
the 2.6.29 kernel?

I have not been able to figure out the bitbake way to rebuild the
kernel and keep my source changes. The way I do it is update the
changes manually and then from the source directory tmp/work/
beagleboard-angstrom-linux-gnueabi/
linux-omap-2.6.29*/git run:

make CROSS_COMPILE=arm-angstrom-linux-gnueabi- clean
make CROSS_COMPILE=arm-angstrom-linux-gnueabi- all
make CROSS_COMPILE=arm-angstrom-linux-gnueabi- uImage
see arch/arm/boot for output (uImage)

Thanks.

Hi Saladino

The idea is not to make any changes in the tmp/work/ directory a keep it the way the distro developers provide it. Bitbake extracts the src tarballs every time you rebuild and thus overwrites your changes. Rather build the modifications from your user.collection directory as explained in the threads.

http://www.nabble.com/Problem-modifying—rebuilding-a-driver-in-OE-td21126028.html
and
http://www.nabble.com/Kernel-Hacking-td17348424.html#a17368684

Regards,
John

See:

http://wh1t3s.com/2009/05/11/oe-bitake-kernel-mods

…actually, most of this is good:
http://wh1t3s.com/category/embedded/

  • dan