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.

Writing in flash- program code protection

Hello all,

In the example of the flash writing operation for F550x family we can find code below.


void main(void)
{
  unsigned long * Flash_ptrD;               // Initialize Flash pointer Seg D
  unsigned long value;
  WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT

  Flash_ptrD = (unsigned long *) 0x1800;    // Initialize Flash pointer
  value = 0x12345678;                       // Initialize Value
  FCTL3 = FWKEY;                            // Clear Lock bit
  FCTL1 = FWKEY+ERASE;                      // Set Erase bit
  *Flash_ptrD = 0;                          // Dummy write to erase Flash seg
  FCTL1 = FWKEY+BLKWRT;                     // Enable long-word write
  *Flash_ptrD = value;                      // Write to Flash
  FCTL1 = FWKEY;                            // Clear WRT bit
  FCTL3 = FWKEY+LOCK;                       // Set LOCK bit
  while(1);                                 // Loop forever, SET BREAKPOINT HERE
}

Simple application.

There are two things I want to know.

1. Is compiler smart enough to don' t store program memory at 0x1800 address?

2. Is it recommended to use any range of addresses?

Best regards,

Mikolaj

  • Mikolaj Filar said:
    Is compiler smart enough to don' t store program memory at 0x1800 address?

    The compile rdoesn't store anythign anywhere. It jus tgenerates relocatable code. th linker puts the pieces together and assigns the file address locations. For this purpose, eery MSP has a linker command file that contains information abotu hwere there is ram or flash and what to put where.

    This command file usually (if not altered for some reason by teh user) defines info flash as 'there but not used for anything'. Code and init vlaues for variables are stored in main memory.

**Attention** This is a public forum