Skip to content

Commit ef4fe98

Browse files
authored
Merge pull request #11607 from fkjagodzinski/fix-usb_device-basic_test
Tests: USB: Move control endpoint buffers to heap
2 parents 51680cb + 71d9bd9 commit ef4fe98

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

TESTS/usb_device/basic/USBEndpointTester.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define VENDOR_TEST_RW_RESTART 11
4141
#define VENDOR_TEST_ABORT_BUFF_CHECK 12
4242

43+
#define CTRL_BUF_SIZE (2048)
44+
4345
#define EVENT_READY (1 << 0)
4446

4547
#define TEST_SIZE_EP_BULK_MAX (64)
@@ -170,6 +172,7 @@ USBEndpointTester::USBEndpointTester(USBPhy *phy, uint16_t vendor_id, uint16_t p
170172

171173
queue = mbed::mbed_highprio_event_queue();
172174
configuration_desc(0);
175+
ctrl_buf = new uint8_t[CTRL_BUF_SIZE];
173176
init();
174177
USBDevice::connect();
175178
flags.wait_any(EVENT_READY, osWaitForever, false);
@@ -183,6 +186,7 @@ USBEndpointTester::~USBEndpointTester()
183186
}
184187
}
185188
deinit();
189+
delete[] ctrl_buf;
186190
}
187191

188192
const char *USBEndpointTester::get_desc_string(const uint8_t *desc)
@@ -225,7 +229,7 @@ void USBEndpointTester::callback_request(const setup_packet_t *setup)
225229
case VENDOR_TEST_CTRL_IN:
226230
result = Send;
227231
data = ctrl_buf;
228-
size = setup->wValue < sizeof(ctrl_buf) ? setup->wValue : sizeof(ctrl_buf);
232+
size = setup->wValue < CTRL_BUF_SIZE ? setup->wValue : CTRL_BUF_SIZE;
229233
break;
230234
case VENDOR_TEST_CTRL_OUT:
231235
result = Receive;

TESTS/usb_device/basic/USBEndpointTester.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
#include "USBDevice_Types.h"
2424
#include "EventQueue.h"
2525
#include "EventFlags.h"
26+
#include "platform/NonCopyable.h"
2627

2728
#include "USBDevice.h"
2829

2930
#define NUM_ENDPOINTS 6 // Not including CTRL OUT/IN
3031

31-
class USBEndpointTester: public USBDevice {
32+
class USBEndpointTester: public USBDevice, private mbed::NonCopyable<USBEndpointTester> {
3233

3334
public:
3435
USBEndpointTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release,
@@ -80,7 +81,7 @@ class USBEndpointTester: public USBDevice {
8081
protected:
8182
events::EventQueue *queue;
8283
rtos::EventFlags flags;
83-
uint8_t ctrl_buf[2048];
84+
uint8_t *ctrl_buf;
8485

8586
bool _abort_transfer_test;
8687
usb_ep_t _endpoints[NUM_ENDPOINTS];

TESTS/usb_device/basic/USBTester.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#define MAX_EP_SIZE 64
3838
#define MIN_EP_SIZE 8
3939

40+
#define CTRL_BUF_SIZE (2048)
41+
4042
#define EVENT_READY (1 << 0)
4143

4244

@@ -57,7 +59,7 @@ USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
5759
queue = mbed::mbed_highprio_event_queue();
5860

5961
configuration_desc(0);
60-
62+
ctrl_buf = new uint8_t[CTRL_BUF_SIZE];
6163
init();
6264
USBDevice::connect();
6365
flags.wait_any(EVENT_READY, osWaitForever, false);
@@ -67,6 +69,7 @@ USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
6769
USBTester::~USBTester()
6870
{
6971
deinit();
72+
delete[] ctrl_buf;
7073
}
7174

7275

@@ -138,7 +141,7 @@ void USBTester::callback_request(const setup_packet_t *setup)
138141
case VENDOR_TEST_CTRL_IN:
139142
result = Send;
140143
data = ctrl_buf;
141-
size = setup->wValue < sizeof(ctrl_buf) ? setup->wValue : sizeof(ctrl_buf);
144+
size = setup->wValue < CTRL_BUF_SIZE ? setup->wValue : CTRL_BUF_SIZE;
142145
break;
143146
case VENDOR_TEST_CTRL_OUT:
144147
result = Receive;

TESTS/usb_device/basic/USBTester.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
#include "USBDevice_Types.h"
2424
#include "EventQueue.h"
2525
#include "EventFlags.h"
26+
#include "platform/NonCopyable.h"
2627

2728
#include "USBDevice.h"
2829

29-
class USBTester: public USBDevice {
30+
class USBTester: public USBDevice, private mbed::NonCopyable<USBTester> {
3031
public:
3132

3233
/*
@@ -138,7 +139,7 @@ class USBTester: public USBDevice {
138139
virtual void epbulk_out_callback();
139140
virtual void epint_out_callback();
140141
virtual void callback_reset();
141-
uint8_t ctrl_buf[2048];
142+
uint8_t *ctrl_buf;
142143

143144
};
144145

0 commit comments

Comments
 (0)