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.

MSP-EXP430F5438: Flash bank erase issue

Part Number: MSP-EXP430F5438

Hello,

I'm currently working on a project where we use TI Dual-Mode Bluetooth® Stack (v1.5 R2) on a MSP430 (www.ti.com/.../CC256XMSPBTBLESW).

For functional operation of the device, we need to erase a complete bank of flash sometimes. Numerous times I have seen unwanted behavior (device reset or ending up at address 0x4) in my IDE while debugging. Since I couldn't find / debug the issue in my project I tried building some simple application to test the Flash bank erase function on the MSP-EXP430F5438 development board.

The flash bank erase function is sourced from the MSPWare library (www.ti.com/.../MSPWare), and the application used is the default SPPDemo from the bluetooth stack. I added just a couple of code lines (mainly I embedded the flash bank erase function, to ease rebuilding process by anyone) to test the flash bank erase function. The attached file (SPPDemo.c) should be replaced in the SPPDemo project and will build under IAR Embedded workbench 7.11.1 (file location will be something like: [bluetooth stack intallation folder]\MSP430_Experimentor\Samples\SPPDemo\SPPDemo.c)

When the application is run, you have to type either "client" or "server" to enter one of the menu's. After that, the bank erase can be tested by typing "flash 1" And it will show up with "Flash Tested 1 times ok". To verify the operation, the test is run with 100 as argument ("flash 100"), So the flash bank should be erased 100 times. Although we can expect from this test that the flash bank erase function is run 100 times and shows up with "Flash Tested 100 times ok", the device resets and starts over again.

Please help me out with this issue, since I cannot find the root of this issue.

Regards and thanks in advance,
Leon

