Skip to content

Commit 8a6d5eb

Browse files
committed
USBHost: Updates to allow compilation with GCC_ARM
I updated a few things in the USBHost source code to get it to compile with GCC: * In USBHALHost.cpp, the usb_buf global variable was defined with two different aligmnent specifiers: static volatile __align(256) uint8_t usb_buf[TOTAL_SIZE] __attribute((section("AHBSRAM1"),aligned)); //256 bytes aligned! The first one was not accepted by GCC. I removed the duplicate alignment specifier and updated the one in the existing __attribute property to force the desired 256 byte alignment. * Removed the explicit use of the __packed property from structures and instead used the PACKED macro defined in the mbed SDK's toolchain.h header file. This macro does the right thing for the various compilers supported by the mbed team. * Updated USB_* message macros in dbg.h to place spaces around references to the 'x' macro parameter. Without this, C++ 11 compilation thought the x character was a string literal operator but it wasn't one it recognized. Adding the spaces makes it easier to see the use of the parameter, fixes this compile time error, and doesn't add any extra space to the final output string since the compiler only concatenates the contents within the double quotes of the strings. By the way, I build with the gnu++11 standard since I have had requests for its support from gcc4mbed. Some of the items fixed here might not be errors when using older standards with GCC. I built and tested a USBHostMSD sample with these updates using both GCC and the online compiler. I will test more of the host interfaces before issuing a pull request containing this commit.
1 parent e8bd53f commit 8a6d5eb

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

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/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/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.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)