我按照网上K40的移植的,函数入下,求解答
/* ###################################################################
** Filename : flexram_eeprom.c
** Project :
** Processor : MK60FX512VLQ15
** Version : Driver 01.01
** Compiler : GNU C Compiler
** Date/Time : 2015-2-27, 9:55, # CodeGen: 0
** Abstract :
**
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/* MODULE flexram_eeprom */
/* Including needed modules to compile this module/procedure */
#include "uart.h"
#include <stdint.h>
#include "common.h"
#include "core_cm4.h"
#include "flexram_eeprom.h"
//
//SIM_FCFG1[EEPROM]¶ÁÈ¡µ±Ç°EEPROMµÄ´óС
//SIM_FCFG1[DEPART]¶ÁÈ¡µ±Ç°backupµÄ´óС
//
/* User includes (#include below this line is not maintained by Processor Expert) */
/*
** ###################################################################
**º¯ÊýÃû³Æ£ºPartition_flash
**º¯Êý¹¦ÄÜ£ºÊµÏÖEEPROMµÄ·ÖÇø
**¾ÙÀý£º Partition_flash( 0X30, 0X07) £» //0X30:16kEEPROM 0X07:512k BACK, 0k Data flash size
**
** ###################################################################
*/
unsigned char Partition_flash(int eeprom_size, int dflash_size)
{
/* Test to make sure the device is not already partitioned. If it
* is already partitioned, then return with no action performed.
*/
if ((SIM->FCFG1 & SIM_FCFG1_DEPART(0xF)) != 0x00000F00)//²é¿´Flex_NVMÊÇ·ñÒѾ·ÖÇø£¬Èç¹ûûÓзÖÇø£¬ÔòÓèÒÔ·ÖÇø£¬Èç¹ûÒѾ·ÖÇø£¬Ôò²»ÔÙ·ÖÇø¡£
{ //07´ú±íÁËDflashÓëEEPROMµÄ·ÖÅä±ÈÀýΪ0:512£¬Óëdflash_size±ØÐëÒ»Ö£¬·ñÔò±¨´í¡£
printf("\nDevice is already partitioned.\n");
return 1;
}
/* Write the FCCOB registers */
FTFE->FCCOB0 = FTFE_FCCOB0_CCOBn(0x80); // Selects the PGMPART command,0X80±à³ÌeepromÃüÁî
FTFE->FCCOB1 = 0x00;
FTFE->FCCOB2 = 0x00;
FTFE->FCCOB3 = 0x00;
/* FCCOB4 is written with the code for the subsystem sizes (eeprom_size define) */
FTFE->FCCOB4 = eeprom_size;
/* FFCOB5 is written with the code for the Dflash size (dflash_size define) */
FTFE->FCCOB5 = dflash_size;
/* All required FCCOBx registers are written, so launch the command */
FTFE->FSTAT = FTFE_FSTAT_CCIF_MASK;//¸øCCIF±ê־λд1-¼´Çå³ýCCIF±ê־룬´Ó¶øÆô¶¯ÃüÁî
/* Wait for the command to complete */
while(!(FTFE->FSTAT & FTFE_FSTAT_CCIF_MASK));//FTFE_FSTATµÄCCIFλÔÚÃüÁîÖ´ÐÐÆÚ¼äʼÖÕ±£³ÖΪ0£¬Ö±µ½ÃüÁîÖ´ÐÐÍê³É²Å±äΪ1£¬µÈ´ýÃüÁî´«ÊäÍê³É
FTFE->FCCOB0 = FTFE_FCCOB0_CCOBn(0x81); // Selects the PGMPART command,0X80±à³ÌeepromÃüÁî
FTFE->FCCOB1 = 0xff;
FTFE->FSTAT = FTFE_FSTAT_CCIF_MASK;//¸øCCIF±ê־λд1-¼´Çå³ýCCIF±ê־룬´Ó¶øÆô¶¯ÃüÁî
/* Wait for the command to complete */
while(!(FTFE->FSTAT & FTFE_FSTAT_CCIF_MASK));//FTFE_FSTATµÄCCIFλÔÚÃüÁîÖ´ÐÐÆÚ¼äʼÖÕ±£³ÖΪ0£¬Ö±µ½ÃüÁîÖ´ÐÐÍê³É²Å±äΪ1£¬µÈ´ýÃüÁî´«ÊäÍê³É
return 0;
}
/*
** ###################################################################
**º¯ÊýÃû³Æ£ºEepromRead_16bit
**º¯Êý¹¦ÄÜ£º°´16bit×Ö¶ÁÈ¡EEPROM Êý¾Ý
**¾ÙÀý£ºEepromRead_16bit(1)£» ¶ÁÈ¡µØַΪ1µÄλÖÃÊý¾Ý×Ö
**×¢Ò⣺ addr<16384,max eeprom = 16K
** ###################################################################
*/
unsigned int EepromRead_16bit(unsigned int addr)//addr<16384,max eeprom = 16K
{
//while(!(FTFE->FCNFG & FTFE_FCNFG_EEERDY_MASK))//Ö»ÓÐEEERDY=1µÄʱºò²ÅÄܶÁдEEPROM
// {
// }
return *((unsigned int*)(0x14000000+addr));
}
/*
** ###################################################################
**º¯ÊýÃû³Æ£ºEepromWrite_16bit
**º¯Êý¹¦ÄÜ£º°´16bit×ÖдEEPROM Êý¾Ý
**¾ÙÀý£ºEepromWrite_16bit(1£¬0x8899)£» ÏòµØÖ·1дÈë0x8899
**×¢Ò⣺ addr<16384,max eeprom = 16K
** ###################################################################
*/
unsigned char EepromWrite_16bit(unsigned int addr, unsigned int data)//addr<16384,max eeprom = 16K
{
if(addr >= EEPROM_SIZE)
return 1;
//while(!(FTFE->FCNFG & FTFE_FCNFG_EEERDY_MASK)){}//Ö»ÓÐEEERDY=1µÄʱºò²ÅÄܶÁдEEPROM
*((unsigned int*)(0x14000000+addr)) = data;
return 0;
}
/*
** ###################################################################
**º¯ÊýÃû³Æ£ºEeprom_Erase
**º¯Êý¹¦ÄÜ£º²Á³ý16KµÄEEPROMËùÓÐÊý¾Ý£¬²Á³ýºóÊý¾Ýλ0
**¾ÙÀý£ºEeprom_Erase()£»
**×¢Ò⣺
** ###################################################################
*/
unsigned char Eeprom_Erase(void)
{
unsigned int addr;
for(addr=0;addr<EEPROM_SIZE;addr++)
{
*((unsigned int*)(0x14000000+addr)) = 0x0000;
while(!(FTFE->FCNFG & FTFE_FCNFG_EEERDY_MASK))//Ö»ÓÐEEERDY=1µÄʱºò²ÅÄܶÁдEEPROM
{
}
}
return 0;
}
/*
** ###################################################################
**º¯ÊýÃû³Æ£ºEeprom_init
**º¯Êý¹¦ÄÜ£º³õʼ»¯EEPROM²ÎÊý£¬ÉèÖÃÏà¹Ø²ÎÊý£¬µ±Ç°É趨Ϊ16KµÄEEPROM£¬512K backup Dflash
**¾ÙÀý£ºEeprom_init()£»
**×¢Ò⣺ ³õʼ»¯²ÎÊý¿É¸ù¾ÝÊÖ²áµ÷Õû£¬Ä¿Ç°ÊÇ×î´óÖµ£»
** ###################################################################
*/
unsigned char Eeprom_init(void)
{
//ʹÄÜARMÄÚºËÏà¹Ø¹ÊÕÏ´¦Àí¼Ä´æÆ÷
SCB->SHCSR|=(SCB_SHCSR_BUSFAULTENA_Msk|SCB_SHCSR_MEMFAULTENA_Msk|SCB_SHCSR_USGFAULTENA_Msk);
/* Partition the memory to enable FlexMem mode */
if ( Partition_flash( 0x30, 0x06) )//0X30:16kEEPROM 0X07:512k BACK, 0k Data flash size
{
return 0;
}
else
return 1;
}
/*
** ###################################################################
**
** This file was created by keil v5
** for the Freescale MK60FX512VLQ12 MCU.
**
** ###################################################################
*/
。h
如下
/* ###################################################################
** Filename : flexram_eeprom.h
** Project :
** Processor : MK60FX512VLQ12
** Version : Driver 01.01
** Compiler : GNU C Compiler
** Date/Time : 2015-2-27, 15:40, # CodeGen: 0
** Abstract :
**
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file flexram_eeprom.h
** @version 01.01
** @brief
**
** This module contains user's application code.
*/
/*!
** @addtogroup ProcessorExpert_module ProcessorExpert module documentation
** @{
*/
/* MODULE flexram_eeprom */
/* Including needed modules to compile this module/procedure */
#include "uart.h"
#include <stdint.h>
#include "common.h"
#include "core_cm4.h"
#define LONGWORD_COUNTER_ADDR 0x14000000
#define WORD_COUNTER_ADDR 0x14000004
#define BYTE_COUNTER_ADDR 0x14000006
#define EEPROM_SIZE 16384 //0X14000000-0X17fffFFF,ALL 16KB
/**********************************************************************/
//EEPROM API
/**********************************************************************/
unsigned char Partition_flash(int eeprom_size, int dflash_size);
unsigned int EepromRead_16bit(unsigned int addr);
unsigned char Eeprom_Erase(void);
unsigned char Eeprom_init(void);
unsigned char EepromWrite_16bit(unsigned int addr, unsigned int data);
|