View topic - Using at90usb1287

Using at90usb1287

anything that doesn't fit to other groups.

Using at90usb1287

Postby parrado » Thu Dec 11, 2008 9:02 pm

This source code shows a little driver i wrote for the at90usb128-demo-template example from Atmel corporation.

I tested it using the usbkey board and everything was fine.

I hope this helps.

/*Archivos de cabecera*/
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>

/*Prototipos para POSIX Threads*/
#include <pthread.h>

/*Prototipos para libusbdiS.a*/
#include <sys/usbdi.h>

/*Códigos de error*/
#include <errno.h>

/*Código del vendor Nokia*/
#define USB_VENDOR_NOKIA 0x0421
/*Código del producto 5310*/
#define USB_PRODUCT_NOKIA_5310 0x006b

/*Código del vendor Atmel*/
#define USB_VENDOR_ATMEL 0x03eb
/*Código del producto AVR USB DEVICE*/

/*Definir con el fabricante y dispositivo específico respectivamente*/


/*Manejador del dispositivo*/
struct usbd_device *device;

/*Punteros a URBs IN y OUT respectivamente para las transferencias bulk*/
struct usbd_urb *urb1,*urb2;

/*Punteros a la tuberías IN y OUT respectivamente*/
struct usbd_pipe *pipe_in,*pipe_out;

/*Puntero a los datos*/
char *data;

/*Mutex para el flag que sincroniza el principal con el hilo de ejecución usb*/
pthread_mutex_t mutex;

/*Flag que sincroniza el principal con el hilo de ejecución usb*/
char isConnected=0;

/*Callback que se ejecuta cuando se ha conectado el dispositivo */
void insertion(struct usbd_connection *connection, usbd_device_instance_t *instance){

/*Vector en el cual se almacenarán los descriptores*/
char descriptor[200];

/*Condiciones de error de las funciones*/
int status;

Active Member
Posts: 20
Joined: Sat Oct 25, 2008 2:39 pm

RE: Using at90usb1287

Postby gallego » Sun May 30, 2010 3:31 pm


First of all thanks for posting your usb driver!, it is helping me a lot to develop my own device driver

I have mostly replicated your insertion() callback but I'm getting an error when opening the Pipe In. In fact I don't understand some small things in your code, thus I'm not able to fix it. Basically my questions are:

1. Why you define the buffer to put the descriptor as a char descriptor[200] ? (I had to define it as _uint8 because char gave me a type error). The size 200 is defined by the USB standard (I haven't find this info) or it depends on your device?

2. Why do you define the descriptor for the endpoint in and endpoint out as:
aux_base_endpoint=descriptor[0]+descriptor[(int)descriptor[0]]; and aux_base_endpoint=descriptor[0]+descriptor[(int)descriptor[0]]+descriptor[descriptor[0]+descriptor[(int)descriptor[0]]];
is it also because USB standard says so?

Thanks in advance
New Member
Posts: 3
Joined: Tue Jul 07, 2009 2:40 pm

Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests