This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5529: USBMSC updating mediainfo

Part Number: MSP430F5529

Hello,

I would like to ask some help in how to do mediainfo update.

I am just a begginner to USB programming. I register CDC and MSC endpoints. Using CDC through FatFs updating a file. At first read Linux reads correctly the file content, but I concluded that the API should be informed about a file has been changed later. 

I would like to ask some help, how to inform the the system about the change.

Thank you in advance,

LAszlo

  • Hello LAszlo,

    That type of functionality would need to be added to your file system SW (FatFs) and your application code. Barring that, you could do a changelog file, but that seems cumbersome. 

    The MSP430 USB API only handles USB stack and transferring of data. Your application should determine if its good data to transfer or if its the latest. See section 8 of the MSP430 USB Programmers guide (inside https://www.ti.com/tool/MSP430USBDEVPACK ) for more information about the MSC implementation. 

  • Hello Jace,

    thanks for directing me. I need some time to rework my code. Hope this helps.

  • Hello Jace,

    I have modified the program according to the direction read in the programmers guide. Unfortunately, it even worse, it blocks after the first writing - no update. Would you so kind having a look at the relevant code, I am not sure I understand the direction well.

            switch (USB_getConnectionState())
            {
                // This case is executed while your device is enumerated on the
                // USB host
                case ST_ENUM_ACTIVE:
    
                    USBMSC_processMSCBuffer(); // Handle READ/WRITE cmds from the host
    
                    // Every second, the Timer_A ISR sets this flag.  The
                    // checking can't be done from within the timer ISR, because it
                    // enables interrupts, and this is not a recommended
                    // practice due to the risk of nested interrupts.
                    if (bDetectCard){
                        USBMSC_checkMSCInsertionRemoval();
    
                        // Clear the flag, until the next timer ISR
                        bDetectCard = 0x00;
                    }
    
                    if (bCDCDataReceived_event){
    
                        // Clear flag early -- just in case execution breaks
                        // below because of an error
                        bCDCDataReceived_event = FALSE;
    
                        count = USBCDC_receiveDataInBuffer((uint8_t*)message, 32, CDC0_INTFNUM);
    
                        USBCDC_sendDataInBackground((uint8_t*)message, count, CDC0_INTFNUM, 1);
    
                        for( i = 0; i < count; i++) {
                            strcat((char *)command, (char *)&message[i]);
                            if ( message[i] == '\x0D' ) command_received = TRUE;
                            strcat((char *)command, (char *)"\x00");
                        }
                    }
    
    
                    if (command_received) {
    
                        command_received = FALSE;
    
                        f_mount(0, &FatFs);
                        fr = f_open( &fd, filename, FA_WRITE);
                        f_stat( filename, &fi );
                        f_lseek( &fd, fi.fsize );
                        if ( fr == FR_OK ) {
                            f_write( &fd, command, strlen((const char *)command), &nob_written );
                            f_sync( &fd );
                            fr = f_close( &fd );
                            }
                        f_mount(0, NULL);
    
                        *command='\x00';
    
                        mI.mediaPresent = USBMSC_MEDIA_PRESENT;
                        mI.mediaChanged = TRUE;
                        mI.writeProtected = 0x00;
                        disk_ioctl(0,GET_SECTOR_COUNT,&mI.lastBlockLba);
                        mI.bytesPerBlock = BYTES_PER_BLOCK;
                        USBMSC_updateMediaInformation( 0, &mI);
                    }
    
                    break;
    
    
                // These cases are executed while your device is disconnected from
                // the host (meaning, not enumerated); enumerated but suspended
                // by the host, or connected to a powered hub without a USB host
                // present.
                case ST_PHYS_DISCONNECTED:
                case ST_ENUM_SUSPENDED:
                case ST_PHYS_CONNECTED_NOENUM_SUSP:
    //                __bis_SR_register(LPM3_bits + GIE);
                    _NOP();
                    break;
    
                // The default is executed for the momentary state
                // ST_ENUM_IN_PROGRESS.  Usually, this state only last a few
                // seconds.  Be sure not to enter LPM3 in this state; USB
                // communication is taking place here, and therefore the mode must
                // be LPM0 or active-CPU.
                case ST_ENUM_IN_PROGRESS:
                default:;
            }
    

  • Hey Laszlo,

    Try getting back to a known good state by following along/cross-checking with our MSC examples in the USB Library.  https://dev.ti.com/tirex/explore/node?node=ACRg-lXAVWco7CfffvwKsg__IOGqZri__LATEST 

**Attention** This is a public forum