Skip to content

Commit c1c082e

Browse files
cmagliefacchinm
authored andcommitted
Using __attribute__((packed)) instead of pragmas
1 parent 8f1ccb3 commit c1c082e

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

cores/arduino/USB/CDC.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ extern USBDevice_SAMD21G18x usbd;
3737

3838
#define CDC_LINESTATE_READY (CDC_LINESTATE_RTS | CDC_LINESTATE_DTR)
3939

40-
typedef struct {
40+
typedef struct __attribute__((packed)) {
4141
uint32_t dwDTERate;
4242
uint8_t bCharFormat;
4343
uint8_t bParityType;
4444
uint8_t bDataBits;
4545
uint8_t lineState;
4646
} LineInfo;
4747

48-
_Pragma("pack(1)")
4948
static volatile LineInfo _usbLineInfo = {
5049
115200, // dWDTERate
5150
0x00, // bCharFormat
@@ -55,7 +54,6 @@ static volatile LineInfo _usbLineInfo = {
5554
};
5655

5756
static volatile int32_t breakValue = -1;
58-
_Pragma("pack()")
5957

6058
// CDC
6159
#define CDC_ACM_INTERFACE pluggedInterface // CDC ACM

cores/arduino/USB/USBCore.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ uint32_t USBDeviceClass::sendConfiguration(uint32_t maxlen)
156156
_dry_run = true;
157157
uint8_t interfaces = SendInterfaces(&total);
158158

159-
_Pragma("pack(1)")
160159
ConfigDescriptor config = D_CONFIG((uint16_t)(total + sizeof(ConfigDescriptor)), interfaces);
161-
_Pragma("pack()")
162160

163161
// Now send them
164162
_dry_run = false;

cores/arduino/USB/USBCore.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@
107107
#define MSC_SUBCLASS_SCSI 0x06
108108
#define MSC_PROTOCOL_BULK_ONLY 0x50
109109

110-
_Pragma("pack(1)")
111-
112110
// Device
113-
typedef struct {
111+
typedef struct __attribute__((packed)) {
114112
uint8_t len; // 18
115113
uint8_t dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE
116114
uint16_t usbVersion; // 0x200
@@ -128,7 +126,7 @@ typedef struct {
128126
} DeviceDescriptor;
129127

130128
// Config
131-
typedef struct {
129+
typedef struct __attribute__((packed)) {
132130
uint8_t len; // 9
133131
uint8_t dtype; // 2
134132
uint16_t clen; // total length
@@ -142,8 +140,7 @@ typedef struct {
142140
// String
143141

144142
// Interface
145-
typedef struct
146-
{
143+
typedef struct __attribute__((packed)) {
147144
uint8_t len; // 9
148145
uint8_t dtype; // 4
149146
uint8_t number;
@@ -156,8 +153,7 @@ typedef struct
156153
} InterfaceDescriptor;
157154

158155
// Endpoint
159-
typedef struct
160-
{
156+
typedef struct __attribute__((packed)) {
161157
uint8_t len; // 7
162158
uint8_t dtype; // 5
163159
uint8_t addr;
@@ -168,8 +164,7 @@ typedef struct
168164

169165
// Interface Association Descriptor
170166
// Used to bind 2 interfaces together in CDC compostite device
171-
typedef struct
172-
{
167+
typedef struct __attribute__((packed)) {
173168
uint8_t len; // 8
174169
uint8_t dtype; // 11
175170
uint8_t firstInterface;
@@ -180,15 +175,12 @@ typedef struct
180175
uint8_t iInterface;
181176
} IADDescriptor;
182177

183-
typedef struct
184-
{
178+
typedef struct __attribute__((packed)) {
185179
InterfaceDescriptor msc;
186180
EndpointDescriptor in;
187181
EndpointDescriptor out;
188182
} MSCDescriptor;
189183

190-
_Pragma("pack()")
191-
192184
#define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
193185
{ 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
194186
/* Table 9-8. Standard Device Descriptor

0 commit comments

Comments
 (0)