drv_sdcard.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2006-2018, 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. */
  10. #include <rtthread.h>
  11. #ifdef BSP_USING_SDCARD
  12. #include <dfs_elm.h>
  13. #include <dfs_fs.h>
  14. #include <dfs_posix.h>
  15. #include "drv_gpio.h"
  16. #define DBG_TAG "app.card"
  17. #define DBG_LVL DBG_INFO
  18. #include <rtdbg.h>
  19. void sd_mount(void *parameter)
  20. {
  21. while (1)
  22. {
  23. rt_thread_mdelay(500);
  24. if(rt_device_find("sd0") != RT_NULL)
  25. {
  26. if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
  27. {
  28. LOG_I("sd card mount to '/'");
  29. break;
  30. }
  31. else
  32. {
  33. LOG_W("sd card mount to '/' failed!");
  34. }
  35. }
  36. }
  37. }
  38. int stm32_sdcard_mount(void)
  39. {
  40. rt_thread_t tid;
  41. tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
  42. 1024, RT_THREAD_PRIORITY_MAX - 2, 20);
  43. if (tid != RT_NULL)
  44. {
  45. rt_thread_startup(tid);
  46. }
  47. else
  48. {
  49. LOG_E("create sd_mount thread err!");
  50. }
  51. return RT_EOK;
  52. }
  53. INIT_APP_EXPORT(stm32_sdcard_mount);
  54. #endif /* BSP_USING_SDCARD */