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.

MSP430F2274 write to flash example works with simulator but not with MSP-FET430UIF emulator

Hi,

I run the msp430x22x4_flashwrite_01.c on IAR simulator (put the break-point where needed) and see the values in the memory windows change as expected.

But when I do the same with the MSP-FET430UIF emulator all numbers remain 0xFF no matter what I do.

Any idea why ???

Best regards,

Danny

  • The simulator doesn't care for physics. If you program the flash controller, fine, but if you then write to 'simulated flash, it is a write whcih will succeed, even if you programmed the flash controller the wrong way. Because the simulated flash is simple ram.

    I don't know this example, but chances are that it will run only on the MSP it was written for, not on every MSP.
    Also, dependign on where you put your breakpoint, it may interfere with the flash write process, and the debugger turns iinto a bugger. There are some errata listed in almost every MSPs errata sheet regarding the debugger. Including debugger access durign a flash write.

  • The example used is the "msp430x22x4_flashwrite_01.c" example downloaded from TI's web site.
    It is for the msp430x22x4. I use MSP430F2274 so I guess it should work.

    Is there anything special I need to set in the project options or emulator options when I program the internal flash?

    The code:

    //******************************************************************************
    // MSP430F22x4 Demo - Flash In-System Programming, Copy SegC to SegD
    //
    // Description: This program first erases flash seg C, then it increments all
    // values in seg C, then it erases seg D, then copies seg C to seg D.
    // ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
    // //* Set Breakpoint on NOP in the Mainloop to avoid Stressing Flash *//
    //
    // MSP430F22x4
    // -----------------
    // /|\| XIN|-
    // | | |
    // --|RST XOUT|-
    // | |
    //
    // A. Dannenberg
    // Texas Instruments Inc.
    // December 2006
    // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.41A
    //******************************************************************************
    #include "msp430x22x4.h"

    char value; // 8-bit value to write to seg C

    // Function prototypes
    void write_SegC(char value);
    void copy_C2D(void);

    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
    DCOCTL = CALDCO_1MHZ;
    FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
    value = 0; // initialize value

    while(1) // Repeat forever
    {
    write_SegC(value++); // Write segment C, increment value
    copy_C2D(); // Copy segment C to D
    __no_operation(); // SET BREAKPOINT HERE
    }
    }

    void write_SegC(char value)
    {
    char *Flash_ptr; // Flash pointer
    unsigned int i;

    Flash_ptr = (char *)0x1040; // Initialize Flash pointer
    FCTL3 = FWKEY; // Clear Lock bit
    FCTL1 = FWKEY + ERASE; // Set Erase bit
    *Flash_ptr = 0; // Dummy write to erase Flash seg

    FCTL1 = FWKEY + WRT; // Set WRT bit for write operation

    for (i = 0; i < 64; i++)
    {
    *Flash_ptr++ = value; // Write value to flash
    }

    FCTL1 = FWKEY; // Clear WRT bit
    FCTL3 = FWKEY + LOCK; // Set LOCK bit
    }

    void copy_C2D(void)
    {
    char *Flash_ptrC; // Segment C pointer
    char *Flash_ptrD; // Segment D pointer
    unsigned int i;

    Flash_ptrC = (char *)0x1040; // Initialize Flash segment C ptr
    Flash_ptrD = (char *)0x1000; // Initialize Flash segment D ptr
    FCTL3 = FWKEY; // Clear Lock bit
    FCTL1 = FWKEY + ERASE; // Set Erase bit
    *Flash_ptrD = 0; // Dummy write to erase Flash seg D
    FCTL1 = FWKEY + WRT; // Set WRT bit for write operation

    for (i = 0; i < 64; i++)
    {
    *Flash_ptrD++ = *Flash_ptrC++; // copy value segment C to seg D
    }

    FCTL1 = FWKEY; // Clear WRT bit
    FCTL3 = FWKEY + LOCK; // Set LOCK bit
    }
  • If it is the original sample code, it shoudl work.

    But what about the supply voiltage? Flashing requires a higher minimum voltage than plain program execution. The absolute minimum is 2.2V while the MSP itself would run on 1.8V. Also up to 7mA extra current are required during erase or write.

    The project settings or the simulator or debugger options don't have any influence on the program execution. Except the voltage setting, if you supply your MSP from a FET430UIF.

  • Hi,

    I found what the problem was: in IAR
    project --> options --> FET Debugger --> Download --> Flash erase, the default option is "Erase main and information flash".
    This erases the factory calibration DCO information from information flash segment A.

    The following code lines loaded 0xFF to BCSCTL1 and DCOCTL and made the program go berserk:

    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;
    Luckily TI has an example (thanks to TI tech support for helping me on that) msp430x22x4_dco_flashcal.c 
    that re-calibrates and programs the data back to information flash segment A in reference to a 32.768 KHz
    crystal. After running it everything started working as expected.
    So if you need to code in system programming of the information flash - 
    use the "Retain unchanged memory" option to avoid erasing this segment.
    Best regards,
    Danny
     

     

  • DannyEllen said:
    he following code lines loaded 0xFF to BCSCTL1 and DCOCTL and made the program go berserk:

    Ah. Normally, the TI code that uses the calibraiton constants has a line like "if (CALDCO:1MHZ == 0xff || CALBC1_1MHz == 0xff) while(1);". it lets the CPU hang if the constants have been erased. So I didn't consider this as teh fault reason.
    Well, the only constant thing in universe is the change.

  • Jens-Michael Gross said:

    he following code lines loaded 0xFF to BCSCTL1 and DCOCTL and made the program go berserk:

    Ah. Normally, the TI code that uses the calibraiton constants has a line like "if (CALDCO:1MHZ == 0xff || CALBC1_1MHz == 0xff) while(1);". it lets the CPU hang if the constants have been erased. So I didn't consider this as teh fault reason.
    Well, the only constant thing in universe is the change.

    [/quote]

     Hi Jens, remember my recent post about example code? ;)

     Regards

     Roberto

**Attention** This is a public forum