这里会显示出您选择的修订版和当前版本之间的差别。
后一修订版 | 前一修订版 | ||
icore4trtt_5 [2020/11/05 15:15] zgf 创建 |
icore4trtt_5 [2022/04/01 11:09] (当前版本) sean |
||
---|---|---|---|
行 2: | 行 2: | ||
|技术支持电话|**0379-69926675-801**||| | |技术支持电话|**0379-69926675-801**||| | ||
|技术支持邮件|Gingko@vip.163.com||| | |技术支持邮件|Gingko@vip.163.com||| | ||
- | |技术论坛|http://www.eeschool.org||| | ||
^ 版本 ^ 日期 ^ 作者 ^ 修改内容 ^ | ^ 版本 ^ 日期 ^ 作者 ^ 修改内容 ^ | ||
| V1.0 | 2020-02-29 | zh. | 初次建立 | | | V1.0 | 2020-02-29 | zh. | 初次建立 | | ||
行 34: | 行 33: | ||
* 5.1 修改kconfig文件,在menuconfig中添加配置W25Q64的选项。 | * 5.1 修改kconfig文件,在menuconfig中添加配置W25Q64的选项。 | ||
{{ :icore4t:iCore4T_RTT_5_7.png?direct |}} | {{ :icore4t:iCore4T_RTT_5_7.png?direct |}} | ||
- | * 5.2 添加w25q64的驱动程序drv_qspi_flash.c文件,并将该文件放在../bsp/stm32/libraries/HAL_Drivers,我把源码贴在下面 | + | * 5.2 添加w25q64的驱动程序drv_qspi_flash.c文件,并将该文件放在../bsp/stm32/libraries/HAL_Drivers,我把源码贴在下面。 |
+ | <code> | ||
+ | /* | ||
+ | * Copyright (c) 2006-2018, RT-Thread Development Team | ||
+ | * | ||
+ | * SPDX-License-Identifier: Apache-2.0 | ||
+ | * | ||
+ | * Change Logs: | ||
+ | * Date Author Notes | ||
+ | * 2018-11-27 zylx first version | ||
+ | */ | ||
+ | |||
+ | #include <board.h> | ||
+ | #include <drv_qspi.h> | ||
+ | #include <rtdevice.h> | ||
+ | #include <rthw.h> | ||
+ | #include <finsh.h> | ||
+ | |||
+ | #ifdef BSP_USING_QSPI_FLASH | ||
+ | |||
+ | #include "spi_flash.h" | ||
+ | #include "spi_flash_sfud.h" | ||
+ | |||
+ | char w25qxx_read_status_register2(struct rt_qspi_device *device) | ||
+ | { | ||
+ | /* 0x35 read status register2 */ | ||
+ | char instruction = 0x35, status; | ||
+ | |||
+ | rt_qspi_send_then_recv(device, &instruction, 1, &status, 1); | ||
+ | |||
+ | return status; | ||
+ | } | ||
+ | |||
+ | void w25qxx_write_enable(struct rt_qspi_device *device) | ||
+ | { | ||
+ | /* 0x06 write enable */ | ||
+ | char instruction = 0x06; | ||
+ | |||
+ | rt_qspi_send(device, &instruction, 1); | ||
+ | } | ||
+ | |||
+ | void w25qxx_enter_qspi_mode(struct rt_qspi_device *device) | ||
+ | { | ||
+ | char status = 0; | ||
+ | /* 0x38 enter qspi mode */ | ||
+ | char instruction = 0x38; | ||
+ | char write_status2_buf[2] = {0}; | ||
+ | |||
+ | /* 0x31 write status register2 */ | ||
+ | write_status2_buf[0] = 0x31; | ||
+ | |||
+ | status = w25qxx_read_status_register2(device); | ||
+ | if (!(status & 0x02)) | ||
+ | { | ||
+ | status |= 1 << 1; | ||
+ | w25qxx_write_enable(device); | ||
+ | write_status2_buf[1] = status; | ||
+ | rt_qspi_send(device, &write_status2_buf, 2); | ||
+ | rt_qspi_send(device, &instruction, 1); | ||
+ | rt_kprintf("flash already enter qspi mode\n"); | ||
+ | rt_thread_mdelay(10); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | static int rt_hw_qspi_flash_with_sfud_init(void) | ||
+ | { | ||
+ | stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); | ||
+ | |||
+ | /* init w25q64 */ | ||
+ | if (RT_NULL == rt_sfud_flash_probe("W25Q64", "qspi10")) | ||
+ | { | ||
+ | return -RT_ERROR; | ||
+ | } | ||
+ | |||
+ | return RT_EOK; | ||
+ | } | ||
+ | INIT_COMPONENT_EXPORT(rt_hw_qspi_flash_with_sfud_init); | ||
+ | |||
+ | #if defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD) | ||
+ | #include <dfs_fs.h> | ||
+ | |||
+ | #define BLK_DEV_NAME "W25Q64" | ||
+ | |||
+ | int mnt_init(void) | ||
+ | { | ||
+ | rt_thread_delay(RT_TICK_PER_SECOND); | ||
+ | |||
+ | if (dfs_mount(BLK_DEV_NAME, "/", "elm", 0, 0) == 0) | ||
+ | { | ||
+ | rt_kprintf("file system initialization done!\n"); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(dfs_mkfs("elm", BLK_DEV_NAME) == 0) | ||
+ | { | ||
+ | if (dfs_mount(BLK_DEV_NAME, "/", "elm", 0, 0) == 0) | ||
+ | { | ||
+ | rt_kprintf("file system initialization done!\n"); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | rt_kprintf("file system initialization failed!\n"); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | INIT_ENV_EXPORT(mnt_init); | ||
+ | |||
+ | #endif /* defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD) */ | ||
+ | #endif /* BSP_USING_QSPI_FLASH */ | ||
+ | |||
+ | |||
+ | </code> | ||
* 5.3 添加文件路径,这样生成工程的时候可以自动将该文件加入MDK工程。 | * 5.3 添加文件路径,这样生成工程的时候可以自动将该文件加入MDK工程。 | ||
{{ :icore4t:iCore4T_RTT_5_8.png?direct |}} | {{ :icore4t:iCore4T_RTT_5_8.png?direct |}} | ||
行 46: | 行 159: | ||
源代码可以移步这里下载: | 源代码可以移步这里下载: | ||
+ | |||
链接:https://pan.baidu.com/s/1fcLU4WaRDlgr0mNYwZj1Yg 提取码:zstq | 链接:https://pan.baidu.com/s/1fcLU4WaRDlgr0mNYwZj1Yg 提取码:zstq |