sdcard_port.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * 2018-12-13 balanceTWK add sdcard port file
  9. * 2021-02-18 DavidLin Fixed the return bug
  10. */
  11. #include <rtthread.h>
  12. #ifdef BSP_USING_SDCARD
  13. #include <dfs_elm.h>
  14. #include <dfs_fs.h>
  15. #include <dfs_file.h>
  16. #include <unistd.h>
  17. #include <stdio.h>
  18. #include <sys/stat.h>
  19. #include <sys/statfs.h>
  20. #define DBG_TAG "app.card"
  21. #define DBG_LVL DBG_INFO
  22. #include <rtdbg.h>
  23. void sd_mount(void *parameter)
  24. {
  25. while (1)
  26. {
  27. rt_thread_mdelay(500);
  28. if(rt_device_find("sd0") != RT_NULL)
  29. {
  30. if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
  31. {
  32. LOG_I("sd card mount to '/'");
  33. break;
  34. }
  35. else
  36. {
  37. LOG_W("sd card mount to '/' failed!");
  38. }
  39. }
  40. }
  41. }
  42. int stm32_sdcard_mount(void)
  43. {
  44. rt_thread_t tid;
  45. tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
  46. 1024, RT_THREAD_PRIORITY_MAX - 2, 20);
  47. if (tid != RT_NULL)
  48. {
  49. rt_thread_startup(tid);
  50. }
  51. else
  52. {
  53. LOG_E("create sd_mount thread err!");
  54. return -RT_ERROR;
  55. }
  56. return RT_EOK;
  57. }
  58. INIT_APP_EXPORT(stm32_sdcard_mount);
  59. #endif /* BSP_USING_SDCARD */