summaryrefslogtreecommitdiff
path: root/components/drivers/usb/cherryusb/platform/rtthread
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2024-09-01 00:24:37 +0800
committerMeco Man <[email protected]>2024-09-02 00:37:35 -0400
commit9511e4bd19d558c2f15f027480dee6d209b36e57 (patch)
tree42121d35dfeb475c67e834e2eff9cbacc50c01ec /components/drivers/usb/cherryusb/platform/rtthread
parentb462daf57e92b9e40e06b9a59b704e4ed1fd2b77 (diff)
update(cherryusb): fix dfs mem leak, add check for lwip stack size, select elmfat when use msc
Diffstat (limited to 'components/drivers/usb/cherryusb/platform/rtthread')
-rw-r--r--components/drivers/usb/cherryusb/platform/rtthread/usb_check.c4
-rw-r--r--components/drivers/usb/cherryusb/platform/rtthread/usbh_dfs.c18
-rw-r--r--components/drivers/usb/cherryusb/platform/rtthread/usbh_lwip.c4
3 files changed, 19 insertions, 7 deletions
diff --git a/components/drivers/usb/cherryusb/platform/rtthread/usb_check.c b/components/drivers/usb/cherryusb/platform/rtthread/usb_check.c
index 79ab320746..be16ea1495 100644
--- a/components/drivers/usb/cherryusb/platform/rtthread/usb_check.c
+++ b/components/drivers/usb/cherryusb/platform/rtthread/usb_check.c
@@ -7,11 +7,11 @@
#endif
#if IDLE_THREAD_STACK_SIZE < 2048
-#error "IDLE_THREAD_STACK_SIZE must be greater than or equal to 2048"
+#error "IDLE_THREAD_STACK_SIZE must be >= 2048"
#endif
#if RT_TIMER_THREAD_STACK_SIZE < 2048
-#error "RT_TIMER_THREAD_STACK_SIZE must be greater than or equal to 2048"
+#error "RT_TIMER_THREAD_STACK_SIZE must be >= 2048"
#endif
#endif
diff --git a/components/drivers/usb/cherryusb/platform/rtthread/usbh_dfs.c b/components/drivers/usb/cherryusb/platform/rtthread/usbh_dfs.c
index 745ea5ea29..073d52ea4e 100644
--- a/components/drivers/usb/cherryusb/platform/rtthread/usbh_dfs.c
+++ b/components/drivers/usb/cherryusb/platform/rtthread/usbh_dfs.c
@@ -9,7 +9,7 @@
#include "rtthread.h"
#include <dfs_fs.h>
-#define DEV_FORMAT "/sd%c"
+#define DEV_FORMAT "/dev/sd%c"
#ifndef CONFIG_USB_DFS_MOUNT_POINT
#define CONFIG_USB_DFS_MOUNT_POINT "/"
@@ -46,7 +46,7 @@ static rt_err_t rt_udisk_init(rt_device_t dev)
}
static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer,
- rt_size_t size)
+ rt_size_t size)
{
struct usbh_msc *msc_class = (struct usbh_msc *)dev->user_data;
int ret;
@@ -85,7 +85,7 @@ static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer,
}
static ssize_t rt_udisk_write(rt_device_t dev, rt_off_t pos, const void *buffer,
- rt_size_t size)
+ rt_size_t size)
{
struct usbh_msc *msc_class = (struct usbh_msc *)dev->user_data;
int ret;
@@ -175,15 +175,17 @@ int udisk_init(struct usbh_msc *msc_class)
ret = usbh_msc_scsi_read10(msc_class, 0, msc_sector, 1);
if (ret != RT_EOK) {
rt_kprintf("usb mass_storage read failed\n");
+ rt_free(dev);
return ret;
}
- for (i = 0; i < 16; i++) {
+ for (i = 0; i < 4; i++) {
/* Get the first partition */
ret = dfs_filesystem_get_partition(&part0, msc_sector, i);
if (ret == RT_EOK) {
rt_kprintf("Found partition %d: type = %d, offet=0x%x, size=0x%x\n",
i, part0.type, part0.offset, part0.size);
+ break;
} else {
break;
}
@@ -219,6 +221,8 @@ void usbh_msc_run(struct usbh_msc *msc_class)
void usbh_msc_stop(struct usbh_msc *msc_class)
{
+ struct rt_device *dev;
+
char name[CONFIG_USBHOST_DEV_NAMELEN];
char mount_point[CONFIG_USBHOST_DEV_NAMELEN];
@@ -226,5 +230,9 @@ void usbh_msc_stop(struct usbh_msc *msc_class)
snprintf(mount_point, CONFIG_USBHOST_DEV_NAMELEN, CONFIG_USB_DFS_MOUNT_POINT, msc_class->sdchar);
dfs_unmount(mount_point);
- rt_device_unregister(rt_device_find(name));
+ dev = rt_device_find(name);
+ if (dev) {
+ rt_device_unregister(dev);
+ rt_free(dev);
+ }
}
diff --git a/components/drivers/usb/cherryusb/platform/rtthread/usbh_lwip.c b/components/drivers/usb/cherryusb/platform/rtthread/usbh_lwip.c
index 360a848953..1211b337d1 100644
--- a/components/drivers/usb/cherryusb/platform/rtthread/usbh_lwip.c
+++ b/components/drivers/usb/cherryusb/platform/rtthread/usbh_lwip.c
@@ -44,6 +44,10 @@
#error PBUF_POOL_BUFSIZE must be larger than 1600
#endif
+#if RT_LWIP_TCPTHREAD_STACKSIZE < 2048
+#error RT_LWIP_TCPTHREAD_STACKSIZE must be larger than 2048
+#endif
+
// #define CONFIG_USBHOST_PLATFORM_CDC_ECM
// #define CONFIG_USBHOST_PLATFORM_CDC_RNDIS
// #define CONFIG_USBHOST_PLATFORM_CDC_NCM