const char 포인터 사용하여 바이너리 이미지 접근

기술노트 71111






2018-02-28 오전 2:52


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.

죄송하지만, 당사 사이트에서는 Internet Explorer를 지원하지 않습니다.보다 편안한 사이트를 위해 Chrome, Edge, Firefox 등과 같은 최신 브라우저를 사용해 주시길 부탁드립니다.