Skip to content

Get USBHost to build and run with GCC_ARM #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/USBHost/USBHost/USBEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir

//TDs have been allocated by the host
memcpy((HCTD**)td_list, td_list_, sizeof(HCTD*)*2); //TODO: Maybe should add a param for td_list size... at least a define
memcpy(td_list_[0], 0, sizeof(HCTD));
memcpy(td_list_[1], 0, sizeof(HCTD));
memset(td_list_[0], 0, sizeof(HCTD));
memset(td_list_[1], 0, sizeof(HCTD));

td_list[0]->ep = this;
td_list[1]->ep = this;
Expand Down
2 changes: 1 addition & 1 deletion libraries/USBHost/USBHost/USBHALHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE))

static volatile __align(256) uint8_t usb_buf[TOTAL_SIZE] __attribute((section("AHBSRAM1"),aligned)); //256 bytes aligned!
static volatile uint8_t usb_buf[TOTAL_SIZE] __attribute((section("AHBSRAM1"),aligned(256))); //256 bytes aligned!

USBHALHost * USBHALHost::instHost;

Expand Down
18 changes: 9 additions & 9 deletions libraries/USBHost/USBHost/USBHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ void USBHost::usb_process() {

if (i == MAX_DEVICE_CONNECTED) {
USB_ERR("Too many device connected!!\r\n");
deviceInited[i] = false;
usb_mutex.unlock();
continue;
}
Expand Down Expand Up @@ -287,7 +286,7 @@ void USBHost::transferCompleted(volatile uint32_t addr)
{
uint8_t state;

if(addr == NULL)
if(addr == 0)
return;

volatile HCTD* tdList = NULL;
Expand Down Expand Up @@ -482,6 +481,8 @@ void USBHost::unqueueEndpoint(USBEndpoint * ep)
case INTERRUPT_ENDPOINT:
tailInterruptEndpoint = prec;
break;
default:
break;
}
}
current->setState(USB_TYPE_FREE);
Expand Down Expand Up @@ -1152,13 +1153,12 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,

void USBHost::fillControlBuf(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index, int len)
{
#ifdef __BIG_ENDIAN
#error "Must implement BE to LE conv here"
#endif
setupPacket[0] = requestType;
setupPacket[1] = request;
//We are in LE so it's fine
*((uint16_t*)&setupPacket[2]) = value;
*((uint16_t*)&setupPacket[4]) = index;
*((uint16_t*)&setupPacket[6]) = (uint32_t) len;
setupPacket[2] = (uint8_t) value;
setupPacket[3] = (uint8_t) (value >> 8);
setupPacket[4] = (uint8_t) index;
setupPacket[5] = (uint8_t) (index >> 8);
setupPacket[6] = (uint8_t) len;
setupPacket[7] = (uint8_t) (len >> 8);
}
21 changes: 11 additions & 10 deletions libraries/USBHost/USBHost/USBHostTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define USB_INC_H

#include "mbed.h"
#include "toolchain.h"

