打印

关于IAP over IIC的例程

[复制链接]
1634|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
torsten|  楼主 | 2011-1-11 16:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
iic, iap, ov, TE, AD
void Write_Memory_Command(void)
{
    uint16_t WriteCounter= 0;
    uint16_t Number_Bytes_Transferred = 0;
    uint32_t Add_Flash,DATA_SIZE_IN_PAGE = 0;
    uint16_t Idx = 0;

    /* Wait until receiving Flash address to  write into + number of data to be written
      + the data to be written */
    while (Rx_Idx!= 0);
    /* Read the address  */
    Add_Flash = Read_Add();
    /* Read the number of bytes to be written  */
    Number_Bytes_Transferred = Read_Byte_Page_Number();
    if (Number_Bytes_Transferred <= PAGE_SIZE)
    {
        DATA_SIZE_IN_PAGE = 1;
    }
    else
    {
        if ((Number_Bytes_Transferred%PAGE_SIZE)==0)
        {
            DATA_SIZE_IN_PAGE= Number_Bytes_Transferred/PAGE_SIZE;
        }
        else
        {
            DATA_SIZE_IN_PAGE=(uint32_t) (Number_Bytes_Transferred/PAGE_SIZE)+1;
        }
    }
    for (Idx=4; Idx<(Number_Bytes_Transferred+8)/2; Idx++)
    {
        I2C1_Buffer_Rx[2*Idx+1]=I2C1_Buffer_Rx[2*Idx+1]<<8;
        I2C1_Buffer_Rx[2*Idx]=I2C1_Buffer_Rx[2*Idx]|I2C1_Buffer_Rx[2*Idx+1];
    }
#if defined USE_STM3210B_EVAL  || USE_STM32100B_EVAL
  Erase_Page(Add_Flash,DATA_SIZE_IN_PAGE);
#elif defined USE_STM3210E_EVAL ||  USE_STM3210C_EVAL
  if (((Add_Flash/(PAGE_SIZE/(PAGE_SIZE/Number_Bytes_Transferred)))&1)==0)
    {
        Erase_Page(Add_Flash,DATA_SIZE_IN_PAGE);
    }
#endif  

    for (WriteCounter = 0; (WriteCounter < (Number_Bytes_Transferred)/2 ); WriteCounter++)
    {
        FLASH_ProgramHalfWord((Add_Flash+2*WriteCounter), I2C1_Buffer_Rx[2*(WriteCounter+4)]);
    }
    opcode=0;
}


请问其中下面这句为什么Number_Bytes_Transferred要+8呢
for (Idx=4; Idx<(Number_Bytes_Transferred+8)/2; Idx++)
沙发
香水城| | 2011-1-11 16:29 | 只看该作者
你断章取义地不知道从哪里抄来一段程序,谁知道是什么意思?

提问题,请首先说明背景和出处。

使用特权

评论回复
板凳
torsten|  楼主 | 2011-1-11 16:46 | 只看该作者
2# 香水城
不好意思版主,没说清楚,是官网上的AN3078(in-application programming over IIC)里面的command.c的,我不明白为什么在把收到的字节转成半字的时候,
for (Idx=4; Idx<(Number_Bytes_Transferred+8)/2; Idx++)
这个Number_Bytes_Transferred要+8

使用特权

评论回复
地板
torsten|  楼主 | 2011-1-13 17:28 | 只看该作者
2# 香水城
香主,还有我生成了bin文件,IAP的话是把整个bin文件写到flash里面去吗?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

37

帖子

1

粉丝