Hi I want to send an array of data to a USB pen drive using LPC1768. and USBhostlite code is available here: >ics.nxp.com/.../ and I removed Uart from codes so that it just copies data to usb. the codes that i modified are:
void Main_Write(void){ USB_INT32S fdw; USB_INT32U bytes_read; char temp[8]; USB_INT08U temp_buf[504]={0}; int i,j={0}; bytes_read=9; fdw = FILE_Open(FILENAME_W, RDWR); if (fdw>0) { do{ sprintf(temp,"%d",bytes_read); for (j=0;j<9;j++){ temp_buf [i]=(temp[j]); i++; } temp_buf [i]=0xA; i++; bytes_read ++; }while(i<=504); FILE_Write(fdw,temp_buf,504); FILE_Close(fdw); }else{ return; } }
sprintf converts bytes_read to ascii codes then it is sent to temp_buf using a do{...}while() then an "MSWRITE.TXT" file is created in usb disk and finally the buffer will be written to the usb disk.
these codes work properly, when size of the buffer(temp_buf) is less than "90". but when i change the buffer size to a bigger number(eg: 504), the program doesn't work! it even doesn't creates any empty text file(due to file_open) i traced file_open routine and i found that the problem is in MS_BulkRecv routine. because the program runs before calling MS_BulkRecv and halts during calling this line. this routine is as follows:
*********************************************************************************************** * RECEIVE THE BULK DATA * * Description: This function is used to receive the bulk data * * Arguments : None * * Returns : OK if Success * ERR_INVALID_BOOTSIG if Failed * **********************************************************************************************/ USB_INT32S MS_BulkRecv ( USB_INT32U block_number, USB_INT16U num_blocks, volatile USB_INT08U *user_buffer) { USB_INT32S rc; int i; volatile USB_INT08U *c = user_buffer; for (i=0;i<MS_BlkSize*num_blocks;i++) *c++ = 0; Fill_MSCommand(block_number, MS_BlkSize, num_blocks, MS_DATA_DIR_IN, SCSI_CMD_READ_10, 10); rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE); if (rc == OK) { rc = Host_ProcessTD(EDBulkIn, TD_IN, user_buffer, MS_BlkSize * num_blocks); if (rc == OK) { rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE); if (rc == OK) { if (TDBuffer[12] != 0) { rc = ERR_MS_CMD_FAILED; } } } } return (rc); }
can any body tell me why this increase in buffer size causes the program not to work? and help me to solve it?
thanks Amir
last lines of your badly formatted code
..... return; } } // what happens here?
} // what happens here?
when the size of buffer is less than 90: an "mswrite.txt" file is created in usb drive. but when this size is greater than 90, nothing is created in usb drive. even FILE_OPEN doesn't run properly. and next lines doesn't run!
Amir
*********************************************************************************************** * RECEIVE THE BULK DATA * * Description: This function is used to receive the bulk data * * Arguments : None * * Returns : OK if Success * ERR_INVALID_BOOTSIG if Failed * **********************************************************************************************/ USB_INT32S MS_BulkRecv ( USB_INT32U block_number, USB_INT16U num_blocks, volatile USB_INT08U *user_buffer)
/************************************************************************************************ * TYPE DEFINITIONS OF DATA TYPES ************************************************************************************************/ typedef unsigned int USB_INT32U; typedef signed int USB_INT32S; typedef unsigned short USB_INT16U; typedef signed short USB_INT16S; typedef unsigned char USB_INT08U; typedef signed char USB_INT08S;
there are some typo in Description of the routines. I think this is just a mistake. when the routines, recives the bulk data, it must exits parameters as input.
Thanks Amir