sdcard_port.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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-14 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_spi.h"
  16. #include "spi_msd.h"
  17. #define DBG_TAG "app.card"
  18. #define DBG_LVL DBG_INFO
  19. #include <rtdbg.h>
  20. void sd_mount(void *parameter)
  21. {
  22. while (1)
  23. {
  24. rt_thread_mdelay(500);
  25. if(rt_device_find("sd0") != RT_NULL)
  26. {
  27. if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
  28. {
  29. LOG_I("sd card mount to '/'");
  30. break;
  31. }
  32. else
  33. {
  34. LOG_W("sd card mount to '/' failed!");
  35. }
  36. }
  37. }
  38. }
  39. int stm32_sdcard_mount(void)
  40. {
  41. rt_thread_t tid;
  42. tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
  43. 1024, RT_THREAD_PRIORITY_MAX - 2, 20);
  44. if (tid != RT_NULL)
  45. {
  46. rt_thread_startup(tid);
  47. }
  48. else
  49. {
  50. LOG_E("create sd_mount thread err!");
  51. }
  52. return RT_EOK;
  53. }
  54. INIT_APP_EXPORT(stm32_sdcard_mount);
  55. static int rt_hw_spi1_tfcard(void)
  56. {
  57. __HAL_RCC_GPIOC_CLK_ENABLE();
  58. rt_hw_spi_device_attach("spi1", "spi10", GPIOC, GPIO_PIN_3);
  59. return msd_init("sd0", "spi10");
  60. }
  61. INIT_DEVICE_EXPORT(rt_hw_spi1_tfcard);
  62. #endif /* BSP_USING_SDCARD */