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.

MSP430FR5994: Writing does not take!

Part Number: MSP430FR5994

Tool/software:

I  have problem writing to FRAM2, no errors or warnings, but the write don't take.
I minimized the test-code to this, the read works, but the writing does nothing.

Please advice!

lnk_msp430fr5994.cmd:

...

    } > 0x4000

    .storage          : {}  > FRAM2         /* Storage, remove the FRAM2 from other parts of the file. */

    .cinit            : {}  > FRAM          /* Initialization tables             */
...

main.c:

#pragma DATA_SECTION (fram2, ".storage")

unsigned char fram2[10];
void main(void)
{
   unsigned char aa, index;
   while(true)
   {
      for(index=0;index<10;index++)
      {
         aa = __data20_read_char( (unsigned long) ( fram2+index ) );
         aa = index;
         __data20_write_char( (unsigned long) ( fram2+index ), aa); // does nothing
         aa = __data20_read_char( (unsigned long) ( fram2+index ) );
         
         __delay_cycles(100);
      }
   }
}
  • And of cource large code and data_model.

  • I don't see where you write-enable FRAM. For your use-case (high-FRAM) you would do this using the MPU.

    A quick experiment would be to just disable the MPU (un-check Build Settings->General->MPU[tab]->Enable MPU). This write-enables all of FRAM.

    As you suppose, that method isn't so good long term. You can change the RWX settings on FRAM regions using the MPU[tab] (seen above). The memory layout is in the datasheet.

    You can also create writable FRAM using "#pragma PERSISTENT()". For this feature, the compiler/linker do the MPU work for you, but the .ti.persistent section is put in low FRAM, and so is limited in size. This is demonstrated in example msp430fr599x_framwrite.c here:

    https://dev.ti.com/tirex/explore/node?node=A__AAkb-Bq6Hd25qRBlFc08Zw__msp430ware__IOGqZri__LATEST

    [Edit: Fixed typo.]

  • This did the trick!!

    #pragma
    PERSISTENT (fram2)
    #pragma location=0x10000
    unsigned char fram2[0x33F00] = {0x55};

    void main(void)
    {
       unsigned char aa;
       int index;
       WDTCTL = WDTPW | WDTHOLD;               // Stop WDT

       // MPU
       MPUCTL0 = MPUPW; // Write PWD to access MPU registers
       // Segment 1 – Allows read and write only
       // Segment 2 – Allows read only
       // Segment 3 – Allows read and execute onl
       MPUSEGB1 = 0x0480; // B1 = 0x4800; B2 = 0x10000
       MPUSEGB2 = 0x1000; // Borders are assigned to segments
       MPUSAM = (MPUSEG1RE |  // Read on Main Memory Segment 1 is allowed
                 MPUSEG1WE |  // Write on Main Memory Segment 1 is allowed
                 MPUSEG1XE |  // Execute on Main Memory Segment 1 is allowed
                 MPUSEG2RE |  // Read on Main Memory Segment 2 is allowed
                 MPUSEG2WE |  // Write on Main Memory Segment 2 is allowed
                 MPUSEG2XE |  // Execute on Main Memory Segment 2 is allowed
                 MPUSEG3RE |  // Read on Main Memory Segment 3 is allowed
                 MPUSEG3WE |  // Write on Main Memory Segment 3 is allowed
                 MPUSEG3XE);  // Execute code on Main Memory Segment 3 is allowed
       MPUCTL0 = MPUPW | MPUENA | MPUSEGIE; // Enable MPU protection
       // MPU registers locked until BOR

       while(true)
       {
          for(index=0;index<0x33F00;index++)
          {
             aa = __data20_read_char( (unsigned long) ( fram2+index ) );
             aa = index;
             __data20_write_char( (unsigned long) ( fram2+index ), aa);
             aa = __data20_read_char( (unsigned long) ( fram2+index ) );
             
             __delay_cycles(100);
          }
       }
    }
  • I'm glad you got it working.

    >           MPUSEG2WE |  // Write on Main Memory Segment 2 is allowed

    Segment 2 is (presumably) where your code is. You probably don't want that writable.   
  • That might the correct.

    I'll look into it when I manage to get everything else working.

    Thank you for the observation.

**Attention** This is a public forum