CH374DiskSize已經(jīng)可以正確讀出容量大小,但調(diào)用CH374FileOpen會卡死,不知道什么原因,LIB的版本號是0X19。MCU用的是STM32F103VE6。
?
int main()
{
?u32 isize = 0;
?u8 i;
?uart_init(115200);
?//printf("start\n");
?delay_init();
?LED_Init( LED0 | LED1 | LED2 | LED3 );
?NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);?
???
?CH374_Init();
?i = CH374LibInit( );????????????????????????????????????? /* 初始化CH375程序庫和CH375芯片,操作成功返回0 */
?mStopIfError( i );?
?
?while(1)
?{
??//printf( "Wait Udisk\n" );
??while ( CH374DiskStatus < DISK_CONNECT ) {??????????? /* 查詢CH375中斷并更新中斷狀態(tài),等待U盤插入 */
???if ( CH374DiskConnect( ) == ERR_SUCCESS ) break;? /* 有設(shè)備連接則返回成功,CH375DiskConnect同時會更新全局變量CH375DiskStatus */
???delay_ms( 100 );
??}
??delay_ms(200);
??
??//printf("Disk Init\n");
??for ( i = 0; i < 5; i ++ ) {????????????????????????? /* 有的U盤總是返回未準備好,不過可以被忽略 */
???delay_ms( 100 );
???printf( "Ready ?\n" );
???if ( CH374DiskReady( ) == ERR_SUCCESS ) break;??? /* 查詢磁盤是否準備好 */
??}
??
/* 查詢磁盤物理容量 */
??//printf( "DiskSize\n" );
??i = CH374DiskSize( );?
??mStopIfError( i );
??isize = mCmdParam.DiskSize.mDiskSizeSec * (CH374vSectorSize/512) / 2048;
???printf( "size = %d\n" ,isize);
??//printf( "TotalSize = %u MB \n", (unsigned int)( mCmdParam.DiskSize.mDiskSizeSec * (CH374vSectorSize/512) / 2048 ) );? // 顯示為以MB為單位的容量
??// 原計算方法 (unsigned int)( mCmdParam.DiskSize.mDiskSizeSec * CH374vSectorSize / 1000000 ) 有可能前兩個數(shù)據(jù)相乘后導(dǎo)致溢出, 所以修改成上式
??
??mCmdParam.Open.mPathName[0] = '/';
??mCmdParam.Open.mPathName[1] = '1';
??mCmdParam.Open.mPathName[2] = '.';
??mCmdParam.Open.mPathName[3] = 'C';
??mCmdParam.Open.mPathName[4] = 0;
??i = CH374FileOpen();
??mStopIfError( i );
??CH374FileReadX();
??printf( "size = %d\n" ,mCmdParam.ByteRead.mByteCount);
??
/* 產(chǎn)生新文件 */
??//printf( "Create\n" );???????????????????????????????? //串口創(chuàng)建時間會超長
??mCmdParam.Create.mPathName[0] = '/';
??mCmdParam.Create.mPathName[1] = '1';
??mCmdParam.Create.mPathName[2] = '.';
??mCmdParam.Create.mPathName[3] = 'C';
??mCmdParam.Create.mPathName[4] = 0;
??i = CH374FileCreate( );?????????????????????????????? /* 新建文件并打開,如果文件已經(jīng)存在則先刪除后再新建 */
??mStopIfError( i );
??printf( "Write some data to file 1.C \n" );
??mCmdParam.ByteWrite.mByteBuffer[0] = 'a';
??mCmdParam.ByteWrite.mByteBuffer[1] = 'b';
??mCmdParam.ByteWrite.mByteBuffer[2] = 'c';
??mCmdParam.ByteWrite.mByteBuffer[3] = 'd';
??mCmdParam.ByteWrite.mByteBuffer[4] = 'e';
??
??mCmdParam.ByteWrite.mByteCount = 5;?????????????????? /* 指定本次寫入的字節(jié)數(shù),單次讀寫的長度不能超過MAX_BYTE_IO */
??i = CH374ByteWrite( );??????????????????????????????? /* 以字節(jié)為單位向文件寫入數(shù)據(jù),單次讀寫的長度不能超過MAX_BYTE_IO */
??mStopIfError( i );
?
??//printf( "Close\n" );
??mCmdParam.Close.mUpdateLen = 1;?????????????????????? /* 不要自動計算文件長度,如果自動計算,那么該長度總是CH374vSectorSize的倍數(shù) */
??i = CH374FileClose( );
??mStopIfError( i );??
??
??//printf( "Take out\n" );
??while ( 1 ) {
???delay_ms( 10 );?????????????????????????????????? /* 沒必要頻繁查詢 */
???if ( CH374DiskConnect( ) != ERR_SUCCESS ) break;? /* 查詢方式: 檢查磁盤是否連接并更新磁盤狀態(tài),返回成功說明連接 */
??}
??delay_ms( 200 );??
??
??
?}