查看: 5763|回复: 15

[求助] MK60FX512VLQ15读写内部EEPROM问题

[复制链接]

该用户从未签到

4

主题

38

帖子

0

注册会员

Rank: 2

积分
128
最后登录
2014-12-31
发表于 2014-12-28 12:54:34 | 显示全部楼层 |阅读模式
好像照搬了论坛那个 还是不行啊,那个好像不适用于FX512LQ15              读取地址时提示 串口调试提示:BusFault Interrupt0    BusFault Interrupt0

谢谢!谁有读写成功的,麻烦提供参考一下!
我知道答案 目前已有15人回答
回复

使用道具 举报

该用户从未签到

4

主题

38

帖子

0

注册会员

Rank: 2

积分
128
最后登录
2014-12-31
 楼主| 发表于 2014-12-28 12:57:42 | 显示全部楼层
回复 支持 反对

使用道具 举报

该用户从未签到

145

主题

4926

帖子

0

金牌会员

Rank: 6Rank: 6

积分
9267
最后登录
1970-1-1
发表于 2014-12-29 09:15:16 | 显示全部楼层
retome 发表于 2014-12-28 12:57
https://www.nxpic.org.cn/module/forum/thread-564360-1-1.html这个好像不适用于fx512lq15

具体flexNVM的分区指令,你要查看K60 150M的用户手册。
还有就是要保证你本身的基础工程要正确。
你现在分区命令用的是什么?
回复 支持 反对

使用道具 举报

该用户从未签到

4

主题

38

帖子

0

注册会员

Rank: 2

积分
128
最后登录
2014-12-31
 楼主| 发表于 2014-12-29 13:50:34 | 显示全部楼层
FSL_TICS_ZJJ 发表于 2014-12-29 09:15
具体flexNVM的分区指令,你要查看K60 150M的用户手册。
还有就是要保证你本身的基础工程要正确。
你现在 ...

分区命令0x80
回复 支持 反对

使用道具 举报

该用户从未签到

4

主题

38

帖子

0

注册会员

Rank: 2

积分
128
最后登录
2014-12-31
 楼主| 发表于 2014-12-29 13:54:55 | 显示全部楼层


/* Define globals for address of counters */
#define LONGWORD_COUNTER_ADDR 0x14000000
#define WORD_COUNTER_ADDR 0x14000004
#define BYTE_COUNTER_ADDR 0x14000006

__RAMFUNC void flexmem_eeprom_init(void)
{
   SCB_SHCSR|=SCB_SHCSR_BUSFAULTENA_MASK|SCB_SHCSR_MEMFAULTENA_MASK|SCB_SHCSR_USGFAULTENA_MASK;
   //FTFE_FEPROT |=FTFE_FEPROT_EPROT(15);
   //FTFE_FDPROT |=FTFE_FDPROT_DPROT(15);
  partition_flash( EEPROM_8K_8K, DFLASH_SIZE_256);
}


__RAMFUNC void flexmem_ee32bit_write(uint32 flex_addr,uint32 flex_data)
{
                  *((uint32 *)(flex_addr)) = flex_data;
                  while(!(FTFE_FCNFG & FTFE_FCNFG_EEERDY_MASK));
}

void flexmem_ee16bit_write(uint16 flex_addr,uint16 flex_data)
{
                *((uint16 *)(flex_addr)) = flex_data;
                  while(!(FTFE_FCNFG & FTFE_FCNFG_EEERDY_MASK));
}

void flexmem_ee8bit_write(uint8 flex_addr,uint8 flex_data)
{
           *((uint8 *)(flex_addr)) = flex_data;
            while(!(FTFE_FCNFG & FTFE_FCNFG_EEERDY_MASK));
}


uint32 flex_ee32bit_read(uint32 flex_addr)
{
  return (*(uint32 *)(flex_addr));
}


uint16 flex_ee16bit_read(uint16 flex_addr)
{
  return (*(uint16 *)(flex_addr));
}

uint8 flex_ee8bit_read(uint8 flex_addr)
{
  return (*(uint8 *)(flex_addr));
}



__RAMFUNC   uint8 partition_flash(uint16 eeprom_size, uint16 dflash_size)
{
      /* Test to make sure the device is not already partitioned. If it
       * is already partitioned, then return with no action performed.
       */
   //FTFE_FCCOB0 = FTFE_FCCOB0_CCOBn(0x44); // Selects the PGMPART command
     /* Wait for the command to complete */
   //   printf("error:%d\n",FTFE_FSTAT);

    if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0xF)) != 0x00000F00)
     {
         // printf("\nDevice is already partitioned.\n");
          return 0;
      }

      /* Write the FCCOB registers */
      FTFE_FCCOB0 = FTFE_FCCOB0_CCOBn(0x80); // Selects the PGMPART command
      FTFE_FCCOB1 = 0x00;
      FTFE_FCCOB2 = 0x00;
      FTFE_FCCOB3 = 0x00;
      FTFE_FCCOB4 = eeprom_size;
      FTFE_FCCOB5 = dflash_size;  
     FTFE_FSTAT |= FTFE_FSTAT_CCIF_MASK;
      while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK));
      return 1;
}
回复 支持 反对

使用道具 举报

该用户从未签到

4

主题

38

帖子

0

注册会员

Rank: 2

积分
128
最后登录
2014-12-31
 楼主| 发表于 2014-12-29 13:59:50 | 显示全部楼层
