查看: 5039|回复: 9

[已解决] 请问Flash 使用步骤?

[复制链接]

该用户从未签到

10

主题

27

帖子

3

注册会员

Rank: 2

积分
100
最后登录
2019-1-23
发表于 2018-9-7 18:26:48 | 显示全部楼层 |阅读模式
用的是PLC54606芯片
想将一个字符串写入Flash中

#define SECTOR_15_ADDR 0x00078000
const char TEXT_Buffer[]={"PLC54606 FLASH TEST"};
#define SIZE sizeof(TEXT_Buffer)                //数组长度

int main(void)
{
...
FLASHIAP_PrepareSectorForWrite(15, 15);
FLASHIAP_EraseSector(15, 15, SystemCoreClock/1000);                                                                      //第15扇(起始地址0x00078000)擦除
FLASHIAP_PrepareSectorForWrite(15, 15);
FLASHIAP_CopyRamToFlash(SECTOR_15_ADDR, &TEXT_Buffer[0], SIZE, SystemCoreClock/1000);          //第15扇写入TEXT_Buffer
}


IDE里面调试的时候我看了内存情况,并没有变化,是不是在使用之前要配置clock?还是我这几个函数用的不对?

最佳答案

锁了就不会让你调试了,建议你试一下SDK中flashiap例程,来保证代码是绝对没问题的
回复

使用道具 举报

该用户从未签到

10

主题

27

帖子

3

注册会员

Rank: 2

积分
100
最后登录
2019-1-23
 楼主| 发表于 2018-9-7 18:33:19 | 显示全部楼层
C:\Users\chenjun\Desktop\11.png

点评

图片没显示啊  发表于 2018-9-10 14:51
回复 支持 反对

使用道具 举报

该用户从未签到

712

主题

6371

帖子

0

超级版主

Rank: 8Rank: 8

积分
24849
最后登录
2025-7-17
发表于 2018-9-7 19:36:05 | 显示全部楼层

从你的调用IAP command的顺序来说看不出问题,
有个建议给你:
调用erase 或者program这些个command后,result[0]存的是status ,用于表示command是否调用成功已经错误是什么,这可以用于找出引起问题的原因
回复 支持 反对

使用道具 举报

该用户从未签到

10

主题

27

帖子

3

注册会员

Rank: 2

积分
100
最后登录
2019-1-23
 楼主| 发表于 2018-9-9 14:37:25 | 显示全部楼层
小恩GG 发表于 2018-9-7 19:36
从你的调用IAP command的顺序来说看不出问题,
有个建议给你:
调用erase 或者program这些个command后,r ...

我在每一句后面都加了反馈情况,实际代码如下:

status=FLASHIAP_PrepareSectorForWrite(15, 15);
        if(status==kStatus_FLASHIAP_Success)
        {
                PRINTF("1Api was executed successfully\r\n");
        }
        else if(status==kStatus_FLASHIAP_NoPower)
        {
                PRINTF("1Flash memory block is powered down\r\n");
        }
        else if(status==kStatus_FLASHIAP_NoClock)
        {
                PRINTF("1Flash memory block or controller is not clocked\r\n");
        }
        else if(status==kStatus_FLASHIAP_InvalidSector)
        {
                PRINTF("1Sector number is invalid or end sector number is greater than start sector number\r\n");
        }
        else
        {
                PRINTF("1Flash programming hardware interface is busy\r\n");
        }

        status=FLASHIAP_EraseSector(15, 15, SystemCoreClock/1000);
        if(status==kStatus_FLASHIAP_Success)
        {
                PRINTF("2Api was executed successfully\r\n");
        }
        else if(status==kStatus_FLASHIAP_NoPower)
        {
                PRINTF("2Flash memory block is powered down\r\n");
        }
        else if(status==kStatus_FLASHIAP_NoClock)
        {
                PRINTF("2Flash memory block or controller is not clocked\r\n");
        }
        else if(status==kStatus_FLASHIAP_InvalidSector)
        {
                PRINTF("2Sector number is invalid or end sector number is greater than start sector number\r\n");
        }
        else if(status==kStatus_FLASHIAP_NotPrepared)
        {
                PRINTF("2Command to prepare sector for write operation was not executed\r\n");
        }
        else
        {
                PRINTF("2Flash programming hardware interface is busy\r\n");
        }

        FLASHIAP_PrepareSectorForWrite(15, 15);
        if(status==kStatus_FLASHIAP_Success)
        {
                PRINTF("3Api was executed successfully\r\n");
        }
        else if(status==kStatus_FLASHIAP_NoPower)
        {
                PRINTF("3Flash memory block is powered down\r\n");
        }
        else if(status==kStatus_FLASHIAP_NoClock)
        {
                PRINTF("3Flash memory block or controller is not clocked\r\n");
        }
        else if(status==kStatus_FLASHIAP_InvalidSector)
        {
                PRINTF("3Sector number is invalid or end sector number is greater than start sector number\r\n");
        }
        else
        {
                PRINTF("3Flash programming hardware interface is busy\r\n");
        }

        FLASHIAP_CopyRamToFlash(SECTOR_15_ADDR,&TEXT_Buffer[0], SIZE, SystemCoreClock/1000);
        if(status==kStatus_FLASHIAP_Success)
        {
                PRINTF("4Api was executed successfully\r\n");
        }
        else if(status==kStatus_FLASHIAP_NoPower)
        {
                PRINTF("4Flash memory block is powered down\r\n");
        }
        else if(status==kStatus_FLASHIAP_NoClock)
        {
                PRINTF("4Flash memory block or controller is not clocked\r\n");
        }
        else if(status==kStatus_FLASHIAP_SrcAddrError)
        {
                PRINTF("4Source address is not on word boundary\r\n");
        }
        else if(status==kStatus_FLASHIAP_DstAddrError)
        {
                PRINTF("4Destination address is not on a correct boundary\r\n");
        }
        else if(status==kStatus_FLASHIAP_SrcAddrNotMapped)
        {
                PRINTF("4Source address is not mapped in the memory map\r\n");
        }
        else if(status==kStatus_FLASHIAP_DstAddrNotMapped)
        {
                PRINTF("4Destination address is not mapped in the memory map\r\n");
        }
        else if(status==kStatus_FLASHIAP_CountError)
        {
                PRINTF("4Byte count is not multiple of 4 or is not a permitted value\r\n");
        }
        else if(status==kStatus_FLASHIAP_NotPrepared)
        {
                PRINTF("4Command to prepare sector for write operation was not executed\r\n");
        }
        else
        {
                PRINTF("4Flash programming hardware interface is busy\r\n");
        }
实际也就四个函数起作用嘛,IDE调试后都是Api was executed successfully,这说明成功了嘛,但是看内存情况都是FFFFFFFF啊,没有变化。
回复 支持 反对

使用道具 举报

该用户从未签到

712

主题

6371

帖子

0

超级版主

Rank: 8Rank: 8

积分
24849
最后登录
2025-7-17
发表于 2018-9-10 08:45:46 | 显示全部楼层
我不知道你那边为什么返回值都是 success,你使用的API来自的SDK, FLASHIAP_EraseSector()和FLASHIAP_CopyRamToFlash()函数中第三个参数不需要先除1000,至于又没有其他错误,建议先对照SDK中的flashiap例程检查一遍吧
回复 支持 反对

使用道具 举报

该用户从未签到

10

主题

27

帖子

3

注册会员

Rank: 2

积分
100
最后登录
2019-1-23
 楼主| 发表于 2018-9-13 11:23:25 | 显示全部楼层
小恩GG 发表于 2018-9-10 08:45
我不知道你那边为什么返回值都是 success,你使用的API来自的SDK, FLASHIAP_EraseSector()和FLASHIAP_Co ...