SPPDemo.c

  • Hi Leon,

    Can you use an oscilloscope to measure VCC on the board during the flash erase test? It is possible that repeatedly calling the FlashEraseBank function causes VCC to drop low enough to cause a reset.

    You can also add the following code structure toward the beginning of your code main function and add breakpoints during debugging to test what exactly is causing the reset:

        switch(__even_in_range(SYSRSTIV, SYSRSTIV_PMMKEY)) {
            case SYSRSTIV_NONE:        /* No interrupt pending */
                _no_operation();
                break;
            case SYSRSTIV_BOR:         /* SYSRSTIV : BOR */
                _no_operation();
                break;
            case SYSRSTIV_RSTNMI:      /* SYSRSTIV : RST/NMI */
                _no_operation();
                break;
            case SYSRSTIV_DOBOR:       /* SYSRSTIV : Do BOR */
                _no_operation();
                break;
            case SYSRSTIV_LPM5WU:      /* SYSRSTIV : Port LPM5 Wake Up */
                _no_operation();
                break;
            case SYSRSTIV_SECYV:       /* SYSRSTIV : Security violation */
                _no_operation();
                break;
            case SYSRSTIV_SVSL:         /* SYSRSTIV : SVSL */
                _no_operation();
                break;
            case SYSRSTIV_SVSH:         /* SYSRSTIV : SVSH */
                _no_operation();
                break;
            case SYSRSTIV_SVML_OVP:     /* SYSRSTIV : SVML_OVP */
                _no_operation();
                break;
            case SYSRSTIV_SVMH_OVP:     /* SYSRSTIV : SVMH_OVP */
                _no_operation();
                break;
            case SYSRSTIV_DOPOR:        /* SYSRSTIV : Do POR */
                _no_operation();
                break;
            case SYSRSTIV_WDTTO:        /* SYSRSTIV : WDT Time out */
                _no_operation();
                break;
            case SYSRSTIV_WDTKEY:       /* SYSRSTIV : WDTKEY violation */
                _no_operation();
                break;
            case SYSRSTIV_KEYV:         /* SYSRSTIV : Flash Key violation */
                _no_operation();
                break;
            case SYSRSTIV_PLLUL:        /* SYSRSTIV : PLL unlock */
                _no_operation();
                break;
            case SYSRSTIV_PERF:         /* SYSRSTIV : peripheral/config area fetch */
                _no_operation();
                break;
            case SYSRSTIV_PMMKEY:       /* SYSRSTIV : PMMKEY violation */
                _no_operation();
                break;
            default:   break;
        }

    Regards,

    Ryan

  • Hello Ryan,

    Thanks for your reply. You have to know that I have spend quite some time finding the root cause of this issue. Voltage has been one the items I focused on as well. I have measured this on my own target board (running at 1.9V) and the voltage wasn't dropping at all. Since debugging these issues with fellow developers is difficult when using own hardware, I switched to a "know" development board.

    I didn't measure the board voltage on this development bard, but since the voltage is much higher (3.3v) and the margin to the minimum voltage is much higher than my own board, the voltage source is no longer a suspect to me.

    Your suggestion to catch the NMI triggered interrupts is very helpful indeed. When I started this issue, I have used UNMI as well as SNMI to find the reset source. It amazed me however, to see that I had different reset sources triggered, depending on the compilation of only slightly different sources. Sometimes, the debugger ends up (when paused) at 0x4, without even passing or triggering the SNMI / UNMI interrupt service routines.

    Any other suggestions are welcome
  • Hi Leon,

    Have you had a chance to look at the F5438 Erratasheet to see if one of the known issues resembles the behavior you're seeing? One of the Flash Errata Numbers may be affecting the performance, or if the behavior only appears when the F5438 is connected to the debugger, one of the JTAG ones might be a cause.

    Regards,

    Ryan

  • Hi Ryan,

    I'm aware of the errata's on the flash controller. The issue however was discovered on my own board, populated with a MSP43F5359, which doesn't seem to have this errata. Further more, I have performed the same test without console interaction, but with a GPIO pin toggling on a looped flash bank erase. The GPIO was connected to my oscilloscope to monitor the flash bank erase function.

    The GPIO was introduced so I could disconnect my debugger. The test showed the same result. For a random number of times, it runs ok. And then, there's a total freeze / hang-up.

    regards,
    Leon
  • Hi Leon,

    Has the .cmd file (linker file) for the project been modified to prevent any code from being unexpectedly placed in the Flash bank being erased? You may also want to disable interrupts before erasing the flash bank and re-enable them afterwards in your FlashEraseBank function to be safe.

    Regards,
    Ryan

  • Hi Ryan,

    Yes, my normal application linker file is modified, so application code cannot be placed into this section. Although MSP430 user guide states "Interrupts are automatically disabled during any flash operation." I disabled them myself and reenabled it, as described by you, but it doesn't change the situation.

    As desribed in my first question, I have used all standard components: development board, bluetooth stack, demo application and mspware library function. To speed-up the root cause analysis, it might be the best option to check if you can obtain yourself such a deveploment board. This should be possible as Ti Employee :-), or maybe you know someone in your team who can perform this test for you.

    Hope to hear form you soon.
    Regards,
    Leon
  • Hi Leon,

    I tracked down an F5438 Experimenter Board and will try to replicate what you're seeing today. Can you please post your updated linker file and any other files that were updated to work with the flash test?

    Thanks,
    Ryan
  • Hi Ryan,

    The test you can perform with just the default application from the bluetooth stack (only sppdemo.c is modified). Everything else is just default. You can verify the memory bank which is to be erased, by memory lookup, map file etc that there's no application code placed in this last flash bank. For this test I did not change the linker file, but the issue is exactly the same.

    Regards,
    Leon

    p.s. good to hear that you already have tracked down the experimentor board.
  • Hi Leon,

    I haven't had luck replicating the behavior you're seeing so far. Can you please post the following register values during code execution just before the flash test is run:
    PMMCTL0
    SVSMHCTL
    SVSMLCTL
    PMMRIE

    Can you create a simplified application that only runs your FlashEraseBank function after stopping the watchdog timer without the Bluetooth stack and see if the device still resets?

    Thanks,
    Ryan
  • Hi Ryan,

    The register values have to wait, since I'm currently at another location, but the key to this issue is, that it has something to do with this stack or at least placement of code in flash. (Although I have no clue why). I have tried to build a simple application with just the bank erase, without stack and I was also not able to replicate the behavior.

    I thought you had the bluetooth module as well together with the development board. But maybe you can arrange this one as well, since it is necessary to run the bluetooth stack.

    Hope to hear from you soon,
    regards,
    Leon
  • Hi Ryan,

    You can try to run the attached code. It doesn't need the bluetooth module, but keeps the stack in place (altough I do not like to return a valid bluetooth stack id, while it isn't valid). It allows you to enter the console and type "server" and than e.g. "flash 100". It ends up with the same result. So you only have to install the bluetooth stack as mentioned and replace the SPPDemo.c file in the samples directory with this one. Open the IAR project, build and go.

    Regards,

    Leon

    3173.SPPDemo.c

  • Hi Leon,

    I was able to replicate the behavior you're seeing thanks to the code and test setup you provided. After testing many possible root causes, I think the issue stems from instability on the voltage supply line caused by the power requirements needed to repeatedly erase a flash bank. As stated in the MSP430F5438A Datasheet, up to 11 mA is needed during a Flash bank erase which can cause noise on DVCC that could erroneously set the SVM low-side flag.

    According to Errata Flash37 having the SVM low-side flag set may cause a corrupted flash read. Based on reading through the MSP430x5xx and MSP430x6xx Family User's Guide, it seems like fetching the corrupted instruction of 0x3FFF from Flash is common under these circumstances because it will be returned from a corrupted Flash read or trying to access an invalid memory address. 0x3FFF corresponds to a jump command to address 0x4 which itself contains 0x3FFF, causing an infinite loop. If the noise on DVCC is severe enough, it could generate the resets that you saw as well. 

    Implementing code before and after the flash bank erase to make sure that the supply voltage is stabilized seems to have solved the problem. The updated code is attached. Please test it in your system and let me know if it corrects the behavior.

    Thanks,

    Ryan

    0250.SPPDemo.c

  • Ryan,

    Thanks for the code you sent me. I tested the code on the development board, and it works fine. So the next step I made is replacing the code in my own platform with this one, and it did not work. It still crashes as before.

    So I went back to your code running on the development board and did some simple empirical testing. Now based on your voltage suspect, the entry and exit code of the flash erase should cover the voltage issue. However the behavior of this phenomena is really strange (as you have probably already seen by the tests you performed yourself). During testing some small modification were made to your code and the code onto the development board fails again.

    I really don't understand why, but maybe you can help me out. I attached the modifications I made in the code, and surprisingly enough, I only added some "nop" instructions which normally do not cause any harm. In my opinion, this issue tends to be something out of normal behavior of the MSP.

    Please let me know what you think about it and maybe there's still a good explanation for the behavior.

    Regards,
    Leon

    4544.SPPDemo.c

  •  Leon,

    When I retested the code you sent, I did indeed see that it was resetting again. This is possibly still explained by fetching corrupted Flash instructions during code execution because the code checking to see if the voltage supply is stabilized is still executed from Flash memory, so perhaps the code I sent was not a fix for all cases.

    One more thing to try would be to run the Flash erase function from RAM to ensure the code cannot fetch a corrupted instruction from Flash during the bank erase. Attached is code that copies the bank erase function from Flash to RAM and executes it from RAM. There is also an updated linker file which allocates space for the function at the beginning addresses of Flash and RAM and moves the rest of the code to be stored at addresses above it. The updated parts of the file are toward the bottom in the Code and Constant Data sections.

    More examples for running code from RAM can be found on this e2e thread.

    If this doesn't correct the behavior in your system, I will begin looking into other root causes.

    Regards,

    Ryan

    8055.SPPDemo.c

    lnk430f5438a.xcl

  • Hi Ryan,

    I tested the code you send me. First I made a linker file for IAR, because the one which is attached to your post is a linker file from CCS as I am not mistaking. Copying code to RAM for execution, I have never used before, but seems to work fine, without crashing.

    The code I have adopted to run at my own platform, and surprisingly enough, it seems to run fine as well. So we have a big win here :-). Thanks for the effort so far.

    What keeps me thinking however, why didn't I find any of this in the user manual or maybe in the MSP Ware library, since it doesn't dictate the "FlashCtl_eraseBank" function to reside in RAM ? So can you tell me in some more detail, what is the specific reasons for executing the code from RAM and what is the cause of the MSP fetching corrupted Flash instructions?

    From my opinion, the code should be able to run from flash as well. Maybe you can tell me what I am missing?

    To complete the post, I attached the code which I used for testing. I went back to the original situation, with the only difference that the code is copied to RAM. Further more, the IAR linker file is attached for completeness of this post.

    Hope to hear from you soon,
    Regards,Leon

    3288.SPPDemo.c

    lnk430f5438aRamCopy.zip

  • Hi Leon,

    I'm glad to hear the code fixed the issue! I accidentally posted the incorrect linker file in my previous post, and it is now edited to contain the correct linker file for IAR.

    The behavior you are seeing seems like it is well explained by errata Flash34 which states that a concurrent flash read during a bank erase fails and is fixed by moving code execution to RAM. However this errata applies to the F5438A and not the F5359 in your system. The F5359 architecture has had a fix implemented to eliminate this errata.

    We are now working to replicate the issue on an F5359 to make sure that it is the same issue appearing, and I will provide details as we make more progress.

    Regards,
    Ryan
  • Hello Ryan,

    Thanks for the effort you put into this issue. I marked your post, placing code into RAM as the resolution for the issue. Good to hear that you are looking into the issue for the MSP430F5359 as well.

    For the MSP430F5359 setup, it might be valuable to know that I am running the MSP at 1.8 V. Although in my tests, trying to solve the issue, I also raised the board voltage to 2.0V (could get higher due to connected components).

    Keep me in touch indeed with the progress you make. This is much appreciated

    Regards,
    Leon

**Attention** This is a public forum