Skip to content

Commit 061259c

Browse files
committed
Merge pull request #67 from adamgreen/gccFixUSBHost
Get USBHost to build and run with GCC_ARM
2 parents 2481fbe + 2056ad0 commit 061259c

File tree

11 files changed

+43
-43
lines changed

11 files changed

+43
-43
lines changed

libraries/USBHost/USBHost/USBEndpoint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir
2727

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

3333
td_list[0]->ep = this;
3434
td_list[1]->ep = this;

libraries/USBHost/USBHost/USBHALHost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

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

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

4444
USBHALHost * USBHALHost::instHost;
4545

libraries/USBHost/USBHost/USBHost.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ void USBHost::usb_process() {
9696

9797
if (i == MAX_DEVICE_CONNECTED) {
9898
USB_ERR("Too many device connected!!\r\n");
99-
deviceInited[i] = false;
10099
usb_mutex.unlock();
101100
continue;
102101
}
@@ -287,7 +286,7 @@ void USBHost::transferCompleted(volatile uint32_t addr)
287286
{
288287
uint8_t state;
289288

290-
if(addr == NULL)
289+
if(addr == 0)
291290
return;
292291

293292
volatile HCTD* tdList = NULL;
@@ -482,6 +481,8 @@ void USBHost::unqueueEndpoint(USBEndpoint * ep)
482481
case INTERRUPT_ENDPOINT:
483482
tailInterruptEndpoint = prec;
484483
break;
484+
default:
485+
break;
485486
}
486487
}
487488
current->setState(USB_TYPE_FREE);
@@ -1152,13 +1153,12 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,
11521153

11531154
void USBHost::fillControlBuf(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index, int len)
11541155
{
1155-
#ifdef __BIG_ENDIAN
1156-
#error "Must implement BE to LE conv here"
1157-
#endif
11581156
setupPacket[0] = requestType;
11591157
setupPacket[1] = request;
1160-
//We are in LE so it's fine
1161-
*((uint16_t*)&setupPacket[2]) = value;
1162-
*((uint16_t*)&setupPacket[4]) = index;
1163-
*((uint16_t*)&setupPacket[6]) = (uint32_t) len;
1158+
setupPacket[2] = (uint8_t) value;
1159+
setupPacket[3] = (uint8_t) (value >> 8);
1160+
setupPacket[4] = (uint8_t) index;
1161+
setupPacket[5] = (uint8_t) (index >> 8);
1162+
setupPacket[6] = (uint8_t) len;
1163+
setupPacket[7] = (uint8_t) (len >> 8);
11641164
}

libraries/USBHost/USBHost/USBHostTypes.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define USB_INC_H
1919

2020
#include "mbed.h"
21+
#include "toolchain.h"
2122

