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