enum USB_TYPE {
USB_TYPE_OK = 0,
Expand Down Expand Up @@ -135,34 +136,34 @@ enum ENDPOINT_TYPE {
#define CONFIGURATION_DESCRIPTOR_LENGTH 0x09

// ------------ HostController Transfer Descriptor ------------
typedef __packed struct HCTD {
typedef struct HCTD {
__IO uint32_t control; // Transfer descriptor control
__IO uint8_t * currBufPtr; // Physical address of current buffer pointer
__IO HCTD * nextTD; // Physical pointer to next Transfer Descriptor
__IO uint8_t * bufEnd; // Physical address of end of buffer
void * ep; // ep address where a td is linked in
uint32_t dummy[3]; // padding
} HCTD;
} PACKED HCTD;

// ----------- HostController EndPoint Descriptor -------------
typedef __packed struct hcEd {
typedef struct hcEd {
__IO uint32_t control; // Endpoint descriptor control
__IO HCTD * tailTD; // Physical address of tail in Transfer descriptor list
__IO HCTD * headTD; // Physcial address of head in Transfer descriptor list
__IO hcEd * nextED; // Physical address of next Endpoint descriptor
} HCED;
} PACKED HCED;


// ----------- Host Controller Communication Area ------------
typedef __packed struct hcca {
typedef struct hcca {
__IO uint32_t IntTable[32]; // Interrupt Table
__IO uint32_t FrameNumber; // Frame Number
__IO uint32_t DoneHead; // Done Head
volatile uint8_t Reserved[116]; // Reserved for future use
volatile uint8_t Unknown[4]; // Unused
} HCCA;
} PACKED HCCA;

typedef __packed struct {
typedef struct {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB;
Expand All @@ -177,9 +178,9 @@ typedef __packed struct {
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
} DeviceDescriptor;
} PACKED DeviceDescriptor;

typedef __packed struct {
typedef struct {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
Expand All @@ -188,7 +189,7 @@ typedef __packed struct {
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
} ConfigurationDescriptor;
} PACKED ConfigurationDescriptor;

typedef struct {
uint8_t bLength;
Expand Down
12 changes: 6 additions & 6 deletions libraries/USBHost/USBHost/dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
#define DEBUG_EVENT 0

#if (DEBUG)
#define USB_DBG(x, ...) std::printf("[USB_DBG: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define USB_DBG(x, ...) std::printf("[USB_DBG: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#else
#define USB_DBG(x, ...)
#endif

#if (DEBUG_TRANSFER)
#define USB_DBG_TRANSFER(x, ...) std::printf("[USB_TRANSFER: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define USB_DBG_TRANSFER(x, ...) std::printf("[USB_TRANSFER: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#else
#define USB_DBG_TRANSFER(x, ...)
#endif

#if (DEBUG_EVENT)
#define USB_DBG_EVENT(x, ...) std::printf("[USB_EVENT: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define USB_DBG_EVENT(x, ...) std::printf("[USB_EVENT: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#else
#define USB_DBG_EVENT(x, ...)
#endif

#define USB_INFO(x, ...) std::printf("[USB_INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define USB_WARN(x, ...) std::printf("[USB_WARNING: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define USB_ERR(x, ...) std::printf("[USB_ERR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define USB_INFO(x, ...) std::printf("[USB_INFO: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define USB_WARN(x, ...) std::printf("[USB_WARNING: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define USB_ERR(x, ...) std::printf("[USB_ERR: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);

#endif

Expand Down
1 change: 0 additions & 1 deletion libraries/USBHost/USBHostHID/USBHostMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ bool USBHostMouse::connect() {

void USBHostMouse::rxHandler() {
int len_listen = int_in->getSize();
int len = int_in->getLengthTransferred();

if (onUpdate) {
(*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);
Expand Down
6 changes: 3 additions & 3 deletions libraries/USBHost/USBHostHub/USBHostHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void USBHostHub::rxHandler() {
host->deviceConnected(dev->getHub() + 1, port, status & PORT_LOW_SPEED, this);
} else {
USB_DBG("[hub handler hub: %d - port: %d] device disconnected", dev->getHub(), port);
host->deviceDisconnected(dev->getHub() + 1, port, this, NULL);
host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
}

clearPortFeature(C_PORT_CONNECTION_FEATURE, port);
Expand All @@ -209,7 +209,7 @@ void USBHostHub::rxHandler() {
if ((status & PORT_OVER_CURRENT)) {
USB_ERR("OVER CURRENT DETECTED\r\n");
clearPortFeature(PORT_OVER_CURRENT, port);
host->deviceDisconnected(dev->getHub() + 1, port, this, NULL);
host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
}
}
}
Expand All @@ -229,7 +229,7 @@ void USBHostHub::portReset(uint8_t port) {
if (status & PORT_OVER_CURRENT) {
USB_ERR("OVER CURRENT DETECTED\r\n");
clearPortFeature(PORT_OVER_CURRENT, port);
host->deviceDisconnected(dev->getHub() + 1, port, this, NULL);
host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
break;
}
Thread::wait(10);
Expand Down
2 changes: 1 addition & 1 deletion libraries/USBHost/USBHostMSD/USBHostMSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int USBHostMSD::SCSIRequestSense() {
int USBHostMSD::inquiry(uint8_t lun, uint8_t page_code) {
USB_DBG("Inquiry");
uint8_t evpd = (page_code == 0) ? 0 : 1;
uint8_t cmd[6] = {0x12, (lun << 5) | evpd, page_code, 0, 36, 0};
uint8_t cmd[6] = {0x12, uint8_t((lun << 5) | evpd), page_code, 0, 36, 0};
uint8_t result[36];
int status = SCSITransfer(cmd, 6, DEVICE_TO_HOST, result, 36);
if (status == 0) {
Expand Down
8 changes: 4 additions & 4 deletions libraries/USBHost/USBHostMSD/USBHostMSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,23 @@ class USBHostMSD : public IUSBEnumerator, public FATFileSystem {
uint8_t nb_ep;

// Bulk-only CBW
typedef __packed struct {
typedef struct {
uint32_t Signature;
uint32_t Tag;
uint32_t DataLength;
uint8_t Flags;
uint8_t LUN;
uint8_t CBLength;
uint8_t CB[16];
} CBW;
} PACKED CBW;

// Bulk-only CSW
typedef __packed struct {
typedef struct {
uint32_t Signature;
uint32_t Tag;
uint32_t DataResidue;
uint8_t Status;
} CSW;
} PACKED CSW;

CBW cbw;
CSW csw;
Expand Down
8 changes: 4 additions & 4 deletions libraries/USBHost/USBHostSerial/USBHostSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ void USBHostSerial::format(int bits, Parity parity, int stop_bits) {
line_coding.stop_bits = (stop_bits == 1) ? 0 : 2;

// set line coding
int res = host->controlWrite( dev,
USB_RECIPIENT_INTERFACE | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS,
SET_LINE_CODING,
0, serial_intf, (uint8_t *)&line_coding, 7);
host->controlWrite( dev,
USB_RECIPIENT_INTERFACE | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS,
SET_LINE_CODING,
0, serial_intf, (uint8_t *)&line_coding, 7);
}

int USBHostSerial::_getc() {
Expand Down
4 changes: 2 additions & 2 deletions libraries/USBHost/USBHostSerial/USBHostSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ class USBHostSerial : public IUSBEnumerator, public Stream {

uint8_t buf[64];

typedef __packed struct {
typedef struct {
uint32_t baudrate;
uint8_t stop_bits;
uint8_t parity;
uint8_t data_bits;
} LINE_CODING;
} PACKED LINE_CODING;

LINE_CODING line_coding;

Expand Down