使用keil 生成 Flash Loader image
1.1参考文档及路径
- DUI0459F_02_mdk_fromelf_user_guide.pdf;
2.Cortex-M3 技术参考手册.pdf;
1.2 Flash Loader简介
平时我们使用的仿真器(ST-LINK,J-LINK)并不是直接将数据烧写到芯片的flash存储器中。而是通过一段专门的程序Flash Loader。它实际上是一段主要用来擦除,写入Flash的小程序。从原理上来说就是仿真器先下载Flash Loader到RAM中,然后操作内核寄存器调用Flash Loader函数集。当函数返回,会产生一个中断,仿真器就会知道函数已经完成,进而继续调用Flash Loader。
简单的说,仿真器从Flash Loader调用函数来实现对芯片的烧写,擦除操作。将程序下载到flash,有两种方式:
- 直接操作Flash存储器
通过调试接口(DAP)操作芯片相关的FLASH寄存器,具体怎么做需要查阅芯片的相关说明文档。
2. 间接操作Flash存储器
A)下载Flash Loader到RAM中;
B)将应用程序的映像下载到RAM缓冲区中;
C)Flash Loader通过仿真器启动,将RAM Buffer里读出的数据编程到Flash中;
D)现在,应用程序的映像文件就在Flash存储器中了。
1.3 Flash Loader编写
根据keil提供的模板C:\Keil_v5\ARM\Flash\_Template,至少需要以下3个文件:
A) FlashDev.c,Device Decription,是一个结构体变量,里面定义的是Flash相关信息
1 /***********************************************************************/ 2 /* This file is part of the ARM Toolchain package */ 3 /* Copyright (c) 2010 Keil - An ARM Company. All rights reserved. */ 4 /***********************************************************************/ 5 /* */ 6 /* FlashDev.C: Device Description for New Device Flash */ 7 /* */ 8 /***********************************************************************/ 9 10 #include "..\FlashOS.H" // FlashOS Structures 11 12 13 struct FlashDevice const FlashDevice = { 14 FLASH_DRV_VERS, // Driver Version, do not modify! 15 "New Device 256kB Flash", // Device Name 16 ONCHIP, // Device Type 17 0x00000000, // Device Start Address 18 0x00040000, // Device Size in Bytes (256kB) 19 1024, // Programming Page Size 20 0, // Reserved, must be 0 21 0xFF, // Initial Content of Erased Memory 22 100, // Program Page Timeout 100 mSec 23 3000, // Erase Sector Timeout 3000 mSec 24 25 // Specify Size and Address of Sectors 26 0x002000, 0x000000, // Sector Size 8kB (8 Sectors) 27 0x010000, 0x010000, // Sector Size 64kB (2 Sectors) 28 0x002000, 0x030000, // Sector Size 8kB (8 Sectors) 29 SECTOR_END 30 };
B)FlashPrg.c,Program Functions实现Flash的初始化,擦除,写等函数
1 /***********************************************************************/ 2 /* This file is part of the ARM Toolchain package */ 3 /* Copyright (c) 2010 Keil - An ARM Company. All rights reserved. */ 4 /***********************************************************************/ 5 /* */ 6 /* FlashDev.C: Flash Programming Functions adapted */ 7 /* for New Device 256kB Flash */ 8 /* */ 9 /***********************************************************************/ 10 11 #include "..\FlashOS.H" // FlashOS Structures 12 /* 13 * Initialize Flash Programming Functions 14 * Parameter: adr: Device Base Address 15 * clk: Clock Frequency (Hz) 16 * fnc: Function Code (1 - Erase, 2 - Program, 3 - Verify) 17 * Return Value: 0 - OK, 1 - Failed 18 */ 19 20 int Init (unsigned long adr, unsigned long clk, unsigned long fnc) { 21 22 /* Add your Code */ 23 return (0); // Finished without Errors 24 } 25 26 27 /* 28 * De-Initialize Flash Programming Functions 29 * Parameter: fnc: Function Code (1 - Erase, 2 - Program, 3 - Verify) 30 * Return Value: 0 - OK, 1 - Failed 31 */ 32 33 int UnInit (unsigned long fnc) { 34 35 /* Add your Code */ 36 return (0); // Finished without Errors 37 } 38 39 40 /* 41 * Erase complete Flash Memory 42 * Return Value: 0 - OK, 1 - Failed 43 */ 44 45 int EraseChip (void) { 46 47 /* Add your Code */ 48 return (0); // Finished without Errors 49 } 50 51 52 /* 53 * Erase Sector in Flash Memory 54 * Parameter: adr: Sector Address 55 * Return Value: 0 - OK, 1 - Failed 56 */ 57 58 int EraseSector (unsigned long adr) { 59 60 /* Add your Code */ 61 return (0); // Finished without Errors 62 } 63 64 65 /* 66 * Program Page in Flash Memory 67 * Parameter: adr: Page Start Address 68 * sz: Page Size 69 * buf: Page Data 70 * Return Value: 0 - OK, 1 - Failed 71 */ 72 73 int ProgramPage (unsigned long adr, unsigned long sz, unsigned char *buf) { 74 75 /* Add your Code */ 76 return (0); // Finished without Errors 77 }
C)FlashOS.h, 结构体定义
1 /* ----------------------------------------------------------------------------- 2 * Copyright (c) 2014 ARM Ltd. 3 * 4 * This software is provided 'as-is', without any express or implied warranty. 5 * In no event will the authors be held liable for any damages arising from 6 * the use of this software. Permission is granted to anyone to use this 7 * software for any purpose, including commercial applications, and to alter 8 * it and redistribute it freely, subject to the following restrictions: 9 * 10 * 1. The origin of this software must not be misrepresented; you must not 11 * claim that you wrote the original software. If you use this software in 12 * a product, an acknowledgment in the product documentation would be 13 * appreciated but is not required. 14 * 15 * 2. Altered source versions must be plainly marked as such, and must not be 16 * misrepresented as being the original software. 17 * 18 * 3. This notice may not be removed or altered from any source distribution. 19 * 20 * 21 * $Date: 14. Jan 2014 22 * $Revision: V1.00 23 * 24 * Project: FlashOS Headerfile for Flash drivers 25 * --------------------------------------------------------------------------- */ 26 27 /* History: 28 * Version 1.00 29 * Initial release 30 */ 31 32 #define VERS 1 // Interface Version 1.01 33 34 #define UNKNOWN 0 // Unknown 35 #define ONCHIP 1 // On-chip Flash Memory 36 #define EXT8BIT 2 // External Flash Device on 8-bit Bus 37 #define EXT16BIT 3 // External Flash Device on 16-bit Bus 38 #define EXT32BIT 4 // External Flash Device on 32-bit Bus 39 #define EXTSPI 5 // External Flash Device on SPI 40 41 #define SECTOR_NUM 512 // Max Number of Sector Items 42 #define PAGE_MAX 65536 // Max Page Size for Programming 43 44 struct FlashSectors { 45 unsigned long szSector; // Sector Size in Bytes 46 unsigned long AddrSector; // Address of Sector 47 }; 48 49 #define SECTOR_END 0xFFFFFFFF, 0xFFFFFFFF 50 51 struct FlashDevice { 52 unsigned short Vers; // Version Number and Architecture 53 char DevName[128]; // Device Name and Description 54 unsigned short DevType; // Device Type: ONCHIP, EXT8BIT, EXT16BIT, ... 55 unsigned long DevAdr; // Default Device Start Address 56 unsigned long szDev; // Total Size of Device 57 unsigned long szPage; // Programming Page Size 58 unsigned long Res; // Reserved for future Extension 59 unsigned char valEmpty; // Content of Erased Memory 60 61 unsigned long toProg; // Time Out of Program Page Function 62 unsigned long toErase; // Time Out of Erase Sector Function 63 64 struct FlashSectors sectors[SECTOR_NUM]; 65 }; 66 67 #define FLASH_DRV_VERS (0x0100+VERS) // Driver Version, do not modify! 68 69 // Flash Programming Functions (Called by FlashOS) 70 extern int Init (unsigned long adr, // Initialize Flash 71 unsigned long clk, 72 unsigned long fnc); 73 extern int UnInit (unsigned long fnc); // De-initialize Flash 74 extern int BlankCheck (unsigned long adr, // Blank Check 75 unsigned long sz, 76 unsigned char pat); 77 extern int EraseChip (void); // Erase complete Device 78 extern int EraseSector (unsigned long adr); // Erase Sector Function 79 extern int ProgramPage (unsigned long adr, // Program Page Function 80 unsigned long sz, 81 unsigned char *buf); 82 extern unsigned long Verify (unsigned long adr, // Verify Function 83 unsigned long sz, 84 unsigned char *buf);
绝大多数的Flash Loader可以去keil的官网上下载。
转载于:https://www.cnblogs.com/lff225-213/p/9596392.html
使用keil 生成 Flash Loader image相关推荐
- 怎么重写MDK(KEIL)Flash烧写程序
MDK提供了Flash烧写程序接口,位于文件夹C:\Keil\ARM\Flash (不同的安装目录参考相对路径).KEIL提供了各种的demo,打开_Template文件夹 有个NewDevice的工 ...
- 使用Flash Loader(JTAG模式)下载EPCS器件
一般来说Altera公司Cyclone或者CycloneII系列FPGA相应的配置器件会选择EPCS系列串行FLASH.一般使用AS模式下载EPCS系列器件.但有时候可能遇到AS模式不能成功下载的案例 ...
- keil 生成bin找不到afx文件_【学习笔记】Keil不能正确生成.bin文件的解决办法
前段时间我写过如何利用CW.IAR和Keil生成image文件,效果还不错,有些用户反馈挺有帮助的,毕竟待项目开发到最后是需要生成image文件用来量产烧写,我们总不至于到最后使用调试下载吧(不过还别 ...
- flash loader下载使用说明
转载:https://blog.csdn.net/weixin_45456099/article/details/107492742 一般只能通过三种方式下载程序到stm32单片机中: 1.JTAG ...
- Flash Loader Demonstrator无响应怎么办?
首先看错误是不是一样的,符合不多说发图片. 解决方法: 第一步: 拔点口袋机下载线,连接口袋和电脑端都必须拔掉(下面有口袋机端的下载线的照片,电脑端就没拍,也必须拔掉). 第二步: 关闭stm32电源 ...
- php多图片生成flash,PHP_为php4加入动态flash文件的生成的支持,想象过在网站上动态生成flash - phpStudy...
为php4加入动态flash文件的生成的支持 想象过在网站上动态生成flash动画吗,本文就让你步入php+flash的激动时代. php真是个好东西呀,真是无法预料她明天会变的怎样...好了,言归正 ...
- 国民单片机通过Keil生成bin文件
大部分单片机通过Keil生成bin文件的操作如下: Option–Output–Select Folder for Objects找到.axf文件,并且将Name of Executable填入和.b ...
- Keil如何生成bin文件【Keil生成Bin文件的方法】
使用过Keil的同鞋都知道,现在Keil中默认可以输出.axf的调试文件和可以通过钩选输出的.hex可执行文件,没有bin(二进制)文件的输出选项.可是偏偏某些时候需要或者习惯性的使用.bin文件来进 ...
- php能做动画吗,使用 PHP 快速生成 Flash 动画
作为直接构建文件的替代性方法,也可以使用下面的代码,使 SWF 动画像页面那样输出,而无需使用 save 方法: 以下为引用的内容: header( 'Content-type: applicatio ...
最新文章
- 黑科技:绕过眼睛植入幻觉,科学家成功在盲人脑海中呈现指定图像!
- 博士申请 | ​香港中文大学LaVi实验室招收2022年秋季入学博士生、硕士生
- Linux(RHEL7.0)下安装nginx-1.10.2
- Oracle 11g 错误:ORA-28002: the password will expire within 7 days 解决方法
- Swift - 本地消息的推送通知(附样例)
- SIP协议学习2-pjsip
- sat2 计算机科目,2019-2020年SAT2考试时间及Top100大学要求
- 从零开始写一个Exporter
- Xen 安装ubuntu xen DomU
- 我为什么要使用Webpack?
- AI技术的苹果iPhone XS Max双卡双待7纳米6.5寸512GB顶配12799元(公号回复“苹果AI”下载PDF资料)
- C# 简单的ZEBRA标签打印程序
- h5 api-获得地理经纬度和异常处理
- 计算机怎么接入外接键盘,无线键盘怎么连接电脑 享受无线惬意生活【图文】...
- pythonforandroid下载中文_SL4A、PythonForAndroid和Android 7.0 Noug
- crate部署(crateDB)
- 【RTD】二分法查找和分段线性插值算法在RTD中应用
- 逻辑函数(表示方法、形式转换、化简、最小项、最大项)
- python学习资源整理
- 架构师成长营-年度成长计划