AnsweredAssumed Answered

How RAM and Flash actually work?

Question asked by Dimitris Sideris on Mar 22, 2017
Latest reply on Mar 23, 2017 by Carlos_Mendoza

I am trying to understand the procedure memory handling in LPC mcus.

 

I am working with an LPCxpresso 4367.

 

I wanted to store a buffer in flash I tested this code:

 

#include "board.h"

 

#define FLASHA_BASE_ADDR 0x1A000000
static int *fb  = (int *)FLASHA_BASE_ADDR;

 

int main(void)
{
    SystemCoreClockUpdate();
    Board_Init();
    int arsize = 10;

 

    for (int i = 0; i < arsize; i++)
        {
        fb[i] = 0xA;
      }

 

    while (1) {
        __WFI();
    }
}

 

And after adding -print-memory-usage linker option i get this result:


MFlashA512:        7984 B       512 KB      1.52%
RamLoc32:          352 B        32 KB         1.07%

 

I went through normally without declaring specific address to fb buffer and i tested this code:

 

#include "board.h"

#define FLASHA_BASE_ADDR 0x1A000000

int main(void)
{
    SystemCoreClockUpdate();
    Board_Init();
    int arsize = 10;
    int fb[arsize];

    for (int i = 0; i < arsize; i++)
        {
        fb[i] = 0xA;
      }


    while (1) {
        __WFI();
    }
}


MFlashA512:        8044 B       512 KB     1.53%
RamLoc32:          348 B        32 KB       1.06%

 

 

Can some explain what is going on?

When i put fb in flash, flash occupied space is less.

When i put fb in ram, ram occupied space is less.

Outcomes