本文主要是通过迁移的思维,记录本人初次使用NXP MCUXpresso SDK API进行BSP开发
本文主要描述了如何在RT1170平台下,制作Flash下载算法文件(FLM文件)
1. 原理
初次接触先补充相关的理论基础知知识。
reference:
https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/flashAlgorithm.html
https://www.keil.com/support/man/docs/ulinkplus/ulinkplus_su_newalgorithms.htm
总结一下对FLM文件的理解:
- 它是用来下载程序到MCU片内或片处的Flash上。
- 它是运行在片内内存区域的。
- 它需要提供flash初始化接口(时钟及引脚,flash LUT初始化),page编程及sector擦除,chip erase全擦除等必要的功能。
2. 实操
对于新手,如何找到一个学习的突破口,当然是demo工程。在官方开放的git仓库中https://github.com/NXPmicro/i.mxrt-ufl.git
// MIMXRT1170-EVK
struct FlashDevice const FlashDevice = {
FLASH_DRV_VERS, // Driver Version, do not modify!
"MIMXRT_FLEXSPI", // Device Name
EXTSPI, // Device Type
0x30000000, // Device Start Address
0x01000000, // Device Size in Bytes (16mB)
256, // Programming Page Size
0, // Reserved, must be 0
0xFF, // Initial Content of Erased Memory
100, // Program Page Timeout 100 mSec
15000, // Erase Sector Timeout 15000 mSec
// Specify Size and Address of Sectors
0x1000, 0x00000000, // Sector Size 4kB (256 Sectors)
SECTOR_END
};
打开i.mxrt-ufl\build\mdk
下的工程,在FlashDev.c中打开上述变量,将Sector Size 及 Programming Page Size 这两个字段与具体的使用的Flash相关,从手册第一页就可以找到。
- Chip Erase with Uniform Sector/Block
Erase (4/32/64 Kbyte)
- Program 1 to 256 Byte per Page
- Program/Erase Suspend & Resume
编译之后就生成FLM文件
3. 验证
本文主要是通过JFLASH来验证,将生成的FLM文件拷贝至C:\Program Files (x86)\SEGGER\JLink\Devices\NXP\iMXRT1172
目录下,如果该目前不存在,创建对应的目录。并将i.mxrt-ufl\algo\SEGGER\JLink_Vxxx\Devices\NXP\iMXRT_UFL
目录下的iMXRT117x_CortexM7.JLinkScript
文件也拷贝进去。在JLinkDevices.xml
添加在RT1172使用该FLM文件进行下载操作的支持。
<Device>
<ChipInfo Vendor="NXP" Name="NXP_FUL_RT1172" WorkRAMAddr="0x20000000" WorkRAMSize="0x00080000" Core="JLINK_CORE_CORTEX_M7" JLinkScriptFile="Devices/NXP/iMXRT1172/iMXRT117x_CortexM7.JLinkScript" />
<FlashBankInfo Name="QSPI Flash" BaseAddr="0x30000000" MaxSize="0x01000000" Loader="Devices/NXP/iMXRT1172/MIMXRT_FLEXSPI_UV5_UFL.FLM" LoaderType="FLASH_ALGO_TYPE_OPEN" />
</Device>
打开对应的JFlash,选中如下设备时行测试:
实际测试时发现速度有点慢,所以做了如下的改动之后速度提上来了,但是还是不如原生的FLM速度快。
diff --git a/src/ufl_main.c b/src/ufl_main.c
index 4629f1b..f72d56c 100644
--- a/src/ufl_main.c
+++ b/src/ufl_main.c
@@ -173,6 +173,7 @@ static void ufl_fill_flash_api(void)
uflTargetDesc->flashDriver.read = g_bootloaderTree_imxrt117x->flexspiNorDriver->read;
uflTargetDesc->flashDriver.set_clock_source = NULL;
uflTargetDesc->flashDriver.get_config = g_bootloaderTree_imxrt117x->flexspiNorDriver->get_config;
+ uflTargetDesc->flashDriver.erase_block = g_bootloaderTree_imxrt117x->flexspiNorDriver->erase_block;
// It doesn't matter that page size is overrided or not.
uflTargetDesc->iarCfg.enablePageSizeOverride = true;
break;
diff --git a/src/ufl_rom_api.c b/src/ufl_rom_api.c
index 98df4e1..5b3b12c 100644
--- a/src/ufl_rom_api.c
+++ b/src/ufl_rom_api.c
@@ -51,7 +51,8 @@ status_t flexspi_nor_get_config(uint32_t instance, flexspi_nor_config_t *config,
status_t flexspi_nor_flash_erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
{
- return g_uflTargetDesc.flashDriver.erase(instance, config, start, length);
+// return g_uflTargetDesc.flashDriver.erase(instance, config, start, length);
+ return g_uflTargetDesc.flashDriver.erase_block(instance, config, start);
}
status_t flexspi_nor_flash_read(uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes)
diff --git a/src/ufl_rom_api.h b/src/ufl_rom_api.h
index f28efef..bf214df 100644
--- a/src/ufl_rom_api.h
+++ b/src/ufl_rom_api.h
@@ -30,6 +30,7 @@ typedef struct _flexspi_nor_flash_driver
status_t (*read)(uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t addr, uint32_t lengthInBytes);
status_t (*set_clock_source)(uint32_t clockSrc);
status_t (*get_config)(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option);
+ status_t (*erase_block)(uint32_t instance, flexspi_nor_config_t *config, uint32_t start);
} flexspi_nor_flash_driver_t;
4. 总结
之前在RT1052平台上面都是直接使用代理商给的SDK,其中就自带了FLM文件,本次将其补上。 对于sector区的擦除及page的写入其实是很耗时间的,可以通过对block进行擦除,然后调大page size的大小,在page编程接口内通过循环写入的方式进行写入,这样的话,速度就能加快。
希望对各位读者帮助。
欢迎订阅
“嵌入式实操”一个分享开发实践经验的地方。
文章会同时发布到我的 CSDN主页、今日头条号 平台上。