flashDriver的制作
1、修改连接文件,划分出flashdriver所占的RAM空间(需要更具用户的单片机资源情况进行自定义)
__sram_data_rom_FD = 0x2000EC00;
.Interface_FD_ram :
{
__sram_data_begin_FD__ = .;
*(.Interface)
*(.interface .*)
*(.Interface_Init)
*(.interface_Init .*)
*(.Interface_Erase)
*(.Interface_Erase .*)
*(.Interface_Write)
*(.Interface_Write .*)
*(.Interface_Unlock)
*(.Interface_Unlock .*)
__sram_date_end_FD__ = .;
} > int_dtcm
2、定义结构体,分别存放解锁、擦除和写入函数的函数指针,也可以包含其他参数,存放在划分的空间开始处,便于后续的调用
typedef flashStatus_t(*plockFun)(uint8,uint32,uint32);//解锁函数函数指针
typedef flashStatus_t(*pereaseFun)(uint32_t,uint8);//擦除函数函数指针
typedef falshStatus_t(*ppgFun)(uint32,uint8*,uint8);//写入函数的函数指针
typedef C40_ip_statusType(*pointFun)(const C40_configType*);//初始化函数指针
typedef struct
{
/* Motorola star12 */
const uint8_t mcuType;
/*some mask number */
const uint8_t maskType;
/* byte reserved for future use */
const uint8t reserve;
/*interface version number */
const uint8 t interface;
/*flash initialize function */
const pintFun flashInitFct;
/*flash erase function */
const pereaseFun flashEraseFct;
/*flash program function */
const ppgmFun flashWriteFct;
/*flash Unlock function */
const plockFun flashUnlockFct;
}tflash_infoType;
3、声明和定义解锁,擦除和写入的具体函数内容(注意函数中不能有区局变量、函数外的指针等)什么时将函数指向对应的空间
extern C40_IP_statusType FD_int(const C40_configType * InitConfig)__attribute__((section(".Interface_init")));
extern flashStatus_t FD_SetLockStatus(uint8 blocknum,uiint32 supmask)__attribute__((section(".Interface_init")));
extern flashStatus_t FD_EraseAddredss(uint32 addres,uint8 setting)__attribute__((section(".Interface_init")));
extern flashStatus_t FD_ProgramAddress(uint32 addres,uint8*date,uint8 size)__attribute__((section(".Interface_init")));
4、将结构体放在指定的RAM空间
const tFlash_infoType BLFlash_infoptr __attribute__((section(".interface"))) =
{
TFLASH DRIVER VERSION MCUTYPE,
TFLASH DRIVER VERSION MASKTYPE,
0x00,
TFLASH DRIVER VERSION INTERFACE,
&FD_Int,
&FD EreaseAddress,
&FD ProgramAddress,
&FD SetLockstatus,
}
5、生产bin文件或HEX或S19文件,按照所划分的区域将flash driver部分截取出来,形成单独的flashdriver文件。
6、驱动的使用步骤
1、将UDS工程中的驱动函数和结构体注释掉
2、声明结构体指针,执行存放flash driver空间的首地址,也就是指向了flash driver中的结构体。
const fFlash_InfoType *BLFlash_Infoptr = (tFlash_InfoType*)FL_DEV_BASE_ADDRESS;//指向当时存放结构体的地址
3、在刷写上位机加载flash driver文件,将flash driver写入到RAM中。
4、UDS程序内通过结构体调用相关函数,实现解锁、擦除、写入。
BLFlash_InfoPtr->flashUnlockFct(blocknum, SupMask, NorMask);
BLFlash_InfoPtr->flashEraseFct(address, 0);
BLFlash_InfoPtr->flashWriteFct(address,data,length);