历史上的今天
今天是:2025年07月30日(星期三)
2021年07月30日 | MC9S12XEP100 FTM模块 驱动程序
2021-07-30 来源:eefocus
MC9S12XEP100的Flash(S12XFTM1024K5V2)包含:
1024KB的P-Flash 内存,包含5个物理Flash blocks,用于存储非易失性代码。
32KB的D-Flash内存,由一个物理Flash block组成,可作为Flash内存存储非易失性数据,或用于支持内建的模拟EEPROM。
4KB的缓存RAM,由一个物理RAM block组成,可用作普通的RAM,或者用于支持内建的模拟EEPROM。
MC9S12(X)系列单片机的Flash内存可以在不加外部电压的情况下自我重编程(擦除/写入),这是通过FTM模块提供的一个内存控制器来完成的,内存控制器独立于内核运行,用户通过给内存控制器传递命令及参数以使内存控制器修改Flash内存内容或配置模拟EEPROM资源;控制过程如下图:

本驱动程序对这个控制过程进行了封装(即FTM_LaunchCommand函数),并进一步对所有可用的命令进行了封装,提供了用户友好的接口,方便各位使用。
下面上代码:
先是FTM.h文件
/*
*********************************************************************************************************
*
*
* FLASH TECHNOLOGY MODULE SUPPORT MODULE
* FREESCALE MC9S12XEP100
* 飞思卡尔单片机 FLASH模块(FTM) 支持包
*
* File : FTM.h
* By : Lin Shijun(http://blog.csdn.net/lin_strong)
* Date : 2020/01/09
* Version : V2.4
* Note : 1. this module is customized for MC9S12XEP100. If used for other derivation, it may need
* some modification according to the PARTID.
* History : 2018/03/12 v1.0 prototype of the package.
* 2018/03/31 v1.1 a little modification.
* 2018/04/12 v2.0 encapsulate all of the FLASH COMMON COMMAND into more user-friendly interface.
* 2018/07/02 v2.1 add code in FTM_LaunchCommand to clear flags.
* 2018/07/05 v2.2 exclude FTM_FSTAT_MASK_MGBUSY from FTM_FSTAT_MASK_ANYERR
* 2019/03/19 v2.3 fix a bug that if EEPROM happens to be updating datas. The FTM may treat
* MGBUSY flag as error. So I remove FTM_FSTAT_MASK_MGBUSY from the
* FTM_FSTAT_MASK_ANYERR malloc.
* some modifications to the configuration malloc.
* 2020/01/09 v2.4 add FTM_EEPROM_WaitFinish interface
*********************************************************************************************************
*/
#ifndef _FTM_H
#define _FTM_H
/*
*********************************************************************************************************
* TYPE DEFINITION 类型定义
*********************************************************************************************************
*/
/*** FSTAT - Flash Status Register; ***/
typedef union {
unsigned char Byte;
struct {
unsigned int MGSTAT0 :1; /* Memory Controller Command Completion Status Flag 0 */
unsigned int MGSTAT1 :1; /* Memory Controller Command Completion Status Flag 1 */
unsigned int :1;
unsigned int MGBUSY :1; /* Memory Controller Busy Flag */
unsigned int FPVIOL :1; /* Flash Protection Violation Flag */
unsigned int ACCERR :1; /* Flash Access Error Flag */
unsigned int :1;
unsigned int CCIF :1; /* Command Complete Interrupt Flag */
} Bits;
} FTM_FSTAT;
#define FTM_FSTAT_MASK_MGSTAT0 1U
#define FTM_FSTAT_MASK_MGSTAT1 2U
#define FTM_FSTAT_MASK_MGBUSY 8U
#define FTM_FSTAT_MASK_FPVIOL 16U
#define FTM_FSTAT_MASK_ACCERR 32U
#define FTM_FSTAT_MASK_CCIF 128U
#define FTM_FSTAT_MASK_ANYERR (FTM_FSTAT_MASK_MGSTAT0 | FTM_FSTAT_MASK_MGSTAT1 |
FTM_FSTAT_MASK_FPVIOL | FTM_FSTAT_MASK_ACCERR)
/*** FERSTAT - Flash Error Status Register; ***/
typedef union {
unsigned char Byte;
struct {
unsigned int SFDIF :1; /* Single Bit Fault Detect Interrupt Flag */
unsigned int DFDIF :1; /* Double Bit Fault Detect Interrupt Flag */
unsigned int ERSVIF0 :1; /* EEE Error Type 0 Interrupt Flag */
unsigned int ERSVIF1 :1; /* EEE Error Type 1 Interrupt Flag */
unsigned int EPVIOLIF :1; /* EEE Protection Violation Interrupt Flag */
unsigned int :1;
unsigned int PGMERIF :1; /* EEE Program Error Interrupt Flag */
unsigned int ERSERIF :1; /* EEE Erase Error Interrupt Flag */
} Bits;
} FTM_FERSTAT;
#define FTM_FERSTAT_MASK_SFDIF 1U
#define FTM_FERSTAT_MASK_DFDIF 2U
#define FTM_FERSTAT_MASK_ERSVIF0 4U
#define FTM_FERSTAT_MASK_ERSVIF1 8U
#define FTM_FERSTAT_MASK_EPVIOLIF 16U
#define FTM_FERSTAT_MASK_PGMERIF 64U
#define FTM_FERSTAT_MASK_ERSERIF 128U
#define FTM_FERSTAT_MASK_ERSVIF 12U
#define FTM_FERSTAT_MASK_ANYERR (FTM_FERSTAT_MASK_SFDIF | FTM_FERSTAT_MASK_DFDIF | FTM_FERSTAT_MASK_ERSVIF0 |
FTM_FERSTAT_MASK_ERSVIF1 | FTM_FERSTAT_MASK_EPVIOLIF | FTM_FERSTAT_MASK_PGMERIF |
FTM_FERSTAT_MASK_ERSERIF)
typedef union{ //Used to copy and store Flash error status registers.
unsigned short Word;
struct{
FTM_FSTAT fstat;
FTM_FERSTAT ferstat;
} Regs;
} FTM_STATUS;
#define FTM_STATUS_WORD(status) ((status).Word)
#define FTM_STATUS_FSTAT_BYTE(status) ((status).Regs.fstat.Byte)
#define FTM_STATUS_FERSTAT_BYTE(status) ((status).Regs.ferstat.Byte)
typedef struct {
// values if prior to partitioning.
// dfPart = 0xffff, erPart = 0xffff, ECOUNT = 0xffff, deadCnt = 0x00, rdyCnt = 0x00
unsigned short dfPart; // the number of D-flash Sector for genernal use. 0 - 128.
unsigned short erPart; // the number of EEE RAM sections for the FTM (Flash module) to use as EEE. 0 - 16.
unsigned short ersCnt; // sector erase count.
unsigned char deadCnt; // dead sector count.
unsigned char rdyCnt; // ready sector count.
} FTM_EEE_STATUS,*pFTM_EEE_STATUS;
typedef struct {
unsigned short word0;
unsigned short word1;
unsigned short word2;
unsigned short word3;
} INT64U,FTM_KEYGEN;
/*
*********************************************************************************************************
* FLASH COMMON COMMAND FLASH通用命令
*********************************************************************************************************
*/
/**** P-Flash and D-Flash Commands ****/
#define ERASE_VERIFY_ALL_BLOCKS 0x01
// Verify that all program and data Flash blocks are erased.
// CCOBIX end = 0
// CCOB Params - NONE
// MGSTAT set if fault
#define ERASE_VERIFY_BLOCK 0x02
// Verify that a Flash block is erased.
// CCOBIX end = 0
// CCOB Params - gpage
// MGSTAT set if fault
#define ERASE_ALL_BLOCKS 0x08
// Erase all program and data Flash blocks.
// An erase of all Flash blocks is only possible when the FPLDIS, FPHDIS, and FPOPEN
// bits in the FPROT register and the EPDIS and EPOPEN bits in the EPROM register are
// set prior to launching the command.
// CCOBIX end = 0
// CCOB Params - NONE
// MGSTAT set if fault, FPVIOL / ACCERR set where appropriate
#define UNSECURE_FLASH 0x0B
// Supports a method of releasing MCU security by erasing all program and data Flash
// blocks and verifying that all program and data Flash blocks are erased.
// CCOBIX end = 0
// CCOB Params - NONE
// MGSTAT set if fault
#define SET_USER_MARGIN_LEVEL 0x0D
// Specifies a user margin read level for all program Flash blocks.
史海拾趣
|
所用元件:P沟道MOSFET IRF9530,一个二极管1N4001,一个5W20欧的电阻,一个220V变15V的变压器。 控制信号:采用+12V,-12V进行控制。 现在是这样连接的:220经过变压器的初级,变压器的次级接上个1N4001二极管(只让正电压通过),二极管后接上 ...… 查看全部问答> |
|
电话主叫识别信息传送及接收(俗称来电显示), 简称CID(Calling Identify Delivery),是电信局向被叫 电话用户提供的一种服务项目, 是指在被叫用户终 端设备上显示主叫电话号码、主叫用户姓名、呼叫 日期和时间等主叫识别信息并进行存储, 以供 ...… 查看全部问答> |
|
首先读取F盘500的文件,将数据写入安全区,接着再把安全区的数据写到新的文件中, 一次读写128个扇区以上,新生成的文件是损坏的。读写低于128个扇区的,读写扇区数越低,读写速度越慢。当读写扇区数为128时,速度最快,新生成文件可以正常使用。 ...… 查看全部问答> |
|
准确的问题点已经找到,只要将P2.4设置成输入(P2.0输入,两个端口都对地接10K电阻,其余都设成输出),启动AD P2.0采集,经测试,不论有没有REF输出,P2.4瞬间出现80MV左右的尖脉冲,此时电流都很大。 没有REF输出时,只要将P2.4直接对地短路(接 ...… 查看全部问答> |
|
请教各位大虾,我用F149通过L298N驱动两个9伏的电机。单片机io口直接连电机驱动模块,感觉所有的连线都没有错误,但是电机驱动端输出的电压只有0伏。是不是单片机IO口的电压太低呢??… 查看全部问答> |
|
我是在网上找的44b0的iic程序,但是在读写E2PROM是总是读出个ff,我的开发板用的是st24c08的E2PROM,这个问题困扰我很久了,我也对照了下时序,也没有发现什么问题,请各位坛友一定要帮这个忙啊!下面是程序: void Test_Iic(void) { unsign ...… 查看全部问答> |
|
轮换之前 轮换之后 优先级情况为什么会变成这样呢? [ 本帖最后由 ytzys 于 2012-3-26 10:28 编辑 ]… 查看全部问答> |




