mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-06-24 08:35:35 +08:00
[bsp][nxp] support qspi flash and filesystem for imxrt1180-evk board
This commit is contained in:
@@ -27,7 +27,7 @@ CM33对CM7的kick off将在后续版本中支持。
|
||||
| **板载外设** | **支持情况** | **备注** |
|
||||
| :----------------- | :----------: | :------------------------------------|
|
||||
| USB 转串口 | 暂不支持 | |
|
||||
| SPI Flash | 暂不支持 | |
|
||||
| SPI Flash | 支持 | |
|
||||
| 以太网 | 暂不支持 | |
|
||||
| **片上外设** | **支持情况** | **备注** |
|
||||
| GPIO | 暂不支持 | |
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
scons.args: &scons
|
||||
scons_arg:
|
||||
- '--strict'
|
||||
|
||||
# ------ component CI ------
|
||||
|
||||
# ------ Peripheral CI ------
|
||||
Peripheral.flash_fs:
|
||||
<<: *scons
|
||||
kconfig:
|
||||
- CONFIG_BSP_USING_QSPI_FLASH_FS=y
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2026-06-02 CoreBoxer add LittleFS on QSPI NOR Flash (IMXRT1180-EVK)
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/* ====================================================================
|
||||
* QSPI NOR Flash LittleFS (controlled by BSP_USING_QSPI_FLASH_FS)
|
||||
*
|
||||
* Dependencies:
|
||||
* - drv_flash.c (Flash read/write/erase driver via ROM API)
|
||||
* - FAL framework (partition management)
|
||||
* - LittleFS component (RT-Thread package)
|
||||
*
|
||||
* FAL partition configuration (fal_cfg.h):
|
||||
* "filesystem" partition → filesystem area of norflash0
|
||||
*
|
||||
* Mount procedure:
|
||||
* 1. Find FAL partition to confirm correct configuration
|
||||
* 2. Create MTD NOR block device
|
||||
* 3. Try direct mount (for already formatted filesystem)
|
||||
* 4. If failed, perform mkfs then remount (first use or format scenario)
|
||||
* ==================================================================== */
|
||||
#ifdef BSP_USING_QSPI_FLASH_FS
|
||||
#include <dfs_fs.h>
|
||||
#include <fal.h>
|
||||
|
||||
#define FS_PARTITION_NAME "filesystem"
|
||||
#define FS_TYPE_NAME "lfs"
|
||||
#define FS_MOUNT_POINT "/"
|
||||
|
||||
static int _qspi_flash_fs_mount(void)
|
||||
{
|
||||
struct fal_mtd_nor_device *mtd_dev;
|
||||
int ret;
|
||||
|
||||
/* Find FAL partition to confirm configuration is correct */
|
||||
if (fal_partition_find(FS_PARTITION_NAME) == RT_NULL)
|
||||
{
|
||||
rt_kprintf("[qspi_fs] partition '%s' not found, check fal_cfg.h\n",
|
||||
FS_PARTITION_NAME);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* Create MTD NOR block device for filesystem partition */
|
||||
mtd_dev = (struct fal_mtd_nor_device *)fal_mtd_nor_device_create(FS_PARTITION_NAME);
|
||||
if (mtd_dev == RT_NULL)
|
||||
{
|
||||
rt_kprintf("[qspi_fs] failed to create MTD NOR device for '%s'\n",
|
||||
FS_PARTITION_NAME);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* Try direct mount (for already formatted flash) */
|
||||
ret = dfs_mount(FS_PARTITION_NAME, FS_MOUNT_POINT, FS_TYPE_NAME, 0, 0);
|
||||
if (ret == 0)
|
||||
{
|
||||
rt_kprintf("[qspi_fs] '%s' mounted at '%s'\n",
|
||||
FS_PARTITION_NAME, FS_MOUNT_POINT);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/* Mount failed, indicating flash is not formatted (first use scenario), perform mkfs */
|
||||
rt_kprintf("[qspi_fs] mount failed (ret=%d), formatting '%s'...\n",
|
||||
ret, FS_PARTITION_NAME);
|
||||
|
||||
ret = dfs_mkfs(FS_TYPE_NAME, FS_PARTITION_NAME);
|
||||
if (ret != 0)
|
||||
{
|
||||
rt_kprintf("[qspi_fs] mkfs failed (ret=%d)\n", ret);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* Remount after successful mkfs */
|
||||
ret = dfs_mount(FS_PARTITION_NAME, FS_MOUNT_POINT, FS_TYPE_NAME, 0, 0);
|
||||
if (ret != 0)
|
||||
{
|
||||
rt_kprintf("[qspi_fs] mount failed after mkfs (ret=%d)\n", ret);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
rt_kprintf("[qspi_fs] '%s' formatted and mounted at '%s'\n",
|
||||
FS_PARTITION_NAME, FS_MOUNT_POINT);
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_APP_EXPORT(_qspi_flash_fs_mount);
|
||||
/*
|
||||
* FAL initialization registered as INIT_COMPONENT_EXPORT:
|
||||
* after Flash driver (INIT_DEVICE_EXPORT)
|
||||
* before filesystem mount (INIT_APP_EXPORT)
|
||||
*/
|
||||
INIT_COMPONENT_EXPORT(fal_init);
|
||||
|
||||
#endif /* BSP_USING_QSPI_FLASH_FS */
|
||||
@@ -229,6 +229,16 @@ menu "Onboard Peripheral Drivers"
|
||||
select BSP_USING_SDIO
|
||||
select RT_USING_DFS_ELMFAT
|
||||
default n
|
||||
|
||||
config BSP_USING_QSPI_FLASH_FS
|
||||
bool "Enable QSPI Flash (LittleFS)"
|
||||
select BSP_USING_FLEXSPI
|
||||
select BSP_USING_FLEXSPI1
|
||||
select RT_USING_FAL
|
||||
select FAL_PART_HAS_TABLE_CFG
|
||||
select RT_USING_MTD_NOR
|
||||
select PKG_USING_LITTLEFS
|
||||
default n
|
||||
endif
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -12,6 +12,9 @@ MCUX_Config/clock_config.c
|
||||
MCUX_Config/pin_mux.c
|
||||
""")
|
||||
|
||||
if GetDepend(['BSP_USING_QSPI_FLASH_FS']):
|
||||
src += ['ports/drv_flexspi_nor_flash.c', 'ports/fal_flash_port.c']
|
||||
|
||||
CPPPATH = [cwd,cwd + '/MCUX_Config',cwd + '/ports']
|
||||
CPPDEFINES = ['CPU_MIMXRT1189CVM8C_cm33', 'MCUXPRESSO_SDK', 'MCUX_META_BUILD', 'MIMXRT1189_cm33_SERIES', 'XIP_BOOT_HEADER_ENABLE=1', 'XIP_BOOT_HEADER_DCD_ENABLE=1', 'XIP_EXTERNAL_FLASH=1', 'ARM_MATH_CM33']
|
||||
|
||||
|
||||
@@ -173,6 +173,7 @@ LR_m_text m_text_start m_text_size
|
||||
|
||||
ER_m_QuickAccessCode m_qacode_start m_qacode_size
|
||||
{
|
||||
fsl_flexspi.o (+RO-CODE)
|
||||
.ANY (CodeQuickAccess)
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2026, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-06-03 CoreBoxer support IMXRT1180-EVK
|
||||
*/
|
||||
|
||||
#ifndef __DRV_FLEXSPI_NOR_FLASH_H__
|
||||
#define __DRV_FLEXSPI_NOR_FLASH_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/* ============================================================
|
||||
* Flash Physical Parameters
|
||||
* Source: SDK example app.h
|
||||
* FLASH_SIZE = 0x4000 (Unit: KB) = 16MB
|
||||
* FlexSPI1_AMBA_BASE = 0x28000000
|
||||
* ============================================================ */
|
||||
#define QSPI_FLASH_BASE FlexSPI1_AMBA_BASE /* 0x28000000 */
|
||||
#define QSPI_FLASH_SIZE (0x4000U * 1024U) /* 16MB (0x4000 KB) */
|
||||
#define QSPI_SECTOR_SIZE 0x00001000U /* 4KB */
|
||||
#define QSPI_PAGE_SIZE 256U /* 256B */
|
||||
|
||||
/*
|
||||
* Partition Plan (Total 16MB):
|
||||
* 0x00000000 ~ 0x007FFFFF: Application Code Area (8MB, limited by Scatter)
|
||||
* 0x00800000 ~ 0x00FFFFFF: File System Area (8MB, LittleFS)
|
||||
*/
|
||||
#define QSPI_FS_OFFSET 0x00800000U
|
||||
#define QSPI_FS_SIZE 0x00800000U
|
||||
|
||||
/* ============================================================
|
||||
* RAM Code Section Attributes
|
||||
* Write/Erase functions placed in CodeQuickAccess (ITCM),
|
||||
* CPU can safely fetch instructions during FlexSPI IP command execution.
|
||||
* ============================================================ */
|
||||
#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
|
||||
#define QSPI_RAM_CODE __attribute__((section("CodeQuickAccess"), noinline))
|
||||
#elif defined(__GNUC__)
|
||||
#define QSPI_RAM_CODE __attribute__((section(".itcm.text"), noinline))
|
||||
#elif defined(__ICCARM__)
|
||||
#define QSPI_RAM_CODE __ramfunc
|
||||
#else
|
||||
#define QSPI_RAM_CODE
|
||||
#endif
|
||||
|
||||
/* ============================================================
|
||||
* External APIs
|
||||
* ============================================================ */
|
||||
int rt_qspi_flash_init(void);
|
||||
int rt_qspi_flash_read(uint32_t offset, uint8_t *buf, size_t size);
|
||||
int rt_qspi_flash_write(uint32_t offset, const uint8_t *buf, size_t size);
|
||||
int rt_qspi_flash_erase(uint32_t offset, size_t size);
|
||||
void *rt_qspi_flash_mmap(uint32_t offset, size_t size);
|
||||
|
||||
#endif /* __DRV_FLEXSPI_NOR_FLASH_H__ */
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-01-01 RT-Thread first version
|
||||
*/
|
||||
|
||||
#ifndef __FAL_CFG_H__
|
||||
#define __FAL_CFG_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <board.h>
|
||||
|
||||
extern const struct fal_flash_dev imxrt1180_nor_flash;
|
||||
|
||||
/* flash device table */
|
||||
#define FAL_FLASH_DEV_TABLE \
|
||||
{ \
|
||||
&imxrt1180_nor_flash, \
|
||||
}
|
||||
|
||||
/* ====================== Partition Configuration ========================== */
|
||||
#ifdef FAL_PART_HAS_TABLE_CFG
|
||||
|
||||
/* partition table */
|
||||
#define FAL_PART_TABLE \
|
||||
{ \
|
||||
{FAL_PART_MAGIC_WROD, "app", "norflash0", 0, 8*1024*1024, 0}, \
|
||||
{FAL_PART_MAGIC_WROD, "filesystem", "norflash0", 8*1024*1024, 8*1024*1024, 0}, \
|
||||
}
|
||||
|
||||
#endif /* FAL_PART_HAS_TABLE_CFG */
|
||||
|
||||
#endif /* __FAL_CFG_H__ */
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2026, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2026-06-03 CoreBoxer support IMXRT1180-EVK
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include <fal.h>
|
||||
|
||||
#include "drv_flexspi_nor_flash.h"
|
||||
|
||||
/*
|
||||
* Logging configuration
|
||||
*/
|
||||
#define LOG_TAG "fal.flash"
|
||||
#define LOG_LVL LOG_LVL_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
/* FAL ops bridge */
|
||||
#ifdef RT_USING_FAL
|
||||
|
||||
static int _fal_init(void)
|
||||
{
|
||||
return rt_qspi_flash_init();
|
||||
}
|
||||
|
||||
static int _fal_read(long offset, rt_uint8_t *buf, size_t size)
|
||||
{
|
||||
return rt_qspi_flash_read((rt_uint32_t)offset, buf, size);
|
||||
}
|
||||
|
||||
QSPI_RAM_CODE static int _fal_write(long offset, const rt_uint8_t *buf, size_t size)
|
||||
{
|
||||
return rt_qspi_flash_write((rt_uint32_t)offset, buf, size);
|
||||
}
|
||||
|
||||
QSPI_RAM_CODE static int _fal_erase(long offset, size_t size)
|
||||
{
|
||||
return rt_qspi_flash_erase((rt_uint32_t)offset, size);
|
||||
}
|
||||
|
||||
const struct fal_flash_dev imxrt1180_nor_flash =
|
||||
{
|
||||
.name = "norflash0",
|
||||
.addr = QSPI_FLASH_BASE,
|
||||
.len = QSPI_FLASH_SIZE,
|
||||
.blk_size = QSPI_SECTOR_SIZE,
|
||||
.ops = { _fal_init, _fal_read, _fal_write, _fal_erase },
|
||||
.write_gran = QSPI_PAGE_SIZE,
|
||||
};
|
||||
|
||||
#endif /* RT_USING_FAL */
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-15 xjy198903 The first version for rt1170
|
||||
* 2026-06-03 CoreBoxer support IMXRT1180-EVK
|
||||
*/
|
||||
|
||||
#ifndef FLEXSPI_PORT_H__
|
||||
#define FLEXSPI_PORT_H__
|
||||
|
||||
/* parameters for flexpsi peripheral */
|
||||
#define FLEXSPI1_CONTROL_BASE FLEXSPI1
|
||||
#define FLEXSPI2_CONTROL_BASE FLEXSPI2
|
||||
#define FLEXSPI_ROOT_CLK (12000000U) /* serial root clk: 12MHz*/
|
||||
#define FLASH_SIZE (16 * 1024) /* device size 16*1024(KB) = 16MB */
|
||||
#define ARD_SEQ_NUMBER 1 /* Sequence number for AHB read command */
|
||||
#define ARD_SEQ_INDEX 0 /* Sequence ID for AHB read command */
|
||||
#define AWR_SEQ_NUMBER 0 /* Sequence number for AHB write command */
|
||||
#define AWR_SEQ_INDEX 0 /* Sequence ID for AHB write command */
|
||||
#define ARD_SEQ_CMD 0xBB /* cmd for read */
|
||||
#define AWR_SEQ_CMD 0xAA /* cmd for write */
|
||||
#define FLEXSPI_RX_SAMPLE_CLOCK kFLEXSPI_ReadSampleClkLoopbackFromDqsPad
|
||||
#define FLASH_PORT kFLEXSPI_PortA1
|
||||
#define CLOCK_SRC kCLOCK_FLEXSPI1_ClockRoot_MuxOscRc24M
|
||||
#define CLOCK_DIV 2U
|
||||
#define CUSTOM_LUT_LENGTH 60U
|
||||
#define FLEXSPI1_AHB_DATA_ADDRESS (0x28000000U)
|
||||
#define FLEXSPI2_AHB_DATA_ADDRESS (0x60000000U)
|
||||
|
||||
#define COMBINATION_MODE 0U
|
||||
#define FREE_RUNNING_MODE 0U
|
||||
|
||||
#define EXAMPLE_FLEXSPI_AMBA_BASE FlexSPI1_AMBA_BASE
|
||||
#define FLASH_PAGE_SIZE 256
|
||||
#define SECTOR_SIZE 0x1000 /* 4K */
|
||||
#define EXAMPLE_FLEXSPI_CLOCK kCLOCK_Flexspi1
|
||||
#define FLASH_PORT kFLEXSPI_PortA1
|
||||
|
||||
#define NOR_CMD_LUT_SEQ_IDX_READ_NORMAL 7
|
||||
#define NOR_CMD_LUT_SEQ_IDX_READ_FAST 13
|
||||
#define NOR_CMD_LUT_SEQ_IDX_READ_FAST_QUAD 0
|
||||
#define NOR_CMD_LUT_SEQ_IDX_READSTATUS 1
|
||||
#define NOR_CMD_LUT_SEQ_IDX_WRITEENABLE 2
|
||||
#define NOR_CMD_LUT_SEQ_IDX_ERASESECTOR 3
|
||||
#define NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_SINGLE 6
|
||||
#define NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_QUAD 4
|
||||
#define NOR_CMD_LUT_SEQ_IDX_READID 8
|
||||
#define NOR_CMD_LUT_SEQ_IDX_WRITESTATUSREG 9
|
||||
#define NOR_CMD_LUT_SEQ_IDX_ENTERQPI 10
|
||||
#define NOR_CMD_LUT_SEQ_IDX_EXITQPI 11
|
||||
#define NOR_CMD_LUT_SEQ_IDX_READSTATUSREG 12
|
||||
#define NOR_CMD_LUT_SEQ_IDX_ERASECHIP 5
|
||||
|
||||
#define FLASH_QUAD_ENABLE 0x40
|
||||
#define FLASH_BUSY_STATUS_POL 1
|
||||
#define FLASH_BUSY_STATUS_OFFSET 0
|
||||
|
||||
#endif /* FLEXSPI_PORT_H__ */
|
||||
@@ -6,10 +6,12 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-09-14 xjy198903 the first version for 1170
|
||||
* 2026-06-03 CoreBoxer support IMXRT1180-EVK
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#ifdef BSP_USING_FLEXSPI
|
||||
#if defined(BSP_USING_FLEXSPI) && \
|
||||
(defined(SOC_IMXRT1170_SERIES) || defined(SOC_IMXRT1180_SERIES))
|
||||
#include "board.h"
|
||||
#include <rtdevice.h>
|
||||
|
||||
@@ -17,16 +19,23 @@
|
||||
#include <finsh.h>
|
||||
#endif
|
||||
|
||||
#include "drv_flexspi.h"
|
||||
#include "flexspi_port.h"
|
||||
#include "fsl_flexspi.h"
|
||||
|
||||
#ifndef COMBINATION_MODE
|
||||
#define COMBINATION_MODE 1U
|
||||
#endif
|
||||
|
||||
#ifndef FREE_RUNNING_MODE
|
||||
#define FREE_RUNNING_MODE 1U
|
||||
#endif
|
||||
|
||||
#define FLEXSPI_DEBUG
|
||||
#define LOG_TAG "drv.flexspi"
|
||||
#include <drv_log.h>
|
||||
|
||||
#if defined(SOC_IMXRT1170_SERIES)
|
||||
static flexspi_device_config_t deviceconfig = {
|
||||
.flexspiRootClk = 12000000,
|
||||
.flashSize = FLASH_SIZE,
|
||||
@@ -50,6 +59,114 @@ const uint32_t customLUT[CUSTOM_LUT_LENGTH] = {
|
||||
[4 * ARD_SEQ_INDEX] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_READ_DDR, kFLEXSPI_8PAD, 0x04, kFLEXSPI_Command_STOP, kFLEXSPI_8PAD, 0),
|
||||
};
|
||||
#elif defined(SOC_IMXRT1180_SERIES)
|
||||
static flexspi_device_config_t deviceconfig = {
|
||||
.flexspiRootClk = 12000000,
|
||||
.flashSize = FLASH_SIZE,
|
||||
.CSIntervalUnit = kFLEXSPI_CsIntervalUnit1SckCycle,
|
||||
.CSInterval = 2,
|
||||
.CSHoldTime = 3,
|
||||
.CSSetupTime = 3,
|
||||
.dataValidTime = 0,
|
||||
.columnspace = 0,
|
||||
.enableWordAddress = 0,
|
||||
.AWRSeqIndex = AWR_SEQ_INDEX,
|
||||
.AWRSeqNumber = AWR_SEQ_NUMBER,
|
||||
.ARDSeqIndex = ARD_SEQ_INDEX,
|
||||
.ARDSeqNumber = ARD_SEQ_NUMBER,
|
||||
.AHBWriteWaitUnit = kFLEXSPI_AhbWriteWaitUnit2AhbCycle,
|
||||
.AHBWriteWaitInterval = 0,
|
||||
};
|
||||
|
||||
const uint32_t customLUT[CUSTOM_LUT_LENGTH] = {
|
||||
/* Normal read mode - SDR */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_READ_NORMAL] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x03,
|
||||
kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_READ_NORMAL + 1] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04,
|
||||
kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),
|
||||
|
||||
/* Fast read mode - SDR */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_READ_FAST] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x0B,
|
||||
kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_READ_FAST + 1] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_DUMMY_SDR, kFLEXSPI_1PAD, 0x08,
|
||||
kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04),
|
||||
|
||||
/* Fast read quad mode - SDR */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_READ_FAST_QUAD] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0xEB,
|
||||
kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_4PAD, 0x18),
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_READ_FAST_QUAD + 1] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_DUMMY_SDR, kFLEXSPI_4PAD, 0x06,
|
||||
kFLEXSPI_Command_READ_SDR, kFLEXSPI_4PAD, 0x04),
|
||||
|
||||
/* Write Enable */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x06,
|
||||
kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),
|
||||
|
||||
/* Erase Sector */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x20,
|
||||
kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
|
||||
|
||||
/* Page Program - single mode */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_SINGLE] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x02,
|
||||
kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_SINGLE + 1] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_WRITE_SDR, kFLEXSPI_1PAD, 0x04,
|
||||
kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),
|
||||
|
||||
/* Page Program - quad mode */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_QUAD] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x32,
|
||||
kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_QUAD + 1] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_WRITE_SDR, kFLEXSPI_4PAD, 0x04,
|
||||
kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),
|
||||
|
||||
/* Read ID */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_READID] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x9F,
|
||||
kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04),
|
||||
|
||||
/* Write Status Register */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_WRITESTATUSREG] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x01,
|
||||
kFLEXSPI_Command_WRITE_SDR, kFLEXSPI_1PAD, 0x04),
|
||||
|
||||
/* Read status register */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_READSTATUSREG] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x05,
|
||||
kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04),
|
||||
|
||||
/* Erase whole chip */
|
||||
[4 * NOR_CMD_LUT_SEQ_IDX_ERASECHIP] =
|
||||
FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0xC7,
|
||||
kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),
|
||||
};
|
||||
#else
|
||||
#error "Unsupported SOC for drv_flexspi"
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* Internal handle
|
||||
* -------------------------------------------------------------------------- */
|
||||
static imxrt_flexspi_handle_t s_flexspi_handle =
|
||||
{
|
||||
.base = FLEXSPI1_CONTROL_BASE,
|
||||
.port = FLASH_PORT,
|
||||
.ahb_base = FLEXSPI1_AHB_DATA_ADDRESS
|
||||
};
|
||||
|
||||
imxrt_flexspi_handle_t *imxrt_flexspi_get_handle(void)
|
||||
{
|
||||
return &s_flexspi_handle;
|
||||
}
|
||||
|
||||
static void flexspi_clock_init(clock_root_t root, uint8_t src, uint8_t div)
|
||||
{
|
||||
@@ -58,19 +175,26 @@ static void flexspi_clock_init(clock_root_t root, uint8_t src, uint8_t div)
|
||||
CLOCK_SetRootClockMux(root, src);
|
||||
}
|
||||
|
||||
static int rt_hw_imxrt_flexspi_init(void)
|
||||
FLEXSPI_RAM_CODE static int rt_hw_imxrt_flexspi_init(void)
|
||||
{
|
||||
flexspi_config_t config;
|
||||
FLEXSPI_Type *base;
|
||||
|
||||
#ifdef BSP_USING_FLEXSPI1
|
||||
base = FLEXSPI1_CONTROL_BASE;
|
||||
#else
|
||||
base = FLEXSPI2_CONTROL_BASE;
|
||||
#endif
|
||||
|
||||
s_flexspi_handle.base = FLEXSPI1_CONTROL_BASE;
|
||||
s_flexspi_handle.port = FLASH_PORT;
|
||||
s_flexspi_handle.ahb_base = FLEXSPI1_AHB_DATA_ADDRESS;
|
||||
//Set root clk 80MHz
|
||||
flexspi_clock_init(kCLOCK_Root_Flexspi1, CLOCK_SRC, CLOCK_DIV);
|
||||
#else
|
||||
base = FLEXSPI2_CONTROL_BASE;
|
||||
s_flexspi_handle.base = FLEXSPI2_CONTROL_BASE;
|
||||
s_flexspi_handle.port = FLASH_PORT;
|
||||
s_flexspi_handle.ahb_base = FLEXSPI2_AHB_DATA_ADDRESS;
|
||||
flexspi_clock_init(kCLOCK_Root_Flexspi2, CLOCK_SRC, CLOCK_DIV);
|
||||
#endif
|
||||
|
||||
|
||||
/*Get FLEXSPI default settings and configure the flexspi. */
|
||||
FLEXSPI_GetDefaultConfig(&config);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2026, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2026-06-03 CoreBoxer support IMXRT1180-EVK
|
||||
*/
|
||||
|
||||
#ifndef __DRV_FLEXSPI_H__
|
||||
#define __DRV_FLEXSPI_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "fsl_flexspi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Put critical transfer code into ITCM (Code TCM) */
|
||||
#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
|
||||
#define FLEXSPI_RAM_CODE __attribute__((section("CodeQuickAccess"), noinline))
|
||||
#elif defined(__GNUC__)
|
||||
#define FLEXSPI_RAM_CODE __attribute__((section("CodeQuickAccess"), noinline))
|
||||
#elif defined(__ICCARM__)
|
||||
#define FLEXSPI_RAM_CODE __ramfunc
|
||||
#else
|
||||
#define FLEXSPI_RAM_CODE
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FLEXSPI_Type *base;
|
||||
flexspi_port_t port;
|
||||
uint32_t ahb_base;
|
||||
} imxrt_flexspi_handle_t;
|
||||
|
||||
/* Get initialized FlexSPI handle (FlexSPI1 or FlexSPI2 decided by BSP config) */
|
||||
imxrt_flexspi_handle_t *imxrt_flexspi_get_handle(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DRV_FLEXSPI_H__ */
|
||||
Reference in New Issue
Block a user