2223
enum USB_TYPE {
2324
USB_TYPE_OK = 0,
@@ -135,34 +136,34 @@ enum ENDPOINT_TYPE {
135136
#define CONFIGURATION_DESCRIPTOR_LENGTH 0x09
136137

137138
// ------------ HostController Transfer Descriptor ------------
138-
typedef __packed struct HCTD {
139+
typedef struct HCTD {
139140
__IO uint32_t control; // Transfer descriptor control
140141
__IO uint8_t * currBufPtr; // Physical address of current buffer pointer
141142
__IO HCTD * nextTD; // Physical pointer to next Transfer Descriptor
142143
__IO uint8_t * bufEnd; // Physical address of end of buffer
143144
void * ep; // ep address where a td is linked in
144145
uint32_t dummy[3]; // padding
145-
} HCTD;
146+
} PACKED HCTD;
146147

147148
// ----------- HostController EndPoint Descriptor -------------
148-
typedef __packed struct hcEd {
149+
typedef struct hcEd {
149150
__IO uint32_t control; // Endpoint descriptor control
150151
__IO HCTD * tailTD; // Physical address of tail in Transfer descriptor list
151152
__IO HCTD * headTD; // Physcial address of head in Transfer descriptor list
152153
__IO hcEd * nextED; // Physical address of next Endpoint descriptor
153-
} HCED;
154+
} PACKED HCED;
154155

155156

156157
// ----------- Host Controller Communication Area ------------
157-
typedef __packed struct hcca {
158+
typedef struct hcca {
158159
__IO uint32_t IntTable[32]; // Interrupt Table
159160
__IO uint32_t FrameNumber; // Frame Number
160161
__IO uint32_t DoneHead; // Done Head
161162
volatile uint8_t Reserved[116]; // Reserved for future use
162163
volatile uint8_t Unknown[4]; // Unused
163-
} HCCA;
164+
} PACKED HCCA;
164165

165-
typedef __packed struct {
166+
typedef struct {
166167
uint8_t bLength;
167168
uint8_t bDescriptorType;
168169
uint16_t bcdUSB;
@@ -177,9 +178,9 @@ typedef __packed struct {
177178
uint8_t iProduct;
178179
uint8_t iSerialNumber;
179180
uint8_t bNumConfigurations;
180-
} DeviceDescriptor;
181+
} PACKED DeviceDescriptor;
181182

182-
typedef __packed struct {
183+
typedef struct {
183184
uint8_t bLength;
184185
uint8_t bDescriptorType;
185186
uint16_t wTotalLength;
@@ -188,7 +189,7 @@ typedef __packed struct {
188189
uint8_t iConfiguration;
189190
uint8_t bmAttributes;
190191
uint8_t bMaxPower;
191-
} ConfigurationDescriptor;
192+
} PACKED ConfigurationDescriptor;
192193

193194
typedef struct {
194195
uint8_t bLength;

libraries/USBHost/USBHost/dbg.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@
2424
#define DEBUG_EVENT 0
2525

2626
#if (DEBUG)
27-
#define USB_DBG(x, ...) std::printf("[USB_DBG: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
27+
#define USB_DBG(x, ...) std::printf("[USB_DBG: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
2828
#else
2929
#define USB_DBG(x, ...)
3030
#endif
3131

3232
#if (DEBUG_TRANSFER)
33-
#define USB_DBG_TRANSFER(x, ...) std::printf("[USB_TRANSFER: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
33+
#define USB_DBG_TRANSFER(x, ...) std::printf("[USB_TRANSFER: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
3434
#else
3535
#define USB_DBG_TRANSFER(x, ...)
3636
#endif
3737

3838
#if (DEBUG_EVENT)
39-
#define USB_DBG_EVENT(x, ...) std::printf("[USB_EVENT: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
39+
#define USB_DBG_EVENT(x, ...) std::printf("[USB_EVENT: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
4040
#else
4141
#define USB_DBG_EVENT(x, ...)
4242
#endif
4343

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

4848
#endif
4949

libraries/USBHost/USBHostHID/USBHostMouse.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ bool USBHostMouse::connect() {
8282

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

8786
if (onUpdate) {
8887
(*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);

libraries/USBHost/USBHostHub/USBHostHub.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void USBHostHub::rxHandler() {
192192
host->deviceConnected(dev->getHub() + 1, port, status & PORT_LOW_SPEED, this);
193193
} else {
194194
USB_DBG("[hub handler hub: %d - port: %d] device disconnected", dev->getHub(), port);
195-
host->deviceDisconnected(dev->getHub() + 1, port, this, NULL);
195+
host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
196196
}
197197

198198
clearPortFeature(C_PORT_CONNECTION_FEATURE, port);
@@ -209,7 +209,7 @@ void USBHostHub::rxHandler() {
209209
if ((status & PORT_OVER_CURRENT)) {
210210
USB_ERR("OVER CURRENT DETECTED\r\n");
211211
clearPortFeature(PORT_OVER_CURRENT, port);
212-
host->deviceDisconnected(dev->getHub() + 1, port, this, NULL);
212+
host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
213213
}
214214
}
215215
}
@@ -229,7 +229,7 @@ void USBHostHub::portReset(uint8_t port) {
229229
if (status & PORT_OVER_CURRENT) {
230230
USB_ERR("OVER CURRENT DETECTED\r\n");
231231
clearPortFeature(PORT_OVER_CURRENT, port);
232-
host->deviceDisconnected(dev->getHub() + 1, port, this, NULL);
232+
host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
233233
break;
234234
}
235235
Thread::wait(10);

libraries/USBHost/USBHostMSD/USBHostMSD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ int USBHostMSD::SCSIRequestSense() {
154154
int USBHostMSD::inquiry(uint8_t lun, uint8_t page_code) {
155155
USB_DBG("Inquiry");
156156
uint8_t evpd = (page_code == 0) ? 0 : 1;
157-
uint8_t cmd[6] = {0x12, (lun << 5) | evpd, page_code, 0, 36, 0};
157+
uint8_t cmd[6] = {0x12, uint8_t((lun << 5) | evpd), page_code, 0, 36, 0};
158158
uint8_t result[36];
159159
int status = SCSITransfer(cmd, 6, DEVICE_TO_HOST, result, 36);
160160
if (status == 0) {

libraries/USBHost/USBHostMSD/USBHostMSD.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ class USBHostMSD : public IUSBEnumerator, public FATFileSystem {
7373
uint8_t nb_ep;
7474

7575
// Bulk-only CBW
76-
typedef __packed struct {
76+
typedef struct {
7777
uint32_t Signature;
7878
uint32_t Tag;
7979
uint32_t DataLength;
8080
uint8_t Flags;
8181
uint8_t LUN;
8282
uint8_t CBLength;
8383
uint8_t CB[16];
84-
} CBW;
84+
} PACKED CBW;
8585

8686
// Bulk-only CSW
87-
typedef __packed struct {
87+
typedef struct {
8888
uint32_t Signature;
8989
uint32_t Tag;
9090
uint32_t DataResidue;
9191
uint8_t Status;
92-
} CSW;
92+
} PACKED CSW;
9393

9494
CBW cbw;
9595
CSW csw;

libraries/USBHost/USBHostSerial/USBHostSerial.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ void USBHostSerial::format(int bits, Parity parity, int stop_bits) {
131131
line_coding.stop_bits = (stop_bits == 1) ? 0 : 2;
132132

133133
// set line coding
134-
int res = host->controlWrite( dev,
135-
USB_RECIPIENT_INTERFACE | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS,
136-
SET_LINE_CODING,
137-
0, serial_intf, (uint8_t *)&line_coding, 7);
134+
host->controlWrite( dev,
135+
USB_RECIPIENT_INTERFACE | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS,
136+
SET_LINE_CODING,
137+
0, serial_intf, (uint8_t *)&line_coding, 7);
138138
}
139139

140140
int USBHostSerial::_getc() {

libraries/USBHost/USBHostSerial/USBHostSerial.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ class USBHostSerial : public IUSBEnumerator, public Stream {
142142

143143
uint8_t buf[64];
144144

145-
typedef __packed struct {
145+
typedef struct {
146146
uint32_t baudrate;
147147
uint8_t stop_bits;
148148
uint8_t parity;
149149
uint8_t data_bits;
150-
} LINE_CODING;
150+
} PACKED LINE_CODING;
151151

152152
LINE_CODING line_coding;
153153

0 commit comments

Comments
 (0)