Skip to content

Commit 762df4c

Browse files
committed
perf(usbh_serial): optimize memory usage and add shell cmd switch
Includes: 1. Add `CONFIG_USBHOST_SERIAL_CMD` in Kconfig to allow disable/enable the `usbh_serial` command. 2. Wrap the `usbh_serial` command and `g_serial_testbuffer` with the macro to save resources when not needed. Result: - Flash: Reduced by ~0.9KB (text) + potential stdlib removal (snprintf/atoi). - RAM: Reduced by 512 Bytes (NoCache Data).
1 parent fb6dbb4 commit 762df4c

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed

Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ if CHERRYUSB
436436
prompt "Set host serial rx max buffer size"
437437
default 2048
438438

439+
config USBHOST_SERIAL_CMD
440+
bool
441+
prompt "Enable usbh_serial command for shell"
442+
default n
443+
depends on USBHOST_SERIAL
444+
439445
menu "Select USB host template, please select class driver first"
440446
config TEST_USBH_SERIAL
441447
bool

Kconfig.rtt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ if RT_USING_CHERRYUSB
453453
prompt "Set host serial rx max buffer size"
454454
default 2048
455455

456+
config CONFIG_USBHOST_SERIAL_CMD
457+
bool
458+
prompt "Enable usbh_serial command for shell"
459+
default n
460+
depends on CONFIG_USBHOST_SERIAL
461+
456462
config RT_LWIP_PBUF_POOL_BUFSIZE
457463
int "The size of each pbuf in the pbuf pool"
458464
range 1500 2000

Kconfig.rttpkg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ if PKG_USING_CHERRYUSB
452452
prompt "Set host serial rx max buffer size"
453453
default 2048
454454

455+
config CONFIG_USBHOST_SERIAL_CMD
456+
bool
457+
prompt "Enable usbh_serial command for shell"
458+
default n
459+
depends on CONFIG_USBHOST_SERIAL
460+
455461
config RT_LWIP_PBUF_POOL_BUFSIZE
456462
int "The size of each pbuf in the pbuf pool"
457463
range 1500 2000

class/serial/usbh_serial.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ int usbh_serial_cdc_read_async(struct usbh_serial *serial, uint8_t *buffer, uint
618618
return usbh_submit_urb(urb);
619619
}
620620

621+
#ifdef CONFIG_USBHOST_SERIAL_CMD
621622
void usbh_serial_help(void)
622623
{
623624
USB_LOG_RAW("USB host serial test\r\n"
@@ -702,6 +703,7 @@ int usbh_serial(int argc, char **argv)
702703

703704
return 0;
704705
}
706+
#endif
705707

706708
__WEAK void usbh_serial_run(struct usbh_serial *serial)
707709
{

class/serial/usbh_serial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ int usbh_serial_cdc_read_async(struct usbh_serial *serial, uint8_t *buffer, uint
173173
void usbh_serial_run(struct usbh_serial *serial);
174174
void usbh_serial_stop(struct usbh_serial *serial);
175175

176+
#ifdef CONFIG_USBHOST_SERIAL_CMD
176177
int usbh_serial(int argc, char **argv);
178+
#endif
177179

178180
#ifdef __cplusplus
179181
}

platform/rtthread/usb_msh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ MSH_CMD_EXPORT(usbh_init, init usb host);
4545
MSH_CMD_EXPORT(usbh_deinit, deinit usb host);
4646
MSH_CMD_EXPORT(lsusb, ls usb devices);
4747

48-
#ifdef CONFIG_USBHOST_SERIAL
48+
#if defined(CONFIG_USBHOST_SERIAL) && defined(CONFIG_USBHOST_SERIAL_CMD)
4949
#include "usbh_serial.h"
5050
MSH_CMD_EXPORT(usbh_serial, usbh_serial test);
5151
#endif

tests/hpmicro/inc/usb_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@
268268
#define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
269269
#endif
270270

271+
/* For CI/CD tests */
272+
#ifndef CONFIG_USBHOST_SERIAL_CMD
273+
#define CONFIG_USBHOST_SERIAL_CMD 1
274+
#endif
275+
271276
/* ================ USB Device Port Configuration ================*/
272277

273278
#define CONFIG_USBDEV_MAX_BUS USB_SOC_MAX_COUNT

0 commit comments

Comments
 (0)