beagleboard gps warren grant. about the beagleboard beagleboard-xm dm3730 processor - arm cortex a8...

20
BeagleBoard GPS Warren Grant

Upload: kenneth-douglas

Post on 22-Dec-2015

233 views

Category:

Documents


2 download

TRANSCRIPT

BeagleBoard GPS

Warren Grant

About the BeagleBoard

BeagleBoard-xMDM3730 processor - ARM Cortex A8 compatible - Closest to AM3175, but

with DSP

1GHz

512Mb DDR (rev c had 256)No NAND (nothing to destroy)4 USB ports, DB9, camera header, JTAG

About the BeagleBoardDevelopment platform not for use in end productsComes with a universal boot loader and demo of AngstromPowered by 5v adapter or via USB OTG port (up to 1 amp)DVI and S-video only

Getting it Running• Serial port used to connect to host computer running a

terminal emulator program• To update or install bootloader need to format micro sd with a

boot partition (u-boot, uImage) and ext3 file system partition.

OS for BeagleBoard• The Angstrom demo is command line only with limited capability• Tried an expanded version with gnome gui• Uses OPKG for package installation, otherwise compile and run locally• Comes with a 2 gig card and quickly became difficult to do on the board• Cross compiler option – too much back and forth, many errors, lots of

time trying to find everything• Found a linux distro for the board – Maverick 2.6.35-22-omap• Fits on 4G micro SD with room to spare• Saves time since building kernel modules can be done with monitor and

keyboard attached to the Beagleboard• Use standard gcc/g++ packages

Maverick on the BeagleBoard• Ubuntu• Allowed me to

concentrate on the driver for the GPS

The GPS Module

• EM-406A SiRF starIII• Very sensitive• Fast acquisition (picks up as soon as it is turned on)• Built in antenna• 20 channels• TTL level output voltage: 0 – 2.85V• 4800 Baud• NMEA 0183 output

NMEA

• National Marine Electronics Association• Outputs NMEA formatted sentences (ASCII) for time position

and fix data.• Shows satellites available, those in view, id numbers, SNR,

elevation speed, etc.

Connecting to the BeagleBoard

• Need to convert to RS232 levels or to USB• Initially tried via RS232 port• Use a MAX 232 driver receiver • Not so easy to get data into the

RS 232, resource conserved forremote terminal control

• Decided to use USB • MAX 232 with FTDI USB UART IC• Sparkfun (www.sparkfun.com) has this available for less

than cost of construction

Driver• This allowed me to concentrate on a driver• FTDI supports and provides drivers for windows• www.usb.org usb specifications• No set standard for USB to serial devices though• Linux has a subsystem usbcore that handles a large portion of

the standard• The driver then interfaces to the USB core.• HW USB host controller Device driver Kernel user• USB devices are made up of configurations, endpoints and

interfaces.• Endpoints carry data (unidirectional) host to device or vv (IN

or OUT)

USB Driver• Enpoints

– Control: command, configure, get device info– Interrupt: small amounts of data on request i.e. keyboard/mouse– Bulk: large data transfer– Isochronous: constant data flow, but some could be lost – ok for

video/audio– USB address, direction, type, packet size and interval get specified here

• Interfaces– Comprised of endpoints, provides control of endpoints (alternate settings)

(also specs minor number) one driver per interface

• Configurations– Comprised of interfaces– Device can have multiple configurations

URBs• Used to communicate between device to the kernel• Tx/rx data from device endpoint serially• Gets created by driver for a specific endpoint and gets sent to

USB core• Core sends to USB host controller• Processes then transfers to device, notifies device driver

Writing the driver• Device id – what is supported

• Register/unregister

• Module device table to recognize device

static struct usb_driver skel_driver = { name: "skeleton", probe: skel_probe, disconnect: skel_disconnect, fops: &skel_fops, minor: USB_SKEL_MINOR_BASE, id_table: skel_table,

};

/* table of devices that work with this driver */static struct usb_device_id skel_table [ ] = {{ USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },{ } /* Terminating entry */};MODULE_DEVICE_TABLE (usb, skel_table);

static void __exit usb_skel_exit(void) { /* deregister this driver with the USB subsystem */ usb_deregister(&skel_driver); } module_exit(usb_skel_exit);

