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.

Accessing to SRAM on MSP430FR5969

Other Parts Discussed in Thread: MSP430FR5969

Hi

I am measuring the accessing time for SRAM on MSP430FR5969. According to the datasheet, the address is from 001C00h-0023FFh. So I use this code to write to SRAM.

#define OUTPIN BIT5

/*
 * main.c
 */
void SRAM_write(void);
unsigned int data=0x11;

#define SRAM_TEST_START 0x1D00

int main(void) {
	int i=5;
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    P1OUT &= ~OUTPIN;
    P1DIR |= OUTPIN;
    PM5CTL0 &= ~LOCKLPM5;
    while(1)
    {
    	for (i=0;i<200;i++)
    		SRAM_write();
    	P1OUT ^= OUTPIN;
    }
}

void SRAM_write(void)
{
	int i;
	SRAM_ptr_write = (unsigned int *)SRAM_TEST_START;
	for(i=0;i<256;i++)
	{
		*SRAM_ptr_write=data;
		SRAM_ptr_write++;
	}
	
}

But the accessing time (when measuring, it's the time writing to ram 256*200 times)  is equal to the FRAM, which means I am accessing to the FRAM.

Then I use the following code, using a vector instead of the pointer. And the time is 3/4 of previous time.

#define OUTPIN BIT5

/*
 * main.c
 */
void SRAM_write(void);
unsigned int data=0x11;

#pragma DATA_SECTION(SRAM_ptr_write, ".sram")
volatile unsigned int SRAM_ptr_write[257];

int main(void) {
	int i=5;
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    P1OUT &= ~OUTPIN;
    P1DIR |= OUTPIN;
    PM5CTL0 &= ~LOCKLPM5;
    while(1)
    {
    	//P1OUT ^= OUTPIN;
    	for (i=0;i<200;i++)
    		SRAM_write();
    	P1OUT ^= OUTPIN;
    }
}

void SRAM_write(void)
{
	int i;
	for(i=0;i<256;i++)
	{
		SRAM_ptr_write[i]=data;
	}
	
}

So what's the problem with my first code? Why can't I access to the SRAM using the pointer?

Thanks!

Yin

  • What is the type of SRAM_ptr_write in the first program?
  • Sorry I delete this line by accident, it's int*.
    unsigned int * SRAM_ptr_write;
  • Probably different code generated by the compiler. Optimization settings might make a difference.

    To be sure, show the assembler output generated by the compiler for both loops.

  • In the first code, the compiler needs to increment two independent variables, i and the pointer. In the second, it can keep the pointer constant and directly use i as the offset (which doesn't take additional time/code due to the indexed addressing mode).
    In the second code, the compiler may even inline the whole function call, as the code is smaller, further speeding up the execution.

    SRAM and FRAM are accessed by the CPU likewise. The only difference is the address. The CPU doesn't know about FRAM or SRAM or registers. All are handled the same way: The CPU asks for data on the address bus, and gets data from the data bus in return. From whatever physical media it may come. Hardware registers or FRAM may add waitstates, if required, SRAM won't, but that's also transparent.

    if your CPU clock is no higher than 8MHz, then FRAM will be as fast as SRAM. For both, reading and writing.

**Attention** This is a public forum