FSL_TICS_ZJJ 发表于 2014-12-29 09:15
具体flexNVM的分区指令,你要查看K60 150M的用户手册。
还有就是要保证你本身的基础工程要正确。
你现在 ...

  flexmem_ee32bit_write(0x14000006,0x000123);
仿真运行完到这个的时候就会串口调试输出:BusFault Interrupt0    BusFault Interrupt0
再运行这个 printf("%d\n",flex_ee32bit_read(0x14000006)); 居然输出是-625435;居然是负数!
回复 支持 反对

使用道具 举报

该用户从未签到

4

主题

38

帖子

0

注册会员

Rank: 2

积分
128
最后登录
2014-12-31
 楼主| 发表于 2014-12-29 14:00:53 | 显示全部楼层
FSL_TICS_ZJJ 发表于 2014-12-29 09:15
具体flexNVM的分区指令,你要查看K60 150M的用户手册。
还有就是要保证你本身的基础工程要正确。
你现在 ...

以下就是基础工程的几个函数:

/* Define globals for address of counters */
#define LONGWORD_COUNTER_ADDR 0x14000000
#define WORD_COUNTER_ADDR 0x14000004
#define BYTE_COUNTER_ADDR 0x14000006

__RAMFUNC void flexmem_eeprom_init(void)
{
   SCB_SHCSR|=SCB_SHCSR_BUSFAULTENA_MASK|SCB_SHCSR_MEMFAULTENA_MASK|SCB_SHCSR_USGFAULTENA_MASK;
   //FTFE_FEPROT |=FTFE_FEPROT_EPROT(15);
   //FTFE_FDPROT |=FTFE_FDPROT_DPROT(15);
  partition_flash( EEPROM_8K_8K, DFLASH_SIZE_256);
}


__RAMFUNC void flexmem_ee32bit_write(uint32 flex_addr,uint32 flex_data)
{
                  *((uint32 *)(flex_addr)) = flex_data;
                  while(!(FTFE_FCNFG & FTFE_FCNFG_EEERDY_MASK));
}

void flexmem_ee16bit_write(uint16 flex_addr,uint16 flex_data)
{
                *((uint16 *)(flex_addr)) = flex_data;
                  while(!(FTFE_FCNFG & FTFE_FCNFG_EEERDY_MASK));
}

void flexmem_ee8bit_write(uint8 flex_addr,uint8 flex_data)
{
           *((uint8 *)(flex_addr)) = flex_data;
            while(!(FTFE_FCNFG & FTFE_FCNFG_EEERDY_MASK));
}


uint32 flex_ee32bit_read(uint32 flex_addr)
{
  return (*(uint32 *)(flex_addr));
}


uint16 flex_ee16bit_read(uint16 flex_addr)
{
  return (*(uint16 *)(flex_addr));
}

uint8 flex_ee8bit_read(uint8 flex_addr)
{
  return (*(uint8 *)(flex_addr));
}



__RAMFUNC   uint8 partition_flash(uint16 eeprom_size, uint16 dflash_size)
{
      /* Test to make sure the device is not already partitioned. If it
       * is already partitioned, then return with no action performed.
       */
   //FTFE_FCCOB0 = FTFE_FCCOB0_CCOBn(0x44); // Selects the PGMPART command
     /* Wait for the command to complete */
   //   printf("error:%d\n",FTFE_FSTAT);

    if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0xF)) != 0x00000F00)
     {
         // printf("\nDevice is already partitioned.\n");
          return 0;
      }

      /* Write the FCCOB registers */
      FTFE_FCCOB0 = FTFE_FCCOB0_CCOBn(0x80); // Selects the PGMPART command
      FTFE_FCCOB1 = 0x00;
      FTFE_FCCOB2 = 0x00;
      FTFE_FCCOB3 = 0x00;
      FTFE_FCCOB4 = eeprom_size;
      FTFE_FCCOB5 = dflash_size;  
     FTFE_FSTAT |= FTFE_FSTAT_CCIF_MASK;
      while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK));
      return 1;
}
回复 支持 反对

使用道具 举报

该用户从未签到

145

主题

4926

帖子

0

金牌会员

Rank: 6Rank: 6

积分
9267
最后登录
1970-1-1
发表于 2014-12-29 14:48:39 | 显示全部楼层
楼主跑看看我这个代码,在RAM中运行; EEPROM大小是2K。

K60FX150_EEPROM.rar (1.02 MB, 下载次数: 43)
回复 支持 反对

使用道具 举报

该用户从未签到

4

主题

38

帖子

0

注册会员

Rank: 2

积分
128
最后登录
2014-12-31
 楼主| 发表于 2014-12-29 16:17:26 | 显示全部楼层
FSL_TICS_ZJJ 发表于 2014-12-29 14:48
楼主跑看看我这个代码,在RAM中运行; EEPROM大小是2K。

灰常感谢FSL_TICS_ZJJ
回复 支持 反对

使用道具 举报

该用户从未签到

145

主题

4926

帖子

0

金牌会员

Rank: 6Rank: 6

积分
9267
最后登录
1970-1-1
发表于 2014-12-29 17:02:02 | 显示全部楼层
retome 发表于 2014-12-29 16:17
灰常感谢FSL_TICS_ZJJ

不客气,测试之后把结果告诉我,是否能打印出来。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-7-20 13:32 , Processed in 0.113638 second(s), 31 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表