系统升级功能须要 把内部flash数据发送到外部flash作备份等操做。 注意,内部flash起始地址为0,和NULL是同样的,函数
所以在使用驱动接口的时候,对于第一个page的flash,会看成NULL处理, 这就引起bug,SPI驱动会认为TX-BUF为NULL而使用默认的0x00做为填充数据!ui
因此对于这个特别的page,先拷贝到ram再发送到驱动层, 且注意,不要使用memcpy,由于也会进行NULL判断。code
按照以下方式(代码来自upgrade.c)接口
//then copy the first page /****************************************************** Caution!!!! The fisrt flash page start addr is 0 !!! That is the same as NULL!!!! so copy to ram buffer first!!! DO NOT use memcpy!! ******************************************************/ do{ uint8_t buff[4]; pSrc = (const uint8_t*)INTFLASH_BLE_APP_ADDR; dstAddr=extFlashAddr; ((uint32_t*)buff)[0]=((uint32_t*)pSrc)[0]; if(copy_page_to_sflash(buff,dstAddr,4)!=0) return -1; return copy_page_to_sflash(pSrc+4,dstAddr+4,256-4); }while(0);
而在BIM中,因为是按一个一个字节发送数据的,所以此问题不会出现! 但依旧须要注意NULL问题,不要使用 memcpy等函数。flash