static int __init usb_skel_init(void){int result;/* register this driver with the USB subsystem */result = usb_register(&skel_driver);if (result < 0) {err("usb_register failed for the "__FILE__ "driver."

/* table of devices that work with this driver */static struct usb_device_id skel_table [] = {{ USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },{ } /* Terminating entry */};MODULE_DEVICE_TABLE (usb, skel_table);

Driver

• Probe function, pass structure, id, and interface #• When in the system the device is bound to the driver• Unregisters when disconnected• Open function called by user• Read and write functions via urb/* we can only write as much as 1 urb will hold */bytes_written = (count > skel->bulk_out_size) ? skel->bulk_out_size : count;/* copy the data from user space into our urb */copy_from_user(skel->write_urb->transfer_buffer, buffer, bytes_written);/* set up our urb */usb_fill_bulk_urb(skel->write_urb,skel->dev,usb_sndbulkpipe(skel->dev, skel->bulk_out_endpointAddr),skel->write_urb->transfer_buffer,bytes_written,skel_write_bulk_callback,skel);/* send the data out the bulk port */result = usb_submit_urb(skel->write_urb);if (result) {err("Failed submitting write urb, error %d", result);}

Driver/* do an immediate bulk read to get data from the device */retval = usb_bulk_msg (skel->dev,usb_rcvbulkpipe (skel->dev,skel->bulk_in_endpointAddr),skel->bulk_in_buffer,skel->bulk_in_size,&count, HZ*10);/* if the read was successful, copy the data to user space */if (!retval) {if (copy_to_user (buffer, skel->bulk_in_buffer, count))retval = -EFAULT;elseretval = count;}

• Free resources when disconnected unexpectedly• All skeleton code available from /drivers/usb/usv-skeleton.c

My Driver• Customized settings and parameters • Didn’t work!• The FT232RL chip that provides the serial to usb interface acts like a

modem• Hardware and EEPROM (only a small portion is user config) require a

rather odd and complex scheme for setting baud rate– Baud rate set sing the internal 48MHz clock– Divided by 16 and sent to a prescaler as a 3MHz ref clock– So to Baud rate of 4800 divisor = 3000000/4800 = 625

• Johan Hovold, Greg Kroah-Hartman and Kuba Ober have written a driver• I decided to optimize the driver for my purposes

– Removed support for all other chips (extensive)– Made baud rate fixed at 4800– Also required changes to ‘.h’ file– Significantly reduced driver file size– For testing ‘cat /dev/ttyUSB0’ did not work until I fixed the baud rate– Interested only in receiving data, so baud does not need to be selected

Driver• Compiled on Beaglebard• Tested with minicom• Wrote simple c prog to

capture the data#include <iostream>#include <fstream>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>

using namespace std; int main(){const char EOL = '\n';int i=0;int nmea;char buffer[1];// = {};

int usbdev;//ofstream nmea;//nmea.open ("nmea.txt");nmea=open("nmea.txt", O_RDWR);usbdev = open("/dev/ttyUSB0", O_RDONLY);

//for(i=0; (i=1); ++i){while(i<400){

read(usbdev, buffer, 1);write(nmea, buffer, 1);cout << buffer;

i=i+1;//}

}close(usbdev);

Also works with gpsd

Still would like to do• Parse data and put into customized GUI• Have it run on a minimal kernel• Can add other features like maps, car navigation, directions, etc.• Smaller Touch screen display• Set the clock for OS• Could add camera, SDR, or DRM• Connect through auto on board diagnostics port to get detailed

vehicle info• What would I do different?

– Focus more on the driver. Steep learning curve, 3 OS’s, understanding omap

– Try a direct rs232 connection and driver– Still feel like I need to know more about USB drivers

References• www.beagleboard.com• www.sparkfun.com (datasheets for gps, FT232RL, MAX232)• www.gpsinformation.org• http://original.jamesthornton.com/linux/man/creat.2.html

– Usb file ops

• http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN128– Linux kernel programming guide – Peter J. Salzman

• www.linuxjournal.com writing USB drivers• http://wiki.openwrt.org/doc/techref/opkg

– Package manager for angstrom

• http://elinux.org/BeagleBoardUbuntu embedded Linux wiki• Embedded Linux Primer – Christopher Hallinan• www.kernel.org Linux Kernel archives

The End