Commit a3dd4e81 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

usbled compiles, but segfaults

parent 53985415
......@@ -28,7 +28,7 @@ static const USB_DeviceDescriptor_TypeDef deviceDesc __attribute__ ((aligned(4))
.bDeviceProtocol = 0,
.bMaxPacketSize0 = USB_EP0_SIZE,
.idVendor = 0x10C4,
.idProduct = 0x0003,
.idProduct = 0x00ff,
.bcdDevice = 0x0000,
.iManufacturer = 1,
.iProduct = 2,
......@@ -168,7 +168,7 @@ static const uint8_t bufferingMultiplier[ NUM_EP_USED + 1 ] = { 1, 1, 2, 2 };
static const USBD_Callbacks_TypeDef callbacks =
{
.usbReset = NULL,
.usbStateChange = StateChange,
.usbStateChange = NULL, //StateChange,
.setupCmd = SetupCmd,
.isSelfPowered = NULL,
.sofInt = NULL
......
......@@ -53,6 +53,9 @@
/* baudrate. Minimum timeout is set to 10 ms. */
#define RX_TIMEOUT EFM32_MAX(10U, 50000 / (cdcLineCoding.dwDTERate))
#define LED_SET 0x11
/* The serial port LINE CODING data structure, used to carry information */
/* about serial port baudrate, parity etc. between host and device. */
EFM32_PACK_START(1)
......@@ -156,8 +159,8 @@ int main(void)
GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);;
GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 1);;
SerialPortInit();
DmaSetup();
// SerialPortInit();
// DmaSetup();
USBD_Init(&initstruct);
/*
......@@ -170,9 +173,9 @@ int main(void)
for (;;)
{
GPIO_PinOutToggle(gpioPortE, 11);
GPIO_PinOutToggle(gpioPortE, 12);
delay(1000);
// GPIO_PinOutToggle(gpioPortE, 11);
// GPIO_PinOutToggle(gpioPortE, 12);
// delay(1000);
}
}
......@@ -492,41 +495,45 @@ static int SetupCmd(const USB_Setup_TypeDef *setup)
{
switch (setup->bRequest)
{
case USB_CDC_GETLINECODING:
/********************/
if ((setup->wValue == 0) &&
(setup->wIndex == 0) && /* Interface no. */
(setup->wLength == 7) && /* Length of cdcLineCoding */
(setup->Direction == USB_SETUP_DIR_IN))
{
/* Send current settings to USB host. */
USBD_Write(0, (void*) &cdcLineCoding, 7, NULL);
retVal = USB_STATUS_OK;
}
break;
case USB_CDC_SETLINECODING:
/********************/
if ((setup->wValue == 0) &&
(setup->wIndex == 0) && /* Interface no. */
(setup->wLength == 7) && /* Length of cdcLineCoding */
(setup->Direction != USB_SETUP_DIR_IN))
{
/* Get new settings from USB host. */
USBD_Read(0, (void*) &cdcLineCoding, 7, LineCodingReceived);
retVal = USB_STATUS_OK;
}
break;
case USB_CDC_SETCTRLLINESTATE:
/********************/
if ((setup->wIndex == 0) && /* Interface no. */
(setup->wLength == 0)) /* No data */
{
/* Do nothing ( Non compliant behaviour !! ) */
retVal = USB_STATUS_OK;
}
break;
case LED_SET:
setup->wValue ? GPIO_PinOutSet(gpioPortE, setup->wIndex) :
GPIO_PinOutClear(gpioPortE, setup->wIndex);
break;
// case USB_CDC_GETLINECODING:
// /********************/
// if ((setup->wValue == 0) &&
// (setup->wIndex == 0) && /* Interface no. */
// (setup->wLength == 7) && /* Length of cdcLineCoding */
// (setup->Direction == USB_SETUP_DIR_IN))
// {
// /* Send current settings to USB host. */
// USBD_Write(0, (void*) &cdcLineCoding, 7, NULL);
// retVal = USB_STATUS_OK;
// }
// break;
//
// case USB_CDC_SETLINECODING:
// /********************/
// if ((setup->wValue == 0) &&
// (setup->wIndex == 0) && /* Interface no. */
// (setup->wLength == 7) && /* Length of cdcLineCoding */
// (setup->Direction != USB_SETUP_DIR_IN))
// {
// /* Get new settings from USB host. */
// USBD_Read(0, (void*) &cdcLineCoding, 7, LineCodingReceived);
// retVal = USB_STATUS_OK;
// }
// break;
//
// case USB_CDC_SETCTRLLINESTATE:
// /********************/
// if ((setup->wIndex == 0) && /* Interface no. */
// (setup->wLength == 0)) /* No data */
// {
// /* Do nothing ( Non compliant behaviour !! ) */
// retVal = USB_STATUS_OK;
// }
// break;
}
}
......
CC = gcc
CFLAGS = -Wall
INCLUDE =
SOURCES = usbled.c
LIB = -L/usr/lib/i386-linux-gnu
LIB =
LDFLAGS = -lusb
all:
$(CC) $(INCLUDE) $(LIB) $(LDFLAGS) -o usbled $(SOURCES)
$(CC) -o usbled $(CFLAGS) $(INCLUDE) $(SOURCES) $(LIB) $(LDFLAGS)
clean:
rm usbled
......@@ -9,7 +9,8 @@ int main()
static struct usb_device *pDev;
static struct usb_bus *pBus;
int led = 0;
int led = 12;
int val = 0;
usb_init();
......@@ -51,16 +52,19 @@ int main()
while (1) {
led ^= 1;
if (led == 11) led = 12;
if (led == 12) led = 11;
val ^= 1;
if ( pDevH )
{
printf("led%d\n", led);
usb_control_msg(
pDevH, // Device handle
USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
// bmRequestType
LED_SET, // bRequest
0, // wValue
val, // wValue
led, // wIndex
NULL, // char *pBuffer
1, // wLength
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment