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.

CCS/TM4C129XNCZAD: TivaWare_C_Series-2.0.1.11577 examples (dk-tm4c129x): usb_dev_msc

Part Number: TM4C129XNCZAD

Tool/software: Code Composer Studio

HI,

(Tiva ™ TM4C129X Development)
TivaWare_C_Series-2.0.1.11577 examples(dk-tm4c129x): usb_dev_msc points to MX66L51235F.

In the example, usbdspiflash.c has SPIFlash related instructions to read and write MX66L51235F.
I want to point it to the internal flash memory of TM4C129XNCZAD, but I don't know how to modify the msc
Media 

         USBDMSCStorageOpen,
         USBDMSCStorageClose,
         USBDMSCStorageRead,
         USBDMSCStorageWrite,
         USBDMSCStorageNumBlocks,
         USBDMSCStorageBlockSize

Are there related instructions to read data from internal memory? At present, FlashErase and ROM_FlashProgram are only found in related manuals.

Thanks!

Wanying Chin

  • You can use a simple memcpy() to read from the flash. If you want to use the internal flash memory of the TM4C129XNCZAD device, I suggest you use the upper 512KB range (0x80000 to 0xFFFFF). That way the lower range can be used to contain the execution program. The upper and lower halves are in different banks. That allows the code to continue to execute while the upper flash banks are being erased or programmed.

  • Thanks for your reply and suggestions!

    I modified the USBDMSCStorageRead to the following, but the disk displayed by the pc seems to be unusable (the disk needs to be formatted, and the formatting fails)

    uint32_t
    USBDMSCStorageRead(void *pvDrive, uint8_t *pui8Data, uint32_t ui32Sector,
    uint32_t ui32NumBlocks)
    {
    ASSERT(pvDrive != 0);

    g_ui32ReadCount += ui32NumBlocks * FLASH_BLOCK_SIZE;

    /*MX66L51235FRead(ui32Sector * FLASH_BLOCK_SIZE, pui8Data,
    ui32NumBlocks * FLASH_BLOCK_SIZE);*/
    memcpy(pui8Data , ui32Sector * FLASH_BLOCK_SIZE, ui32NumBlocks * FLASH_BLOCK_SIZE);
    return(ui32NumBlocks * FLASH_BLOCK_SIZE);
    }

    Thanks for your reply!

    Wanying Chin

  • You have to replace the functions MX66L51235FSectorErase() and MX66L51235FPageProgram() with equivalents for internal memory. Also remember that if you are using the upper 512KB of internal flash memory, the address will be 0x80000 + (ui32Sector * FLASH_BLOCK_SIZE)

  • usb_dev_msc.7z

    I also modified the USBDMSCStorageWrite , but the same problem still occurs (the disk needs to be formatted, and the formatting fails)

    And a pop-up window display "Volume does not contain a recognized file system. Please make sure all required file systems
    System drivers are loaded and the volume is not corrupted "

    uint32_t
    USBDMSCStorageRead(void *pvDrive, uint8_t *pui8Data, uint32_t ui32Sector, uint32_t ui32NumBlocks)
    {
    ASSERT(pvDrive != 0);
    uint32_t *ui32Addr = (uint32_t*) (ui32Sector * FLASH_BLOCK_SIZE);
    g_ui32ReadCount += ui32NumBlocks * FLASH_BLOCK_SIZE;
    /*MX66L51235FRead(ui32Sector * FLASH_BLOCK_SIZE, pui8Data, ui32NumBlocks * FLASH_BLOCK_SIZE);*/
    memcpy(pui8Data , ui32Addr, (ui32NumBlocks * FLASH_BLOCK_SIZE));
    return(ui32NumBlocks * FLASH_BLOCK_SIZE);
    }

    uint32_t
    USBDMSCStorageWrite(void *pvDrive, uint8_t *pui8Data, uint32_t ui32Sector,
    uint32_t ui32NumBlocks)
    {
    uint32_t ui32Idx, ui32BlockAddr;
    uint32_t ui32PageIdx;

    ASSERT(pvDrive != 0);

    g_ui32WriteCount += ui32NumBlocks * FLASH_BLOCK_SIZE;

    for(ui32Idx = 0; ui32Idx < ui32NumBlocks; ui32Idx++)
    {
    //
    // each block is 4K(0x1000) bytes
    //
    ui32BlockAddr = (ui32Sector + ui32Idx) * FLASH_BLOCK_SIZE;

    //
    // erase the block
    //
    //MX66L51235FSectorErase(ui32BlockAddr);
    ROM_FlashErase(ui32BlockAddr);
    //
    // program the block one page(256 bytes) a time
    //
    for(ui32PageIdx = 0; ui32PageIdx < (FLASH_BLOCK_SIZE / 256);
    ui32PageIdx++)
    {
    /*MX66L51235FPageProgram((ui32BlockAddr + (ui32PageIdx * 256)),
    (pui8Data +(ui32Idx * FLASH_BLOCK_SIZE) +(ui32PageIdx * 256)), 256);*/
    ROM_FlashProgram((pui8Data +(ui32Idx * FLASH_BLOCK_SIZE) +(ui32PageIdx * 256)),
    (ui32BlockAddr + (ui32PageIdx * 256)),
    256);
    }
    }

    return(ui32NumBlocks * FLASH_BLOCK_SIZE);
    }

    Thanks for your reply!

    Wanying Chin

  • It does not look like you corrected the address to point to the upper 512K like I suggested in my previous post. Have you tried to debug the code with breakpoints on the calls to FlashErase and FlashProgram to verify that you are passing the correct parameters?

  • I point the address to the upper 512K.

    The zip file has been modified. Forgot to modify the above article.

    I used wireshark to take a screenshot of the data read.
    The first is the data read by the original example usb_dev_msc pc. It seems that it contains some information in addition to the original data in the external flash.
    The second is that I use memcpy() to read out the internal flash data.

    Don't know if it is the cause?

    Thanks for your reply!

    Wanying Chin

  • When the formula runs to read (10), it will jump out of the disk. Because the disk is not available, I cannot debug the code with breakpoints on the calls to FlashErase and FlashProgram.

    Are there any examples of usb msc using internal flash that can be referenced?

    Thanks!

    Wanying Chin

  • I don't see how you correctly set the address offset in the code in the .7z file. Here is what I suggest.

    I added the file "internal_flash.h" to replace the mx66I5123f.h file.

    #define FLASH_BLOCK_SIZE 8192
    #define FLASH_MEMORY_SIZE 0x80000   // 512KB
    #define FLASH_MEMORY_START 0x80000  // Use high region for data
    

    Then in line 151 of usbdspiflash.c, add the offset "FLASH_MEMORY_START"

    uint32_t
    USBDMSCStorageRead(void *pvDrive, uint8_t *pui8Data, uint32_t ui32Sector,
                       uint32_t ui32NumBlocks)
    {
        ASSERT(pvDrive != 0);
        uint32_t *ui32Addr = (uint32_t*) ((ui32Sector * FLASH_BLOCK_SIZE) + FLASH_MEMORY_START);
        g_ui32ReadCount += ui32NumBlocks * FLASH_BLOCK_SIZE;
        /*MX66L51235FRead(ui32Sector * FLASH_BLOCK_SIZE, pui8Data,
                        ui32NumBlocks * FLASH_BLOCK_SIZE);*/
        memcpy(pui8Data  , ui32Addr, (ui32NumBlocks * FLASH_BLOCK_SIZE));
        return(ui32NumBlocks * FLASH_BLOCK_SIZE);
    }
    

    Then also add the offset FLASH_MEMORY_START to line 193:

    uint32_t
    USBDMSCStorageWrite(void *pvDrive, uint8_t *pui8Data, uint32_t ui32Sector,
                        uint32_t ui32NumBlocks)
    {
        uint32_t ui32Idx, ui32BlockAddr;
        uint32_t ui32PageIdx;
    
        ASSERT(pvDrive != 0);
    
        g_ui32WriteCount += ui32NumBlocks * FLASH_BLOCK_SIZE;
    
        for(ui32Idx = 0; ui32Idx < ui32NumBlocks; ui32Idx++)
        {
            //
            // each block is 8K(0x2000) bytes
            //
            ui32BlockAddr = ((ui32Sector + ui32Idx) * FLASH_BLOCK_SIZE) + FLASH_MEMORY_START;
    
            //
            // erase the block
            // 
            //MX66L51235FSectorErase(ui32BlockAddr);
            ROM_FlashErase(ui32BlockAddr);
            //
            // program the block one page(256 bytes) a time
            // 
            for(ui32PageIdx = 0; ui32PageIdx < (FLASH_BLOCK_SIZE / 256);
                ui32PageIdx++)
            {
                /*MX66L51235FPageProgram((ui32BlockAddr + (ui32PageIdx * 256)),
                                       (pui8Data +
                                        (ui32Idx * FLASH_BLOCK_SIZE) +
                                        (ui32PageIdx * 256)), 256);*/
            	ROM_FlashProgram((pui8Data +(ui32Idx * FLASH_BLOCK_SIZE) +(ui32PageIdx * 256)),
            					 (ui32BlockAddr + (ui32PageIdx * 256)),
    							 256);
            }
        }
    
        return(ui32NumBlocks * FLASH_BLOCK_SIZE);
    }