From e6f670440832f519464b19f497b4cac9476de548 Mon Sep 17 00:00:00 2001 From: Anton Staaf Date: Mon, 2 Mar 2015 14:48:27 -0800 Subject: USB Stream: Make RX and TX buffer sizes configurable Previously the USB Stream buffer sizes were fixed at USB_MAX_PACKET_SIZE (currently 64 bytes). But that ended up using up too much packet RAM, a very limited resource. This change makes them configurable and adds asserts to insure that the sizes are valid for the underlying hardware. Signed-off-by: Anton Staaf BRANCH=None BUG=None TEST=make buildall -j Verify that USART forwarding on discovery works Change-Id: Ib19c0dcfa9b16f23c1d72a5a7fc18026ab103f05 Reviewed-on: https://chromium-review.googlesource.com/255232 Trybot-Ready: Anton Staaf Tested-by: Anton Staaf Reviewed-by: Vic Yang Commit-Queue: Anton Staaf --- chip/stm32/usb-stream.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'chip/stm32/usb-stream.c') diff --git a/chip/stm32/usb-stream.c b/chip/stm32/usb-stream.c index 42d9d3774c..05351a8ca3 100644 --- a/chip/stm32/usb-stream.c +++ b/chip/stm32/usb-stream.c @@ -36,7 +36,7 @@ static size_t tx_write(struct usb_stream_config const *config) { size_t count = consumer_read_memcpy(&config->consumer, config->tx_ram, - USB_MAX_PACKET_SIZE, + config->tx_size, memcpy_to_usbram); btable_ep[config->endpoint].tx_count = count; @@ -120,6 +120,14 @@ void usb_stream_rx(struct usb_stream_config const *config) } } +static usb_uint usb_ep_rx_size(size_t bytes) +{ + if (bytes < 64) + return bytes << 9; + else + return 0x8000 | ((bytes - 32) << 5); +} + void usb_stream_reset(struct usb_stream_config const *config) { int i = config->endpoint; @@ -128,7 +136,7 @@ void usb_stream_reset(struct usb_stream_config const *config) btable_ep[i].tx_count = 0; btable_ep[i].rx_addr = usb_sram_addr(config->rx_ram); - btable_ep[i].rx_count = 0x8000 | ((USB_MAX_PACKET_SIZE / 32 - 1) << 10); + btable_ep[i].rx_count = usb_ep_rx_size(config->rx_size); config->state->rx_waiting = 0; -- cgit v1.2.1