2023-04-27 08:54:45 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
* 2023-04-14 murmur the first version
|
|
|
|
|
*/
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
|
|
//#define LOG_TAG "flash"
|
|
|
|
|
//#define LOG_LVL LOG_LVL_DBG
|
|
|
|
|
//#include <ulog.h>
|
|
|
|
|
|
2023-05-23 06:59:35 +00:00
|
|
|
|
#define DBG_TAG "w25q"
|
2023-04-27 08:54:45 +00:00
|
|
|
|
#define DBG_LVL DBG_LOG
|
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
|
#include <rtdevice.h>
|
2023-06-01 02:23:08 +00:00
|
|
|
|
#include "cfg.h"
|
2023-04-27 08:54:45 +00:00
|
|
|
|
|
|
|
|
|
int rt_hw_spi_flash_init(void)
|
|
|
|
|
{
|
2023-06-18 01:34:09 +00:00
|
|
|
|
// rt_kprintf("SW Version: %s\n","1.4(temp)");
|
2023-04-27 08:54:45 +00:00
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
2023-05-23 06:59:35 +00:00
|
|
|
|
// __HAL_RCC_GPIOD_CLK_ENABLE();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
// rt_kprintf("sfud success.\n");
|
|
|
|
|
// rt_tick_t t= rt_tick_get_millisecond();
|
2023-05-23 06:59:35 +00:00
|
|
|
|
rt_hw_spi_device_attach("spi2", "spi10", GPIOB, GPIO_PIN_12);
|
2023-06-01 02:23:08 +00:00
|
|
|
|
// rt_kprintf("sfud success.\n");
|
2023-04-27 08:54:45 +00:00
|
|
|
|
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10"))
|
|
|
|
|
{
|
|
|
|
|
rt_kprintf("sfud error.\n");
|
|
|
|
|
return -RT_ERROR;
|
|
|
|
|
};
|
2023-06-17 10:26:40 +00:00
|
|
|
|
// rt_kprintf("sfud success.\n");
|
2023-04-27 08:54:45 +00:00
|
|
|
|
return RT_EOK;
|
|
|
|
|
}
|
|
|
|
|
/* 导出到自动初始化 */
|
|
|
|
|
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void w25q128_mount(void)
|
|
|
|
|
{
|
|
|
|
|
// dfs_mkfs("elm", "W25Q128");
|
|
|
|
|
rt_device_t dev;
|
|
|
|
|
dev = rt_device_find("W25Q128");
|
|
|
|
|
if(dev != RT_NULL) {
|
|
|
|
|
if(dfs_mount("W25Q128", "/", "elm", 0, 0) == 0){
|
2023-06-17 10:26:40 +00:00
|
|
|
|
// rt_kprintf("spi_flash mount to spi!\n");
|
2023-04-27 08:54:45 +00:00
|
|
|
|
} else {
|
|
|
|
|
rt_kprintf("spi_flash mount to spi failed!\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 导出到自动初始化 */
|
|
|
|
|
INIT_COMPONENT_EXPORT(w25q128_mount);
|
|
|
|
|
|
|
|
|
|
|
2023-06-19 07:56:45 +00:00
|
|
|
|
void sdmnt_init(void)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_mdelay(100);//这段延时必须加上,系统上电过程中存在延时,否则会出现先挂载后注册块设备sd0的情况
|
|
|
|
|
// mkfs("elm","sd0");//挂在前需格式化
|
|
|
|
|
if(dfs_mount("sd0","/sd","elm",0,0)==0) //挂载文件系统,参数:块设备名称、挂载目录、文件系统类型、读写标志、私有数据0
|
|
|
|
|
{
|
|
|
|
|
// rt_kprintf("dfs mount success\r\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rt_kprintf("dfs mount failed\r\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* 导出到自动初始化 */
|
|
|
|
|
INIT_COMPONENT_EXPORT(sdmnt_init);
|
|
|
|
|
|
|
|
|
|
void bootinfo()
|
|
|
|
|
{
|
|
|
|
|
rt_kprintf("%d ms since boot.\n", rt_tick_get_millisecond());
|
|
|
|
|
add_val("bootCnt");
|
|
|
|
|
}
|
|
|
|
|
/* 导出到自动初始化 */
|
|
|
|
|
INIT_COMPONENT_EXPORT(bootinfo);
|