sdcard_port.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-07-13 Dozingfiretruck first version
  9. */
  10. #include <rtthread.h>
  11. #ifdef BSP_USING_SDCARD
  12. #include <dfs_elm.h>
  13. #include <dfs_fs.h>
  14. #include <dfs_file.h>
  15. #include <unistd.h>
  16. #include <stdio.h>
  17. #include <sys/stat.h>
  18. #include <sys/statfs.h>
  19. #define DBG_TAG "app.card"
  20. #define DBG_LVL DBG_INFO
  21. #include <rtdbg.h>
  22. void sd_mount(void *parameter)
  23. {
  24. while (1)
  25. {
  26. rt_thread_mdelay(500);
  27. if(rt_device_find("sd0") != RT_NULL)
  28. {
  29. if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
  30. {
  31. LOG_I("sd card mount to '/'");
  32. break;
  33. }
  34. else
  35. {
  36. LOG_W("sd card mount to '/' failed!");
  37. }
  38. }
  39. }
  40. }
  41. int stm32_sdcard_mount(void)
  42. {
  43. rt_thread_t tid;
  44. tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
  45. 1024, RT_THREAD_PRIORITY_MAX - 2, 20);
  46. if (tid != RT_NULL)
  47. {
  48. rt_thread_startup(tid);
  49. }
  50. else
  51. {
  52. LOG_E("create sd_mount thread err!");
  53. }
  54. return RT_EOK;
  55. }
  56. INIT_APP_EXPORT(stm32_sdcard_mount);
  57. #endif /* BSP_USING_SDCARD */