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.

USB with SD Card as mass storage device

Other Parts Discussed in Thread: MSP430F5638, MSP430F5529, TUSB3410, MSP430F1612

I started with the MSP-EXP430F5529 Experimental Board and got everything to work as needed with the code provided. Now for my particular project there are a lot more features we need the MSP430 to do and we wanted a smaller package. We designed a new board using the MSP430F5638, which also has the USB port and uses the same user guide as the MSP430F5529.

I am trying to get the USB to work on this new board with the MSP430F5638. I imported the USB code over, but it fails. I can do the initial set up just fine, call the MassStorage function, show that the USB is connected and enabled, but it gets stuck in the USB_Reset function. In the function it sets up the IEPs like shown below.

        BYTE edbIndex = stUsbHandle[i].edb_Index;

        /* Set settings for IEPx */
        tInputEndPointDescriptorBlock[edbIndex].bEPCNF   = EPCNF_USBIE |
                                                           EPCNF_UBME |
                                                           EPCNF_DBUF;              //double buffering
        tInputEndPointDescriptorBlock[edbIndex].bEPBBAX  =
            (BYTE)(((stUsbHandle[i].iep_X_Buffer -
                     START_OF_USB_BUFFER) >> 3) & 0x00ff);

        // This is as far as the code will go
        tInputEndPointDescriptorBlock[edbIndex].bEPBBAY =
            (BYTE)(((stUsbHandle[i].iep_Y_Buffer -
                     START_OF_USB_BUFFER) >> 3) & 0x00ff);

       // The CPU turns off after this instruction or just goes to the program start if I step into this line.

Now how do I get past this?

  • Nate Melster said:
    it gets stuck in the USB_Reset function

    What, exactly, do you mean by, "gets stuck"?

    Where, exactly, does it, "get stuck"?

  • Nate Melster said:

    I started with the MSP-EXP430F5529 Experimental Board and got everything to work as needed with the code provided. Now for my particular project there are a lot more features we need the MSP430 to do and we wanted a smaller package. We designed a new board using the MSP430F5638, which also has the USB port and uses the same user guide as the MSP430F5529.

    I am trying to get the USB to work on this new board with the MSP430F5638. I imported the USB code over, but it fails. I can do the initial set up just fine, call the MassStorage function, show that the USB is connected and enabled, but it gets stuck in the USB_Reset function. In the function it sets up the IEPs like shown below.

    For start, you don't need to import anything anywere. Start with basic (original code) TI USB stack examples configured for MSP430F5529. Change device to MSP430F5638 and try to execute compiled code on target device (MSP430F5638). Take care about MSP430F5529 / MSP430F5638 max MCLK 25 Mhz / 20 MHz difference, and setup USB clock depending on used XT2 crystal. Debugging with breakponits something like this, can lead you to something else, not to source of the real problem. 

  • I started with the original code from the development board. I changed some clock settings in the descriptor.h to work with my board. I am using the MSP430F5638 with a 12 MHz crystal connected to XT2. Below are some of the changes made.

    #define USB_MCLK_FREQ 20000000                // MCLK frequency of MCU
    #define USB_PLL_XT        2                  // Defines which XT is used by the PLL (1=XT1, 2=XT2)
    #define USB_XT_FREQ       USBPLL_SETCLK_12_0 // Indicates the freq of the crystal on the oscillator indicated by USB_PLL_XT

    My program runs just fine until it sets up the IEPs in the USB_Reset function. Then it gets the message, "The stack pointer for stack 'Stack' is outside the stack range." After that the MCP430 CPU turns off.

    Any help is appreciated.

  • After plugging USB cable (with MSP430F5638) to PC, device is enumerated right, or not? Even your setup seems correct, if enumeration is failing this can be related to USB clock. Maybe you can force device to use XT2 for MCLK (and 12 MHz for running USB stack is still OK), and not 20 MHz DCO, just to be more clear. MSP430F5638 have more RAM (1C00-63FF) than MSP430F5529 (1C00-43FF) , and if problem is somehow related to RAM, this is strange.

  • Nate Melster said:
    Then it gets the message, "The stack pointer for stack 'Stack' is outside the stack range." After that the MCP430 CPU turns off.

    The message itself just means that the debugger detected the stack growing larger than configured.
    It is possible that the applicaiton really needs more stack space due to large number (or sizes) of local variables, or deep funciton nesting.

    It is also possible that the grown stack has grown so much that it reached the ram area used for global variables. If this happens, the stack will verwrite the globals (leading to unexpected program behaviour), and writing to the globals will overwrite the stack (leadign to undefined program execution, including crash and reset).

    Where does the stack point to in the error message (or in teh PCU register)? You may try to increse the stack setting so it matches this amount. If this gives you a linekr error, then you know that this was a stack overflow (or the stack pointer, whci is a simple processor register) has been unexpectedly modified by the code (maybe a s a result of  aprevious stack overflow, or by wiriting to an array, especially a local one, wiht an index out of bounds).

  • I changed the values of the Stack Size to 14224 and the Data16 Heap Size to 2160, which I think ore the maximum for this chip. This took care of the stack problem, so now it can run without having the CPU turn off. Thanks, I just had that set as the default.

    Now I can get to the mass storage loop just fine, but it is stuck in the ST_ENUM_IN_PROGRESS state. I thought it would be quick and get to the ST_ENUM_ACTIVE state, but it never seems to get there. I am hoping to eventually have the SD card look like a mass storage device to the computer. What could be causing this problem? I really appreciate your help. Thanks!

  • Nate Melster said:
    it is stuck in the ST_ENUM_IN_PROGRESS state ... What could be causing this problem?  

    It is either missing, or never getting whatever condition causes it to exit the ST_ENUM_IN_PROGRESS state!

    You're going to have to examine the source code and use the debugger to determine what, exactly is going on - and, thence, what needs to be fixed...

  • Nate Melster said:
    tack Size to 14224 [...]. This took care of the stack problem

    Well, it now allows you to figure out why that much is requires. It is an exorbitant amount. You should be able to run with 1/100 of that. So somewhere you're doing somethign really wrong. Now that the CPU doesn't crash anymore, you shoudl take a debugger and step through the code to figure out where the stack starts to explode - and why.
    Thsi is not a PC where you can say "Memory leak? Well, let's raise the official requirements from 4GB to 8GB and forget about it"

  • I can use probably 1/100 of that, but I just set it really big at first so I could make sure it will not get a stack overflow. The default was set very small, so I needed just a little more than that.

    My issue now must be with the driver. The program gets stuck at the ST_ENUM_IN_PROGRESS state and the computer has a warning saying it found an unknown USB device.

  • Nate Melster said:
    I just set it really big at first so I could make sure it will not get a stack overflow. [,,,] My issue now must be with the driver.


    You should try tro track down where the large stack usage comes from. Whatever caused this might also be responsible for your other problems and you might chasing shadows if you try to fix a different bug before you solved this riddle.

  • I have a question related to your question ...

    I just purchased the msp430f5529 experimenter's board as we require mass storage ability.  I notice that the board has the 5529 on it but it also has another usb chip, the tusb3410vf chip.  Why is this chip on the experimenter's board?

  • David Johns94798 said:
    Why is this chip on the experimenter's board?

    Likely, there's also an MSP430F1612 on the board. The two implement a JTAG interface for code uplaod and runtime debugging. Teh FET is controlled by teh debugger using a serial connection. Hence the TUSB3410 USB/ser converter

**Attention** This is a public forum