Skip to content

Commit 680b485

Browse files
committed
Making bulkloop work.
1 parent d748272 commit 680b485

7 files changed

Lines changed: 84 additions & 282 deletions

File tree

examples/bulkloop/Makefile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
FX2LIBDIR=../../
22
BASENAME = bulkloop
3-
SOURCES=bulkloop.c dscr_test.c dscr_str.c
4-
A51_SOURCES=dscr.a51
3+
SOURCES=bulkloop.c
54
PID=0x1004
65

7-
SDCCFLAGS=--std-c99
8-
96
include $(FX2LIBDIR)lib/fx2.mk
10-
11-
dscr_str.c: dscr_str.in string_table.py
12-
cat dscr_str.in | python string_table.py > dscr_str.c
7+
include $(FX2LIBDIR)lib/fx2-cdesc.mk
138

149
test: test.cpp
1510
g++ -o test test.cpp -lusb-1.0
16-
Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
11

2-
#include <stddef.h>
3-
#include <linux/ch9.h>
4-
#include <linux/ch9-extra.h>
2+
#include "descriptors.h"
53

6-
7-
struct usb_section {
8-
struct usb_config_descriptor config;
9-
struct usb_interface_descriptor interface;
10-
struct usb_endpoint_descriptor endpoints[2];
11-
};
12-
13-
struct usb_str {
14-
__u8 bLength;
15-
__u8 bDescriptorType;
16-
17-
__le16 wData[]; /* UTF-16LE encoded */
18-
};
19-
20-
struct usb_descriptor {
21-
struct usb_device_descriptor device;
22-
struct usb_qualifier_descriptor qualifier;
23-
struct usb_section highspeed;
24-
struct usb_section fullspeed;
25-
};
26-
27-
__xdata struct usb_descriptor descriptor = {
4+
__code __at(DSCR_AREA) struct usb_descriptors code_descriptors = {
285
.device = {
296
.bLength = USB_DT_DEVICE_SIZE,
307
.bDescriptorType = USB_DT_DEVICE,
@@ -36,10 +13,10 @@ __xdata struct usb_descriptor descriptor = {
3613
.idVendor = 0x04B4,
3714
.idProduct = 0x1004,
3815
.bcdDevice = 0x0001,
39-
.iManufacturer = 1,
40-
.iProduct = 2,
41-
.iSerialNumber = 0,
42-
.bNumConfigurations = 1
16+
.iManufacturer = USB_STRING_INDEX(0),
17+
.iProduct = USB_STRING_INDEX(1),
18+
.iSerialNumber = USB_STRING_INDEX_NONE,
19+
.bNumConfigurations = 1,
4320
},
4421
.qualifier = {
4522
.bLength = USB_DT_DEVICE_QUALIFIER_SIZE,
@@ -56,7 +33,7 @@ __xdata struct usb_descriptor descriptor = {
5633
.config = {
5734
.bLength = USB_DT_CONFIG_SIZE,
5835
.bDescriptorType = USB_DT_CONFIG,
59-
.wTotalLength = sizeof(descriptor.highspeed),
36+
.wTotalLength = sizeof(descriptors.highspeed),
6037
.bNumInterfaces = 1,
6138
.bConfigurationValue = 1,
6239
.iConfiguration = 0,
@@ -71,8 +48,8 @@ __xdata struct usb_descriptor descriptor = {
7148
.bNumEndpoints = 2,
7249
.bInterfaceClass = USB_CLASS_VENDOR_SPEC,
7350
.bInterfaceSubClass = USB_SUBCLASS_VENDOR_SPEC,
74-
.bInterfaceProtocol = 0xff,
75-
.iInterface = 3,
51+
.bInterfaceProtocol = USB_PROTOCOL_VENDOR_SPEC,
52+
.iInterface = USB_STRING_INDEX(2),
7653
},
7754
.endpoints = {
7855
{
@@ -97,7 +74,7 @@ __xdata struct usb_descriptor descriptor = {
9774
.config = {
9875
.bLength = USB_DT_CONFIG_SIZE,
9976
.bDescriptorType = USB_DT_CONFIG,
100-
.wTotalLength = sizeof(descriptor.fullspeed),
77+
.wTotalLength = sizeof(descriptors.fullspeed),
10178
.bNumInterfaces = 1,
10279
.bConfigurationValue = 1,
10380
.iConfiguration = 0,
@@ -134,4 +111,5 @@ __xdata struct usb_descriptor descriptor = {
134111
},
135112
},
136113
},
114+
#include "build/descriptors_stringtable.inc"
137115
};

examples/bulkloop/descriptors.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <stddef.h>
2+
3+
#include "build/descriptors_stringtable.h"
4+
5+
#include <linux/ch9.h>
6+
#include <linux/ch9-extra.h>
7+
8+
#ifndef DESCRIPTORS_H_
9+
#define DESCRIPTORS_H_
10+
11+
struct usb_section {
12+
struct usb_config_descriptor config;
13+
struct usb_interface_descriptor interface;
14+
struct usb_endpoint_descriptor endpoints[2];
15+
};
16+
17+
struct usb_descriptors {
18+
struct usb_device_descriptor device;
19+
struct usb_qualifier_descriptor qualifier;
20+
struct usb_section highspeed;
21+
struct usb_section fullspeed;
22+
struct usb_descriptors_stringtable stringtable;
23+
};
24+
25+
__xdata __at(DSCR_AREA) struct usb_descriptors descriptors;
26+
27+
__code __at(DSCR_AREA+offsetof(struct usb_descriptors, device)) WORD dev_dscr;
28+
__code __at(DSCR_AREA+offsetof(struct usb_descriptors, qualifier)) WORD dev_qual_dscr;
29+
__code __at(DSCR_AREA+offsetof(struct usb_descriptors, highspeed)) WORD highspd_dscr;
30+
__code __at(DSCR_AREA+offsetof(struct usb_descriptors, fullspeed)) WORD fullspd_dscr;
31+
__code __at(DSCR_AREA+offsetof(struct usb_descriptors, stringtable)) WORD dev_strings;
32+
33+
#endif // DESCRIPTORS_H_

examples/bulkloop/dscr.a51

Lines changed: 0 additions & 225 deletions
This file was deleted.

lib/fx2-cdesc.mk

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# common make targets for compiling fx2 firmware with C descriptors
2+
3+
BUILDDIR?=build
4+
5+
DSCR_AREA=-DDSCR_AREA=0x3e00
6+
SDCCFLAGS += --std-c99
7+
SOURCES += descriptors.c
8+
9+
$(BUILDDIR)/descriptors_stringtable.h: $(FX2LIBDIR)/utils/generate_stringtable.py descriptors.strings
10+
$< --header < descriptors.strings > $@
11+
12+
$(BUILDDIR)/descriptors_stringtable.inc: $(FX2LIBDIR)/utils/generate_stringtable.py descriptors.strings
13+
$< --cfile < descriptors.strings > $@
14+
15+
16+
$(BUILDDIR)/$(BASENAME).ihx: descriptors.c $(BUILDDIR)/descriptors_stringtable.h $(BUILDDIR)/descriptors_stringtable.inc
17+
18+
# Check the descriptors using GCC for better error messages
19+
check-descriptors: $(DEPS)
20+
gcc -Wall -Werror -I$(FX2LIBDIR)/include descriptors.c
21+
rm a.out
22+
23+
clean-descriptors:
24+
rm -f $(foreach ext, h inc, $(BUILDDIR)/descriptors_stringtable.${ext})
25+
26+
clean: clean-descriptors
27+
28+
$(FX2LIBDIR)/include/linux/.git: $(FX2LIBDIR)/.gitmodules
29+
git submodule update --recursive --init $(dir $@)
30+
touch $@ -r $(FX2LIBDIR)/.gitmodules
31+
32+
.PHONY: check-descriptors clean-descriptors

0 commit comments

Comments
 (0)