Is it possible to store 8 bit character to 32 bit Internal Data Flash in the Microcontroller by just using only 8 bit of space for each bytes?,by using a combination of 4 bytes which can be also recovered as individual bytes later. I'm using Nuc240 (ARM-M0) Microcontoller with 32 bit Data Flash and 512 bytes erase limit,read write limit is 32 bit.
Please explain a code template if possible.

  • \$\begingroup\$ Do you mean store them there in run-time or at link-time? \$\endgroup\$
    – Lundin
    Commented Dec 12, 2016 at 7:16
  • \$\begingroup\$ During Link-time \$\endgroup\$ Commented Dec 12, 2016 at 7:24

2 Answers 2


Yes, by either array or structure.

char memory [4] = { 'a', 'b', 'c', 'd' };  // Uses 4-bytes (32-bits)

// memory [0] = 'a';
// memory [1] = 'b';
// memory [2] = 'c';
// memory [3] = 'd';

// ... store 'memory' in internal flash memory ...


typedef struct
    char byte_0;
    char byte_1;
    char byte_2;
    char byte_3;
} memory_t;

memory_t memory; // Uses 4-bytes (32-bits );

memory.byte_0 = 'a';
memory.byte_1 = 'b';
memory.byte_2 = 'c';
memory.byte_3 = 'd';

// ... store 'memory' in internal flash memory ...
  • 1
    \$\begingroup\$ I think I can store the array you defined at first directly into the memory by using the array name , and also read back with an array of 4 character size; am I right ? Thank You. \$\endgroup\$ Commented Dec 11, 2016 at 20:16
  • 1
    \$\begingroup\$ The OP apparently wondered how to store it in flash at link-time. This seems to be an example of how to store it there in run-time, minus the whole flash driver. \$\endgroup\$
    – Lundin
    Commented Dec 12, 2016 at 7:42

The standard way of storing data in flash at link-time when C programming, is to declare the variable as const.

const uint8_t array[4] = {0, 1, 2, 3};

Most compilers will then know to place this array in flash instead of RAM, but only if the variable also has static storage duration. Meaning that the above array must either be declared at file scope, or as static. See this for details.

Compilers also have non-standard syntax to place an array in a specific part of flash, which is what you have to use if the above won't work on your specific compiler. It can also be useful when for example dealing with eeprom/data flash.

  • \$\begingroup\$ what if I have an array of 200 characters. 'char Room[200]' . which I need to store at data flash during run time. How can I do this? [ by using multiple of 4 -1 array index to each memory location ?] \$\endgroup\$ Commented Dec 12, 2016 at 8:00
  • \$\begingroup\$ @ArunCheriyan Then you have to write/use a flash programming driver for the specific MCU. \$\endgroup\$
    – Lundin
    Commented Dec 12, 2016 at 8:22
  • \$\begingroup\$ Why the down vote? I posted this after explicitly prompting the OP about what they wanted. \$\endgroup\$
    – Lundin
    Commented Dec 12, 2016 at 8:39
  • \$\begingroup\$ I did not do it, anyways I 've given an upvote \$\endgroup\$ Commented Dec 12, 2016 at 8:49
  • \$\begingroup\$ Note: Not all compilers will put a const variable in flash. \$\endgroup\$
    – m.Alin
    Commented Dec 12, 2016 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.