我又改了,现在没有先除以1000了,但是还是有问题
  1. void flash_text(void)
  2. {
  3.         uint32_t status;
  4. status=FLASHIAP_PrepareSectorForWrite(15, 15);
  5.         if(status==kStatus_FLASHIAP_Success)
  6.         {
  7.                 printf("1Api was executed successfully\r\n");
  8.         }
  9.         else if(status==kStatus_FLASHIAP_NoPower)
  10.         {
  11.                 printf("1Flash memory block is powered down\r\n");
  12.         }
  13.         else if(status==kStatus_FLASHIAP_NoClock)
  14.         {
  15.                 printf("1Flash memory block or controller is not clocked\r\n");
  16.         }
  17.         else if(status==kStatus_FLASHIAP_InvalidSector)
  18.         {
  19.                 printf("1Sector number is invalid or end sector number is greater than start sector number\r\n");
  20.         }
  21.         else
  22.         {
  23.                 printf("1Flash programming hardware interface is busy\r\n");
  24.         }

  25. status=FLASHIAP_EraseSector(15, 15, SystemCoreClock);
  26.         if(status==kStatus_FLASHIAP_Success)
  27.         {
  28.                 printf("2Api was executed successfully\r\n");
  29.         }
  30.         else if(status==kStatus_FLASHIAP_NoPower)
  31.         {
  32.                 printf("2Flash memory block is powered down\r\n");
  33.         }
  34.         else if(status==kStatus_FLASHIAP_NoClock)
  35.         {
  36.                 printf("2Flash memory block or controller is not clocked\r\n");
  37.         }
  38.         else if(status==kStatus_FLASHIAP_InvalidSector)
  39.         {
  40.                 printf("2Sector number is invalid or end sector number is greater than start sector number\r\n");
  41.         }
  42.         else if(status==kStatus_FLASHIAP_NotPrepared)
  43.         {
  44.                 printf("2Command to prepare sector for write operation was not executed\r\n");
  45.         }
  46.         else
  47.         {
  48.                 printf("2Flash programming hardware interface is busy\r\n");
  49.         }

  50. status = FLASHIAP_BlankCheckSector(15, 15);
  51.         if(status==kStatus_FLASHIAP_Success)
  52.         {
  53.                 printf("3Api was executed successfully\r\n");
  54.         }
  55.         else if(status==kStatus_FLASHIAP_NoPower)
  56.         {
  57.                 printf("3Flash memory block is powered down\r\n");
  58.         }
  59.         else if(status==kStatus_FLASHIAP_NoClock)
  60.         {
  61.                 printf("3Flash memory block or controller is not clocked\r\n");
  62.         }
  63.         else
  64.         {
  65.                 printf("3One or more sectors are not blank\r\n");
  66.         }

  67. FLASHIAP_PrepareSectorForWrite(15, 15);
  68.         if(status==kStatus_FLASHIAP_Success)
  69.         {
  70.                 printf("4Api was executed successfully\r\n");
  71.         }
  72.         else if(status==kStatus_FLASHIAP_NoPower)
  73.         {
  74.                 printf("4Flash memory block is powered down\r\n");
  75.         }
  76.         else if(status==kStatus_FLASHIAP_NoClock)
  77.         {
  78.                 printf("4Flash memory block or controller is not clocked\r\n");
  79.         }
  80.         else if(status==kStatus_FLASHIAP_InvalidSector)
  81.         {
  82.                 printf("4Sector number is invalid or end sector number is greater than start sector number\r\n");
  83.         }
  84.         else
  85.         {
  86.                 printf("4Flash programming hardware interface is busy\r\n");
  87.         }

  88. FLASHIAP_CopyRamToFlash(SECTOR_15_ADDR,&TEXT_Buffer[0], 256, SystemCoreClock);
  89.         if(status==kStatus_FLASHIAP_Success)
  90.         {
  91.                 printf("5Api was executed successfully\r\n");
  92.         }
  93.         else if(status==kStatus_FLASHIAP_NoPower)
  94.         {
  95.                 printf("5Flash memory block is powered down\r\n");
  96.         }
  97.         else if(status==kStatus_FLASHIAP_NoClock)
  98.         {
  99.                 printf("5Flash memory block or controller is not clocked\r\n");
  100.         }
  101.         else if(status==kStatus_FLASHIAP_SrcAddrError)
  102.         {
  103.                 printf("5Source address is not on word boundary\r\n");
  104.         }
  105.         else if(status==kStatus_FLASHIAP_DstAddrError)
  106.         {
  107.                 printf("5Destination address is not on a correct boundary\r\n");
  108.         }
  109.         else if(status==kStatus_FLASHIAP_SrcAddrNotMapped)
  110.         {
  111.                 printf("5Source address is not mapped in the memory map\r\n");
  112.         }
  113.         else if(status==kStatus_FLASHIAP_DstAddrNotMapped)
  114.         {
  115.                 printf("5Destination address is not mapped in the memory map\r\n");
  116.         }
  117.         else if(status==kStatus_FLASHIAP_CountError)
  118.         {
  119.                 printf("5Byte count is not multiple of 4 or is not a permitted value\r\n");
  120.         }
  121.         else if(status==kStatus_FLASHIAP_NotPrepared)
  122.         {
  123.                 printf("5Command to prepare sector for write operation was not executed\r\n");
  124.         }
  125.         else
  126.         {
  127.                 printf("5Flash programming hardware interface is busy\r\n");
  128.         }

  129. status = FLASHIAP_Compare(SECTOR_15_ADDR,&TEXT_Buffer[0],256);
  130.         if(status==kStatus_FLASHIAP_Success)
  131.         {
  132.                 printf("6Api was executed successfully\r\n");
  133.         }
  134.         else if(status==kStatus_FLASHIAP_NoPower)
  135.         {
  136.                 printf("6Flash memory block is powered down\r\n");
  137.         }
  138.         else if(status==kStatus_FLASHIAP_NoClock)
  139.         {
  140.                 printf("6Flash memory block or controller is not clocked\r\n");
  141.         }
  142.         else if(status==kStatus_FLASHIAP_AddrError)
  143.         {
  144.                 printf("6Address is not on word boundary.\r\n");
  145.         }
  146.         else if(status==kStatus_FLASHIAP_AddrNotMapped)
  147.         {
  148.                 printf("6Address is not mapped in the memory map\r\n");
  149.         }
  150.         else if(status==kStatus_FLASHIAP_CountError)
  151.         {
  152.                 printf("6Byte count is not multiple of 4 or is not a permitted value\r\n");
  153.         }
  154.         else if(status==kStatus_FLASHIAP_CompareError)
  155.         {
  156.                 printf("6Destination and source memory contents do not match\r\n");
  157.         }
  158.         else
  159.         {
  160.                 printf("6 I dont know\r\n");
  161.         }
  162. }
