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
@@ -32,8 +32,9 @@ void menuRadioVersion(event_t event)
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
char id[27];
|
||||
if (event == EVT_ENTRY) {
|
||||
getCPUUniqueID(reusableBuffer.version.id);
|
||||
getCPUUniqueID(id);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
void menuRadioVersion(event_t event)
|
||||
{
|
||||
char id[27];
|
||||
if (warningResult) {
|
||||
warningResult = 0;
|
||||
showMessageBox(STR_STORAGE_FORMAT);
|
||||
@@ -30,14 +31,14 @@ void menuRadioVersion(event_t event)
|
||||
}
|
||||
|
||||
if (event == EVT_ENTRY) {
|
||||
getCPUUniqueID(reusableBuffer.version.id);
|
||||
getCPUUniqueID(id);
|
||||
}
|
||||
|
||||
SIMPLE_MENU(STR_MENUVERSION, menuTabGeneral, MENU_RADIO_VERSION, 1);
|
||||
|
||||
lcdDrawTextAlignedLeft(MENU_HEADER_HEIGHT+1, vers_stamp);
|
||||
lcdDrawTextAlignedLeft(MENU_HEADER_HEIGHT+4*FH+1, "UID\037\033:");
|
||||
lcdDrawText(5*FW+3, MENU_HEADER_HEIGHT+4*FH+1, reusableBuffer.version.id);
|
||||
lcdDrawText(5*FW+3, MENU_HEADER_HEIGHT+4*FH+1, id);
|
||||
|
||||
lcdDrawTextAlignedLeft(MENU_HEADER_HEIGHT+5*FH+1, STR_EEBACKUP);
|
||||
lcdDrawTextAlignedLeft(MENU_HEADER_HEIGHT+6*FH+1, STR_FACTORYRESET);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
bool menuRadioVersion(event_t event)
|
||||
{
|
||||
char id[27];
|
||||
#if 0
|
||||
if (warningResult) {
|
||||
warningResult = 0;
|
||||
@@ -32,7 +33,7 @@ bool menuRadioVersion(event_t event)
|
||||
#endif
|
||||
|
||||
if (event == EVT_ENTRY) {
|
||||
getCPUUniqueID(reusableBuffer.version.id);
|
||||
getCPUUniqueID(id);
|
||||
}
|
||||
|
||||
SIMPLE_MENU(STR_MENUVERSION, RADIO_ICONS, menuTabGeneral, MENU_RADIO_VERSION, 0);
|
||||
@@ -42,7 +43,7 @@ bool menuRadioVersion(event_t event)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 3*FH, time_stamp);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 4*FH, eeprom_stamp);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 5*FH, "UID:");
|
||||
lcdDrawText(MENUS_MARGIN_LEFT + 64, MENU_CONTENT_TOP + 5*FH, reusableBuffer.version.id);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT + 64, MENU_CONTENT_TOP + 5*FH, id);
|
||||
|
||||
#if 0
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
|
||||
@@ -58,7 +58,7 @@ void handleUsbConnection()
|
||||
#endif
|
||||
POPUP_MENU_START(onUSBConnectMenu);
|
||||
}
|
||||
if (g_eeGeneral.USBMode != USB_UNSELECTED_MODE) {
|
||||
if (g_eeGeneral.USBMode != USB_UNSELECTED_MODE && g_eeGeneral.USBMode <= USB_MAX_MODE) {
|
||||
setSelectedUsbMode(g_eeGeneral.USBMode);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1089,7 +1089,6 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms)
|
||||
mixWarning = lv_mixWarning;
|
||||
}
|
||||
|
||||
int32_t sum_chans512[MAX_OUTPUT_CHANNELS] = {0};
|
||||
|
||||
|
||||
#define MAX_ACT 0xffff
|
||||
@@ -1102,6 +1101,7 @@ uint8_t flightModeTransitionLast = 255;
|
||||
|
||||
void evalMixes(uint8_t tick10ms)
|
||||
{
|
||||
int32_t sum_chans512[MAX_OUTPUT_CHANNELS] = {0};
|
||||
#if defined(PCBMEGA2560) && defined(DEBUG) && !defined(VOICE)
|
||||
PORTH |= 0x40; // PORTH:6 LOW->HIGH signals start of mixer interrupt
|
||||
#endif
|
||||
|
||||
@@ -49,7 +49,12 @@ uint8_t heartbeat;
|
||||
safetych_t safetyCh[MAX_OUTPUT_CHANNELS];
|
||||
#endif
|
||||
|
||||
union ReusableBuffer reusableBuffer;
|
||||
// __DMA for the MSC_BOT_Data member
|
||||
union ReusableBuffer reusableBuffer __DMA;
|
||||
|
||||
#if defined(STM32)
|
||||
uint8_t* MSC_BOT_Data = reusableBuffer.MSC_BOT_Data;
|
||||
#endif
|
||||
|
||||
const pm_uint8_t bchout_ar[] PROGMEM = {
|
||||
0x1B, 0x1E, 0x27, 0x2D, 0x36, 0x39,
|
||||
|
||||
+8
-6
@@ -27,6 +27,9 @@
|
||||
#include <stdlib.h>
|
||||
#include "definitions.h"
|
||||
#include "opentx_types.h"
|
||||
#if defined(STM32)
|
||||
#include "usbd_conf.h"
|
||||
#endif
|
||||
|
||||
#if defined(SIMU)
|
||||
#define SWITCH_SIMU(a, b) (a)
|
||||
@@ -1495,16 +1498,15 @@ union ReusableBuffer
|
||||
} sdmanager;
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
struct
|
||||
{
|
||||
char id[27];
|
||||
} version;
|
||||
#endif
|
||||
struct
|
||||
{
|
||||
uint8_t stickMode;
|
||||
} generalSettings;
|
||||
|
||||
#if defined(STM32)
|
||||
// Data for the USB mass storage driver. If USB mass storage runs no menu is not allowed to be displayed
|
||||
uint8_t MSC_BOT_Data[MSC_MEDIA_PACKET];
|
||||
#endif
|
||||
};
|
||||
|
||||
extern union ReusableBuffer reusableBuffer;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define PRINTF_BUFFER_SIZE 128
|
||||
|
||||
void serialPutc(char c) {
|
||||
#if !defined(BOOT)
|
||||
#if !defined(BOOT) && defined(USB_SERIAL)
|
||||
if (getSelectedUsbMode() == USB_SERIAL_MODE)
|
||||
usbSerialPutc(c);
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
@@ -27,6 +27,7 @@
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
|
||||
#include "usb_conf.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
@@ -111,7 +112,11 @@ MSC_BOT_CSW_TypeDef;
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(BOOT)
|
||||
extern uint8_t MSC_BOT_Data[];
|
||||
#else
|
||||
extern uint8_t* MSC_BOT_Data;
|
||||
#endif
|
||||
extern uint16_t MSC_BOT_DataLen;
|
||||
extern uint8_t MSC_BOT_State;
|
||||
extern uint8_t MSC_BOT_BurstMode;
|
||||
|
||||
+3
-1
@@ -80,7 +80,9 @@ uint8_t MSC_BOT_Status;
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
|
||||
#include "definitions.h"
|
||||
uint8_t MSC_BOT_Data[MSC_MEDIA_PACKET] __DMA; // modified by OpenTX
|
||||
#if defined(BOOT)
|
||||
uint8_t MSC_BOT_Data[MSC_MEDIA_PACKET] __DMA; // modified by OpenTX
|
||||
#endif
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
|
||||
Reference in New Issue
Block a user