usbh_msc.rst 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. usbh_msc
  2. ===============
  3. 本节主要介绍主机 MSC 使用。借助 FATFS 实现读写功能。
  4. - 在 msc 枚举完成的回调中注册一个线程,用于读写操作。
  5. .. code-block:: C
  6. void usbh_msc_run(struct usbh_msc *msc_class)
  7. {
  8. usb_osal_thread_create("usbh_msc", 2048, CONFIG_USBHOST_PSC_PRIO + 1, usbh_msc_thread, msc_class);
  9. }
  10. void usbh_msc_stop(struct usbh_msc *msc_class)
  11. {
  12. }
  13. - 不使用 fatfs,则直接使用 usbh_msc_scsi_read10 或者 usbh_msc_scsi_write10 函数进行读写操作。
  14. - 如果使用 fatfs,则需要在 usbh_msc_thread 中调用 fatfs 的接口进行读写操作。msc读写适配fatfs 参考 `platform/none/usbh_fatfs.c`
  15. .. code-block:: C
  16. static void usbh_msc_thread(void *argument)
  17. {
  18. int ret;
  19. struct usbh_msc *msc_class = (struct usbh_msc *)argument;
  20. /* test with only one buffer, if you have more msc class, modify by yourself */
  21. #if 1
  22. /* get the partition table */
  23. ret = usbh_msc_scsi_read10(msc_class, 0, partition_table, 1);
  24. if (ret < 0) {
  25. USB_LOG_RAW("scsi_read10 error,ret:%d\r\n", ret);
  26. goto delete;
  27. }
  28. for (uint32_t i = 0; i < 512; i++) {
  29. if (i % 16 == 0) {
  30. USB_LOG_RAW("\r\n");
  31. }
  32. USB_LOG_RAW("%02x ", partition_table[i]);
  33. }
  34. USB_LOG_RAW("\r\n");
  35. #endif
  36. #if TEST_USBH_MSC_FATFS
  37. usb_msc_fatfs_test();
  38. #endif
  39. // clang-format off
  40. delete:
  41. usb_osal_thread_delete(NULL);
  42. // clang-format on
  43. }
  44. - 最后处理完成或者失败后,删除线程。