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.

RE: How to write and read FRAM memory

Other Parts Discussed in Thread: MSP430FR6989, MSPBSL, MSP430FR5739

Hi ,

I am using msp430FR6989 and to write in to FRAM , I am using Default example available  at TI web site

But my Problem Is, The program Compiles and run successfully (I am using CCS v6 IDE) But When I use Memory Browser Option to see the data at particular Memory Location , It shows only (FFFF) . So I my understanding the code is correct, But how to see the data that i Wrote in FRAM's Lcoation???

The Code I have used is as below.

#include <msp430.h>

void FRAMWrite(void);

unsigned char count = 0;
unsigned int *FRAM_write_ptr;
unsigned int data;

#define FRAM_TEST_START 0x5400

int main(void)
{
  WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT

    PM5CTL0 &= ~LOCKLPM5;                 /* low power mode disable  */

    /* Clock setting */
    FRCTL0 = FRCTLPW | NWAITS_7;          /* Frame wait state enable */
        /* Clock System Setup */
  CSCTL0_H = CSKEY >> 8;               /* Unlock CS registers */
    CSCTL1 = DCOFSEL_6;                  /*  Set DCO to 8MHz */
    CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;  /* Set SMCLK = MCLK = DCO */
    CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;     /* Set all dividers to 1 */
    CSCTL0_H = 0;                             /* Lock CS registers */

  // Configure GPIO
  P1OUT &= ~BIT0;                           // Clear P1.0 output latch for a defined power-on state
  P1DIR |= BIT0;                            // Set P1.0 to output direction

  // Disable the GPIO power-on default high-impedance mode to activate
  // previously configured port settings

  // Initialize dummy data
  data = 0x55;

  while(1)
  {
    data += 1;
    FRAM_write_ptr = (unsigned int *)FRAM_TEST_START;
    FRAMWrite();                            // Endless loop
    count++;
    if (count > 100)
    {
      P1OUT ^= 0x01;                        // Toggle LED to show 512K bytes
      count = 0;                            // ..have been written
      data = 0x11;
    }
  }
}

void FRAMWrite(void)
{
  unsigned int i=0;

  for ( i= 0; i<128; i++)
  {
    *FRAM_write_ptr++ = data;
    if (*FRAM_write_ptr == data)
        break;
  }
}

  • Hinesh Gohel said:
    But my Problem Is, The program Compiles and run successfully (I am using CCS v6 IDE) But When I use Memory Browser Option to see the data at particular Memory Location , It shows only (FFFF) . So I my understanding the code is correct, But how to see the data that i Wrote in FRAM's Lcoation???

    I just tried out the Register-based example that you referred to and it appears to work OK for me. As noted earlier in this thread, the way this example was written, the FRAM location being written to is erased (set back to 0xFFFF) every time you download the program to the device; that is, it gets erased whenever you start the "Debugger" within CCS.

    I'm not quite sure what your end goal is.

    • Do you just want to use the FRAM as extra "RAM"?
    • Or, do you want to use the FRAM as persistent data storage (values are always retained)?

    If your goal is the first one, then this example should work. (Though, I'm not a big fan of setting a pointer arbitrarily to FRAM. I'm sure my old computer science professor would recommend using actual scalar or aggregate data types.)

    If your goal is the second, you need to indicate to the build tools that you don't want your specific memory of interest (i.e. variables) cleared. This can be done with a #pragma or by editing the linker command file. Here's a couple of references that you may want to refer to:

    Take Care,
    Scott

  • Hi  ,

    I don't wanted to use FRAM as Just Extra 'RAM'. But I wanted to Store My Program in FRAM Space and It should not be erased.

    In That Program , I will Be receiving Data from UART, and that data I wanted to store on particular location in FRAM.

    I have tried with example and played around with that example for writing in to FRAM on particular location. But Not Succeeded.

    So How you suggest to store and write data over FRAM that Will be coming in Run-time.

    Thanks,

    Hinesh

  • In your source code, how did you declare the variable that you wish to write to. I'm just trying to make sure that A) You've placed this variable in FRAM, and B) That it is in a writable area of FRAM (See the MPU documentation for details on FRAM memory protection)

  • Hinesh Gohel said:
    So How you suggest to store and write data over FRAM that Will be coming in Run-time.

    Similar to James comment, it's important how you reference the location in FRAM. I'm not a big fan of the example that you referred to; personally, I do not like the idea of creating a pointer and hardcoding it to a specific hex address. While this can work, it leaves a lot of room for error. (I alluded to this in my earlier posting by saying "my college professor would have hated this".)

    It's better to declare a C variable, array, or data-structure to hold the value (or values) that you want to bring in and store. Not only does this allow the compiler to do the usual data validation, but you can then declare the variable to be "persistent". For example, for a global variable called "count":

    #pragma PERSISTENT ( count )
    uint16_t count = 0;
    

    creates the variable "count" and tells the code generation tools to place it in "persistent" memory; that is, the variable will be placed in FRAM, which is a persistent type of memory. Handled this way, your code can read and write the variable just like it's located in RAM, but its value will be retained even if power is removed from the device.

    Using the "pointer" method not only removes standard compiler validation, but you have to be absolutely sure that you don't accidentally place the data in the same location where your code is linked. This isn't a concern, though, when using the method shown above.

    While not normally a concern when you are just trying to get your code working for the first time, in a real world program you will also want to make use of the MPU (memory protection unit). This peripheral helps to prevent you from accidentally overwriting your program memory with data. Thankfully, when using the variable declaration shown above, the MPU can be automatically configured by CCS - you just need to enable it.

    Once again, both of these topics are covered in the app note, as well as the workshop chapter/example, mentioned in my previous posting.

    I hope this helps,
    Scott

  • Hi James,

    Thanks for looking by,


    I Wanted to simple do the file write operation that can be performed in normal flash read write to particular FRAM Location. Erase is not needed in FRAM.

    Thanks,


    Hinesh

  • Hi ,

    Yes It helped, And I wanted to reference my FRAM as a storage like normal flash, Where on Particular location we can write (/read) the data.

    FRAM don't need erase as normal flash. so it's nice. And in storage, Particularly for boot-loader application , where at time of reset, it will boot up and will write data on particular location on fram coming from UART.

    Please ask if any more information is needed.

    Thanks,
    Hinesh
  • Hinesh Gohel said:
    Particularly for boot-loader application

    Maybe I was misunderstanding your question. Are you asking how to perform a firmware upgrade? That is, bootload a new program into your FRAM device via the UART?

    If that's the case, there is support for that using the BSL bootloader functionality which is documented in this PDF.


    Take Care,
    Scott

  • Hi ,

    let's say I am not using BSL invocation method for Boot loader. But I Am writing MY own Program that Will on reset starts first and have capability for UART that starts Writing on FRAM from Particular location. I am facing Problem in Writing data received from UART.

    on reset my program will firstboot, and that will have UART , So On upgrade or data receive, It will start writing Data to particular location in FRAM. After finish It will reset again and will jump to new program.

    Thats functionality I am implementing , checking that ,the data received over UART should write on FRAM location.

    Please ask if more information needed for suggestion.

    Thanks,
    Hinesh
  • That should work just fine so long as you are certain that the MPU isn't set to write-protect the memory to which you are attempting to write.

  • Hinesh Gohel said:
    ... I Am writing MY own Program that Will on reset starts first and have capability for UART that starts Writing on FRAM from Particular location. ...

    There is no problem there.

    The potential problems are cause by BSL, Debugger, Browser, end other "tools" you may try to use. They all have hidden "features" that could mislead you. These "features" are usually enabled by "default" -- meaning that it is your "fault" :)

  • Hi Hinesh,

    You can do a software invocation of the BSL instead of a hardware invocation - see the FR5xx BSL user's guide www.ti.com/lit/pdf/slau550 section 2.3.1.1 Starting the BSL from an External Software Application.

    Or you could use something like MSPBoot as a guide for doing something completely custom: www.ti.com/.../slaa600

    Regards,
    Katie

  • old_cow_yellow said:

    Hinesh Gohel
    ... I Am writing MY own Program that Will on reset starts first and have capability for UART that starts Writing on FRAM from Particular location. ...

    There is no problem there.

    The potential problems are cause by BSL, Debugger, Browser, end other "tools" you may try to use. They all have hidden "features" that could mislead you. These "features" are usually enabled by "default" -- meaning that it is your "fault" :)

    Hi old_cow_yellow,

    If you can point to fault it would be great. :-)

  • Katie Pier said:
    Hi Hinesh,

    You can do a software invocation of the BSL instead of a hardware invocation - see the FR5xx BSL user's guide www.ti.com/.../lsau550 section 2.3.1.1 Starting the BSL from an External Software Application.

    Or you could use something like MSPBoot as a guide for doing something completely custom: www.ti.com/.../slaa600

    I Have tried BSL invocation by software , going through the command given there. If have hex file that i am transmitting over uart to msp430fr6989, but it is not receiving on Controller.

    I will look more in custom suggestions And Will let you know about problems.

    Any reference code That can you suggest ?

    Thanks,

    Hinesh

  • Hi Hinesh,

    For using the built in BSL with software invocation, you need to make sure that the data is being sent over in the correct format in data packets with the correct sequence of commands - you will want to see www.ti.com/.../slau319 and also maybe the BSL Scripter code would be of some use to you software-dl.ti.com/.../index_FDS.html It includes source code for the host side (on a PC) but that would show using the same protocol/format that you need to use the TI BSL.

    If you want to go the custom route, the app note I mentioned before www.ti.com/.../slaa600 also includes source code software-dl.ti.com/.../index_FDS.html
    These resources are all available on the MSPBSL page.

    Regards,
    Katie
  • Hi ,

    I have gone through the custom bsl link, But it only supports till msp430fr5739, And I am having msp430fr6989.

    is it usable for the same controller too( with controller specific modifications)??

    Thanks,
    Hinesh
  • Hinesh,

    The custom BSL MSPBoot only provides examples for a few of the different MSPs, but the method that it uses can be ported/adapted to any MSP430 device if you make the correct modifications. One concern with MSP430FR6989 is that it has a large memory model, with 20-bit addresses. Currently, our MSPBoot examples only show how to do 16-bit addresses - therefore further modifications will be needed. If you search the forums though, there are others here that have done this for different MSP430 devices already: e2e.ti.com/.../1402558 There are some other threads linked there as well.

    I still think that in general, simply adjusting your host to send the data over in the correct packet format for the built-in BSL based on the documentation in www.ti.com/.../slau550 packet format, and following the format used by BSLScripter and others, would be easier than doing this MSP-Boot port to 20-bit addresses, but it is up to you to decide.

    Regards,
    Katie

**Attention** This is a public forum