mirror of https://github.com/ARMmbed/mbed-os.git
Tests: USB: Move control endpoint buffers to heap
This fixes the stack overflow error during the basic USB tests. Update the ctrl_buf member of the USBTester and USBEndpointTester test classes to be allocated on the heap. This saves 2 KB of a main stack.pull/11607/head
parent
31114ba343
commit
71d9bd9568
|
@ -40,6 +40,8 @@
|
|||
#define VENDOR_TEST_RW_RESTART 11
|
||||
#define VENDOR_TEST_ABORT_BUFF_CHECK 12
|
||||
|
||||
#define CTRL_BUF_SIZE (2048)
|
||||
|
||||
#define EVENT_READY (1 << 0)
|
||||
|
||||
#define TEST_SIZE_EP_BULK_MAX (64)
|
||||
|
@ -170,6 +172,7 @@ USBEndpointTester::USBEndpointTester(USBPhy *phy, uint16_t vendor_id, uint16_t p
|
|||
|
||||
queue = mbed::mbed_highprio_event_queue();
|
||||
configuration_desc(0);
|
||||
ctrl_buf = new uint8_t[CTRL_BUF_SIZE];
|
||||
init();
|
||||
USBDevice::connect();
|
||||
flags.wait_any(EVENT_READY, osWaitForever, false);
|
||||
|
@ -183,6 +186,7 @@ USBEndpointTester::~USBEndpointTester()
|
|||
}
|
||||
}
|
||||
deinit();
|
||||
delete[] ctrl_buf;
|
||||
}
|
||||
|
||||
const char *USBEndpointTester::get_desc_string(const uint8_t *desc)
|
||||
|
@ -225,7 +229,7 @@ void USBEndpointTester::callback_request(const setup_packet_t *setup)
|
|||
case VENDOR_TEST_CTRL_IN:
|
||||
result = Send;
|
||||
data = ctrl_buf;
|
||||
size = setup->wValue < sizeof(ctrl_buf) ? setup->wValue : sizeof(ctrl_buf);
|
||||
size = setup->wValue < CTRL_BUF_SIZE ? setup->wValue : CTRL_BUF_SIZE;
|
||||
break;
|
||||
case VENDOR_TEST_CTRL_OUT:
|
||||
result = Receive;
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
#include "USBDevice_Types.h"
|
||||
#include "EventQueue.h"
|
||||
#include "EventFlags.h"
|
||||
#include "platform/NonCopyable.h"
|
||||
|
||||
#include "USBDevice.h"
|
||||
|
||||
#define NUM_ENDPOINTS 6 // Not including CTRL OUT/IN
|
||||
|
||||
class USBEndpointTester: public USBDevice {
|
||||
class USBEndpointTester: public USBDevice, private mbed::NonCopyable<USBEndpointTester> {
|
||||
|
||||
public:
|
||||
USBEndpointTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release,
|
||||
|
@ -80,7 +81,7 @@ public:
|
|||
protected:
|
||||
events::EventQueue *queue;
|
||||
rtos::EventFlags flags;
|
||||
uint8_t ctrl_buf[2048];
|
||||
uint8_t *ctrl_buf;
|
||||
|
||||
bool _abort_transfer_test;
|
||||
usb_ep_t _endpoints[NUM_ENDPOINTS];
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#define MAX_EP_SIZE 64
|
||||
#define MIN_EP_SIZE 8
|
||||
|
||||
#define CTRL_BUF_SIZE (2048)
|
||||
|
||||
#define EVENT_READY (1 << 0)
|
||||
|
||||
|
||||
|
@ -57,7 +59,7 @@ USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
|
|||
queue = mbed::mbed_highprio_event_queue();
|
||||
|
||||
configuration_desc(0);
|
||||
|
||||
ctrl_buf = new uint8_t[CTRL_BUF_SIZE];
|
||||
init();
|
||||
USBDevice::connect();
|
||||
flags.wait_any(EVENT_READY, osWaitForever, false);
|
||||
|
@ -67,6 +69,7 @@ USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
|
|||
USBTester::~USBTester()
|
||||
{
|
||||
deinit();
|
||||
delete[] ctrl_buf;
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,7 +141,7 @@ void USBTester::callback_request(const setup_packet_t *setup)
|
|||
case VENDOR_TEST_CTRL_IN:
|
||||
result = Send;
|
||||
data = ctrl_buf;
|
||||
size = setup->wValue < sizeof(ctrl_buf) ? setup->wValue : sizeof(ctrl_buf);
|
||||
size = setup->wValue < CTRL_BUF_SIZE ? setup->wValue : CTRL_BUF_SIZE;
|
||||
break;
|
||||
case VENDOR_TEST_CTRL_OUT:
|
||||
result = Receive;
|
||||
|
|
|
@ -23,10 +23,11 @@
|
|||
#include "USBDevice_Types.h"
|
||||
#include "EventQueue.h"
|
||||
#include "EventFlags.h"
|
||||
#include "platform/NonCopyable.h"
|
||||
|
||||
#include "USBDevice.h"
|
||||
|
||||
class USBTester: public USBDevice {
|
||||
class USBTester: public USBDevice, private mbed::NonCopyable<USBTester> {
|
||||
public:
|
||||
|
||||
/*
|
||||
|
@ -138,7 +139,7 @@ protected:
|
|||
virtual void epbulk_out_callback();
|
||||
virtual void epint_out_callback();
|
||||
virtual void callback_reset();
|
||||
uint8_t ctrl_buf[2048];
|
||||
uint8_t *ctrl_buf;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue