Using a const char pointer to access a binary image

Technical Note 71111



10/13/2015 11:25 AM


Define a string in a fixed flash (e.g. address 0x08004000)

#pragma location=0x08004000
char string[100]; // no assigned value

Assign a value to the string from a .binary file (using IAR ILINK Linker).

When accessing the data from source, it is needed to read the data from the fixed address like ...

*(uint32_t *)0x08004000

... but it is prefered to do the access to the data with a variable, that is, a string variable.


IAR Embedded Workbench for ARM provides a feature that can link one binary file of any kind (e.g. bin, bmp, wav, etc.) in a project through the linker option


The linked binary content can be accessed through a pointer.


An example project is available on the link, where these steps are made:

  1. Create a binary file test.bin with a 100 character long text (a text file test.txt was simply renamed to test.bin)
  2. Set the linker options (see Options_Linker_Input.png) to include a binary image (test.bin), define a symbol (test_bin_symbol) and a section (test_bin_section).
  3. Place the binary image with a linker file directive:
    place at address mem:0x08004000 { readonly section test_bin_section };
    The map files shows:
    test_bin_section const 0x08004000 0x64 test.bin [1]
    test_bin_symbol 0x08004000 0x64 Data Gb test.bin [1]
  4. Access the binary image from source through a const char pointer:
    // symbol 'test_bin_symbol' defined by linker option --image_input
    extern const char * test_bin_symbol;

    int main()
    return test_bin_symbol[0];


All Product names are trademarks or registered trademarks of their respective owners.

Related Tech Notes

© IAR Systems 1995-2018 - All rights reserved.

We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies