This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USB HOST problem during array write

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

Parents Reply Children
  • Auto variables takes whatever values that are in the memory at that specific memory location.

    The debugger then allows you to see the value.

    But it is up to you to make sure that there is an assign that guarantees that the variable has the _correct_ value. And not just happens, by pure chance, to get a random value that looks "good".