复制代码


调试后
  1. 1Api was executed successfully
  2. 2Api was executed successfully
  3. 3Api was executed successfully
  4. 4Api was executed successfully
  5. 5Api was executed successfully
  6. 6Destination and source memory contents do not match
复制代码

不清楚咋回事,请问这个会不会被锁住了,不让写。
回复 支持 反对

使用道具 举报

该用户从未签到

712

主题

6371

帖子

0

超级版主

Rank: 8Rank: 8

积分
24849
最后登录
2025-7-17
发表于 2018-9-13 13:44:59 | 显示全部楼层
锁了就不会让你调试了,建议你试一下SDK中flashiap例程,来保证代码是绝对没问题的
回复 支持 反对

使用道具 举报

该用户从未签到

10

主题

27

帖子

3

注册会员

Rank: 2

积分
100
最后登录
2019-1-23
 楼主| 发表于 2018-9-13 14:55:57 | 显示全部楼层
小恩GG 发表于 2018-9-13 13:44
锁了就不会让你调试了,建议你试一下SDK中flashiap例程,来保证代码是绝对没问题的 ...

终于找到原因了,谢谢啊!
错误:
  1. const char TEXT_Buffer[]={"flash_text"};
复制代码

我是将这个字符数组存到内存中。但是前面有const就不行。
正确:
  1. char TEXT_Buffer[]={"flash_text"};
复制代码


大神可知道为什么啊?

评分

参与人数 1 +1 收起 理由
NXP管管 + 1

查看全部评分

回复 支持 反对

使用道具 举报

该用户从未签到

712

主题

6371

帖子

0

超级版主

Rank: 8Rank: 8

积分
24849
最后登录
2025-7-17
发表于 2018-9-14 10:15:14 | 显示全部楼层
jungetiantianxi 发表于 2018-9-13 14:55
终于找到原因了,谢谢啊!
错误:
我是将这个字符数组存到内存中。但是前面有const就不行。

const 定义数组,数组会存储在Flash内的,而不是在RAM中,但是FLASHIAP_CopyRamToFlash()命令是将RAM中的数据烧写到Flash中,这样两者就冲突了,这应该是指令执行不成功的原因
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

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

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

GMT+8, 2025-7-17 18:42 , Processed in 0.107448 second(s), 31 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

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