1 /*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2018-11-27 zylx first version
9 */
10
11 #include <board.h>
12 #include <drv_qspi.h>
13 #include <rtdevice.h>
14 #include <rthw.h>
15 #include <finsh.h>
16 #include <drv_spi.h>
17
18 #ifdef BSP_USING_SPI_FLASH
19
20 #include "dev_spi_flash.h"
21 #include "dev_spi_flash_sfud.h"
22
rt_hw_spi_flash_init(void)23 static int rt_hw_spi_flash_init(void)
24 {
25
26 rt_hw_spi_device_attach("spi1", "spi10", 24); // CS:PB8
27
28 if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10"))
29 {
30 return -RT_ERROR;
31 };
32
33 return RT_EOK;
34 }
35 INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
36
37 #if defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD)
38 #include <dfs_fs.h>
39
40 #define BLK_DEV_NAME "W25Q128"
41
mnt_init(void)42 int mnt_init(void)
43 {
44 rt_thread_delay(RT_TICK_PER_SECOND);
45
46 if (dfs_mount(BLK_DEV_NAME, "/", "elm", 0, 0) == 0)
47 {
48 rt_kprintf("file system initialization done!\n");
49 }
50 else
51 {
52 if(dfs_mkfs("elm", BLK_DEV_NAME) == 0)
53 {
54 if (dfs_mount(BLK_DEV_NAME, "/", "elm", 0, 0) == 0)
55 {
56 rt_kprintf("file system initialization done!\n");
57 }
58 else
59 {
60 rt_kprintf("file system initialization failed!\n");
61 }
62 }
63 }
64
65 return 0;
66 }
67 INIT_ENV_EXPORT(mnt_init);
68
69 #endif /* defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD) */
70 #endif /* BSP_USING_SPI_FLASH */
71