• AVR Freaks

Hot!Embedding a data file in memory during at compile time

Author
dmccric
Senior Member
  • Total Posts : 149
  • Reward points : 0
  • Joined: 2006/05/30 08:13:15
  • Location: Bradford, England
  • Status: offline
2019/02/12 08:06:40 (permalink)
0

Embedding a data file in memory during at compile time

Does anyone know how to include an external data/bin file into the generated hex file during compile time on a PIC32MX MCU?
 
I am using XC32 and the PIC32MX795F512L and would like to include a text file in a section at the end data memory for testing. Once I have created a release version it will not be needed.
 
I understand this can be done by modifying the linker script to create a new section and then including the file as you would a header file in a c source file.
 
Does anyone know how this can be done? I am reading through the Assembler/Linker Script user guide but it will take some time.
#1

4 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17485
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Embedding a data file in memory during at compile time 2019/02/12 08:26:06 (permalink)
    +2 (2)
    You can make the data an array at a fixed address.
    Or
    If you convert the data to intel Hex you can merge the hex files.
    #2
    malaugh
    Super Member
    • Total Posts : 397
    • Reward points : 0
    • Joined: 2011/03/31 14:04:42
    • Location: San Diego
    • Status: offline
    Re: Embedding a data file in memory during at compile time 2019/02/12 11:37:10 (permalink)
    +1 (1)
    Look for a utility called xxd.  There is a version here https://github.com/rickkas7/crc32_and_xxd  This utility takes any binary file and makes a C file containing an array that can be linked to the rest of the code.
     
     
     
    #3
    SERGOSV
    Starting Member
    • Total Posts : 33
    • Reward points : 0
    • Joined: 2017/11/01 11:47:58
    • Location: 0
    • Status: offline
    Re: Embedding a data file in memory during at compile time 2019/07/10 07:20:35 (permalink)
    0
    In Linker Script File:
    1.Set Memory Region:
    (addres and size of region)
    for example:
          fat_nvm_mem           (rx)   : ORIGIN = 0x9D015000, LENGTH = 0x40000  
     
    2. Set SECTIONS (for example)
       .fat_region :
       {
        KEEP(*(.fat_region))
        } >fat_nvm_mem
    3. Place bin-file FILE.bin (for example)  in root of project (size of bin-file must be < LENGTH)
    4. In file with C-code add code:
    asm (".section .fat_region, code"); 
    asm (".incbin \"FILE.bin\""); 
    5. bin-data will be place to ADDR 0x9D015000.
     
    #4
    Jim Nickerson
    User 452
    • Total Posts : 6016
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Embedding a data file in memory during at compile time 2019/07/10 07:38:15 (permalink)
    0
    NKurzman
    You can make the data an array at a fixed address.
    Or
    If you convert the data to intel Hex you can merge the hex files.

    In the v2013-06-15 MLA there is "D:\microchip\mla\v2013-06-15\Microchip\TCPIP Stack\Utilities\Source\MPFS21" directory with the source code for the MPFS21 utility used to make a C data file ( and other types ) from a list of files, in this case the web pages served by the web server.
    I still use this code today on my Windows 10 PC.
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5