我用的是128M的flash,由于单片机的数据存储器容量有限,所以我有4次读写完成1 page 的操作.下面这样写可以吗? void Write10(void) { unsigned long int ByteCount; unsigned int Transfer_Length; unsigned int address; unsigned char rank; unsigned long Logical_Block_Address; Logical_Block_Address=cbw.CBWCB[2]*0x1000000; Logical_Block_Address+=cbw.CBWCB[3]*0x10000; Logical_Block_Address+=cbw.CBWCB[4]*0x100; Logical_Block_Address+=cbw.CBWCB[5]; Transfer_Length=cbw.CBWCB[7]*256+cbw.CBWCB[8];//the number of page(block). while(Transfer_Length--) { for(rank=1;rank<=4;rank++) { ByteCount=512;address=0; while(ByteCount>MAX_BULK_DATA_SIZE) { read_endpoint_buff(1,MAX_BULK_DATA_SIZE,&buffer[address]); ByteCount-=MAX_BULK_DATA_SIZE; address+=MAX_BULK_DATA_SIZE; } read_endpoint_buff(1,ByteCount,&buffer[address]); Flash_page_program(rank,Logical_Block_Address,&buffer); } Flash_reflash(); Logical_Block_Address++; } Return_CSW(0,SUCCESS); }
|