44B0正常操作U盘,后面的帖有CH375源程序。

呵呵,自从上次识别U盘容量正确后,休息了好多天,今天晚上心血来潮,编写了CH375读写扇区的程序,将原来编写的CF卡读写文件的程序稍作修改,就可以正常读写删U盘文件了。 FAT16格式的。一切CH375代码都有源程序,按照沁恒提供的数据手册作的,有疑问的在这里询问后得以解决,不是引用的库文件。

空有访问量,没有回帖量,郁闷,今天把主帖改为回帖可见,其实真正内容在"第2楼".

今天再添加一条广告: 想购买44B0+U盘+CF+CPLD套件的请联系个人信息保护,已隐藏,价格450圆(可以读写U盘或CF卡扇区).如果包含FAT16源代码价格880圆(只可以读写删FAT16根目录文件,子目录下的文件访问不支持).

能贴出来让我们分享吗?


//********************CH375.C**************** /*; CH375/CH372 EVT ; U1(S3C44B0) Program ; ; Website: http:// ; Email: PEIYUAN@2911.NET ; Author: WUHAN 2004.12 ; ;**************************************************************************** */ #include #include "..\inc\44b.h" #include "..\inc\44blib.h" #include "..\inc\CH375.h"

#include #include #include #include #include

//**************************************************************************** #define SUCCESS 0 #define ERROR_READFILE_NOFILE -1 #define ERROR_READFILE_LONGFILENAME -2 #define ERROR_READFILE_BADFILENAME -3 #define ERROR_WRITEFILE_NOSPACE -11 #define ERROR_WRITEFILE_FULLRDT -12 #define ERROR_WRITEFILE_BADCLUSTER -13 #define ERROR_WRITEFILE_FILEEXIST -14

//**************************************************************************** extern unsigned char Usb_Buf_Len; extern unsigned char Usb_Buf[64]; extern U8* Usb_Buf_Startp; extern U8* Usb_Buf_Endp; extern U8 Usb_INT_HAVE; extern U8 Usb_INT_STATUS;

//**************************************************************************** //**************************************************************************** //****************************************************************************

//**************************************************************************** void CH375WriteCommand(U8 commandvalue) { U32 loop; outportb(Ch375_Base_Address + Ch375_Command_Address, commandvalue); for (loop=0;loop<20;loop++) { ; } }

//**************************************************************************** void CH375WriteData(U8 datavalue) { U32 loop; outportb(Ch375_Base_Address + Ch375_Data_Address, datavalue); for (loop=0;loop<5;loop++) { ; } }

//**************************************************************************** U8 CH375ReadData(void) { char i; U32 loop; for (loop=0;loop<5;loop++) { ; } i=inportb(Ch375_Base_Address + Ch375_Data_Address); return i; }

//**************************************************** void CH375_check(void) { CH375WriteCommand(CHECK_EXIST); CH375WriteData(0x55); if (CH375ReadData()==0xaa) { } else { Uart_Printf("\nChip CH375 test error!"); //while(1); } Uart_Printf("\nChip USB test OK!\n"); } //**************************************************** void CH375_setmode(U8 mode) { U8 i,f; f=1; while(f==1) { CH375WriteCommand(SET_USB_MODE); Delay(15); CH375WriteData(mode); Delay(15); i=CH375ReadData(); if (i==CMD_RET_SUCCESS) { f=0; } Delay(1000); } Uart_Printf("Chip USB SET MODE %x\n",mode); } //**************************************************** U8 CH375_get_status(void) { CH375WriteCommand(GET_STATUS); return CH375ReadData(); } //**************************************************** void CH375_Init(void) { CH375_check(); CH375_setmode(0x02); }

//**************************************************** void CH375_Read(void) { int i; CH375WriteCommand(RD_USB_DATA); Usb_Buf_Len=CH375ReadData(); for (i=0;i { Usb_Buf[i]=CH375ReadData(); } }

//**************************************************** void CH375_Write(void)//U8* Usb_Buf_Startp;U8* Usb_Buf_Endp; { U8 k; int i; //int time; //Timer_Start(3);//128us resolution

