Save memory (move usb mass storage buffer to reusableBuffer) (#5579)
* Save 128 byte by moving variable to stack * Make usb mass storage buffer smaller on F2 processors and put into reuseablebuffer - Lower USB mass storage buffer to 512 bytes per default on F2 targets, makes usb speed slightly slower ~600 kB/s instead ~700 KB/s in my tests, saving 3584 bytes - Save another ~300 bytes by putting that buffer into reusableBuffer * Don't put id into reusuableBuffer All uses of id can be on the stack as well. Makes no difference for ram usage but makes it safer to reuse reusableBuffer * Only link cdc serial when needed We always linked usb cdc even in non debug builds. CDC uses about ~600 byte of RAM for its buffers and structures.
This commit is contained in:
committed by
Bertrand Songis
parent
95df593c2f
commit
4925e756a6
@@ -38,14 +38,18 @@ set(FIRMWARE_TARGET_SRC
|
||||
../common/arm/stm32/usb_driver.cpp
|
||||
../common/arm/stm32/flash_driver.cpp
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_cdc.cpp
|
||||
|
||||
if(DEBUG)
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
|
||||
)
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_cdc.cpp
|
||||
)
|
||||
add_definitions(-DUSB_SERIAL)
|
||||
endif()
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
|
||||
|
||||
@@ -109,6 +109,7 @@ endif()
|
||||
remove_definitions(-DDISK_CACHE)
|
||||
remove_definitions(-DLUA)
|
||||
remove_definitions(-DCLI)
|
||||
remove_definitions(-DUSB_SERIAL)
|
||||
add_definitions(-DBOOT)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-mcpu=${MCU} -mthumb -nostartfiles -lm -T${RADIO_SRC_DIRECTORY}/targets/${TARGET_DIR}/stm32_ramboot.ld -Wl,-Map=bootloader.map,--cref,--no-warn-mismatch,--gc-sections")
|
||||
|
||||
@@ -91,6 +91,8 @@ void usbStart()
|
||||
// initialize USB as HID device
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_SERIAL)
|
||||
case USB_SERIAL_MODE:
|
||||
// initialize USB as CDC device (virtual serial port)
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
|
||||
|
||||
@@ -27,7 +27,7 @@ enum usbMode {
|
||||
USB_JOYSTICK_MODE,
|
||||
USB_MASS_STORAGE_MODE,
|
||||
USB_SERIAL_MODE,
|
||||
#if defined(DEBUG)
|
||||
#if defined(USB_SERIAL)
|
||||
USB_MAX_MODE=USB_SERIAL_MODE
|
||||
#else
|
||||
USB_MAX_MODE=USB_MASS_STORAGE_MODE
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#define _USBD_CONF_H_
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_conf.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
#define USBD_CFG_MAX_NUM 1
|
||||
#define USBD_ITF_MAX_NUM 1
|
||||
@@ -37,7 +37,12 @@
|
||||
#define MSC_OUT_EP 0x01
|
||||
#define MSC_MAX_PACKET 64
|
||||
|
||||
// Save some RAM on smaller STM32 processors. Slightly lowers USB mass storage speed
|
||||
#if defined(STM32F2) && !defined(BOOT)
|
||||
#define MSC_MEDIA_PACKET 512
|
||||
#else
|
||||
#define MSC_MEDIA_PACKET 4096
|
||||
#endif
|
||||
|
||||
#define HID_IN_EP 0x81
|
||||
#define HID_OUT_EP 0x01
|
||||
|
||||
Reference in New Issue
Block a user