if ((Usb_Buf_Endp-Usb_Buf_Startp)>64) { Usb_Buf_Len=64; } else { Usb_Buf_Len=Usb_Buf_Endp-Usb_Buf_Startp; } CH375WriteCommand(WR_USB_DATA7); CH375WriteData(Usb_Buf_Len); for (i=0;i { k=*Usb_Buf_Startp; CH375WriteData(k); //Uart_Printf("%x",k); Usb_Buf_Startp++; } //time=Timer_Stop(); //Uart_Printf("%f\n",time*128E-6); }

//**************************************************** void CH375_Unlock_Usb(void) { CH375WriteCommand(UNLOCK_USB); }

//**************************************************** void CH375_Reset_All(void) { CH375WriteCommand(RESET_ALL); }

//****************************************************//**************************************************** //****************************************************//**************************************************** //****************************************************//**************************************************** //****************************************************//****************************************************

//****************************************************

void CH375_INIT_Wait(void) { while(Usb_INT_HAVE==0) { } Usb_INT_HAVE=0; }

//****************************************************

void CH375_Disk_Reset(void) { U8 i; CH375WriteCommand(DISK_RESET); }

//****************************************************

U32 CH375_Disk_Size(void) {

}

//****************************************************

void CH375_Disk_Read(void) {

}

//****************************************************

void CH375_Disk_ReadGo(void) {

}

//****************************************************

void CH375_Disk_Write(void) {

}

//****************************************************

void CH375_Disk_WriteGo(void) {

}

//****************************************************

U32 CH375_Disk_Init(void) { U16 i,j; U32 Size_Udisk; CH375_check(); CH375_setmode(0x06);//usb host

Delay(200); CH375_INIT_Wait(); while(Usb_INT_STATUS!=USB_INT_CONNECT) { }

Delay(2000); CH375WriteCommand(DISK_INIT); CH375_INIT_Wait(); while(Usb_INT_STATUS!=USB_INT_SUCCESS) { }

Delay(2000); Usb_Buf[6]=0xff; while( (Usb_Buf[4]!=0x00)|(Usb_Buf[5]!=0x00)|(Usb_Buf[6]!=0x02)|(Usb_Buf[7]!=0x00) ) { for (j=0;j<20000;j++) { Delay(200); CH375WriteCommand(DISK_SIZE); CH375_INIT_Wait(); if (Usb_INT_STATUS=USB_INT_SUCCESS) break; } CH375_Read(); } Size_Udisk=(Usb_Buf[0]*256*256*256)+(Usb_Buf[1]*256*256)+(Usb_Buf[2]*256)+(Usb_Buf[3]); Size_Udisk=Size_Udisk*0x0200; return Size_Udisk; }

//************************************************************************

S8 CH375_LbaRead(U8 *buffaddr,U32 LbaNo,U8 SecNum) { U8 i; CH375WriteCommand(DISK_READ); CH375WriteData(((LbaNo>>0)&0xff)); CH375WriteData(((LbaNo>>8)&0xff)); CH375WriteData(((LbaNo>>16)&0xff)); CH375WriteData(((LbaNo>>24)&0xff)); CH375WriteData(SecNum); while (1) { CH375_INIT_Wait(); switch (Usb_INT_STATUS) { case USB_INT_DISK_READ: CH375_Read(); for (i=0;i { *buffaddr=Usb_Buf[i]; buffaddr++; } CH375WriteCommand(DISK_RD_GO); break; case USB_INT_SUCCESS: return SUCCESS; break; default : return ERROR_WRITEFILE_BADCLUSTER; break; } } }

//********************************************************************** S8 CH375_LbaWrite(U8 *buffaddr,U32 LbaNo,U8 SecNum) { U8 i; CH375WriteCommand(DISK_WRITE); CH375WriteData(((LbaNo>>0)&0xff)); CH375WriteData(((LbaNo>>8)&0xff)); CH375WriteData(((LbaNo>>16)&0xff)); CH375WriteData(((LbaNo>>24)&0xff)); CH375WriteData(SecNum); while (1) { CH375_INIT_Wait(); switch (Usb_INT_STATUS) { case USB_INT_DISK_WRITE: Usb_Buf_Startp=buffaddr; buffaddr=buffaddr+64; Usb_Buf_Endp=buffaddr; CH375_Write();//void CH375_Write(void)//U8* Usb_Buf_Startp;U8* Usb_Buf_Endp; CH375WriteCommand(DISK_WR_GO); break; case USB_INT_SUCCESS: return SUCCESS; break; default : return ERROR_WRITEFILE_BADCLUSTER; break; } } }


有参考意义,谢谢!


12


请问你44b0降主频了吗?把main函数也贴出来看看吧,我做测试命令 CH375_WR_CMD_PORT( CMD_CHECK_EXIST ); /* 测试CH375是否正常工作 */ CH375_WR_DAT_PORT( 0x55 ); /* 写入测试数据 */ 返回是 0啊,是不是我的读写时序有问题?


不需要降频(66M),只需要这样延时即可. //**************************************************************************** void CH375WriteCommand(U8 commandvalue) { U32 loop; outportb(Ch375_Base_Address + Ch375_Command_Address, commandvalue); for (loop=0;loop<20;loop++) { } }

//**************************************************************************** void CH375WriteData(U8 datavalue) { U32 loop; outportb(Ch375_Base_Address + Ch375_Data_Address, datavalue); for (loop=0;loop<5;loop++) { } }

//**************************************************************************** U8 CH375ReadData(void) { char i; U32 loop; for (loop=0;loop<5;loop++) { } i=inportb(Ch375_Base_Address + Ch375_Data_Address); return i; }

你测试不过关请参看2楼中的程序,这是部分摘录: U32 CH375_Disk_Init(void) { U16 i,j; U32 Size_Udisk; CH375_check();


good


程序太干净了,呵呵


haha


;)


学习中


eee



谢谢,参考一下


调通一个在main中死等读写U盘,不干别的事的程序,再快也是没什么意义的.把你的程序加上FIQ中断嵌套几个IRQ中断并在后台把U盘做存储器随时读写数据试试! 我正用STR710做如此工作,好象比较艰难.


只有登录才能回复,可以选择微信账号登录