Skip to main content
Associate II
January 10, 2024
Solved

STM32Cube Data-Only Project

  • January 10, 2024
  • 3 replies
  • 1365 views

I'm trying to generate an s-record file that contains nothing but an array of data in flash - no executable code.  (This is used by an external tool and loaded into flash later as config data.)  I deleted everything from the project except main.c.  I also stripped everything out of the linker .ld file except the data array.  But the compiler still generates a _init and a _fini section of code.  How do I get rid of those?

main.c

const unsigned char Data_Arr[] __attribute__((section (".data_arr"))) = /* Test array */

{

0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18

};

 

.ld file

/* Memories definition */

MEMORY

{

FLASH (rx) : ORIGIN = 0x0801E000, LENGTH = 4K

}

 

/* Sections */

SECTIONS

{

.data_arr :

{

. = ALIGN(4);

KEEP (*(.data_arr))

} >FLASH

}

 

List file still contains:

Disassembly of section .init:

0801e000 <_init>:
801e000: b5f8 push {r3, r4, r5, r6, r7, lr}
801e002: bf00 nop

Disassembly of section .fini:

0801e004 <_fini>:
801e004: b5f8 push {r3, r4, r5, r6, r7, lr}
801e006: bf00 nop

 

S-Record

S010000054657374446174612E73726563FA
S3090801E000F8B500BFA1
S3090801E004F8B500BF9D
S30D0801E00811121314151617185D
S70500000000FA

 

Thanks for your help.

    Best answer by RHJ

    The real data array will be an array of structs about a K long, so it really needs to be compiled with a C compiler.

    However, this seemed to work (linker script):

    .text (NOLOAD) :

    {

    *(.init)

    *(.fini)

    } >FLASH

     

    Thanks again for your help.

    3 replies

    Bob S
    Super User
    January 10, 2024

    The compiler/linker is always going to include the c/c++ startup code and other stuff.

    How about srecord  https://srecord.sourceforge.net/ .  You can create a text file with hex values then use srec_cat to create the S-record (or almost any other format) formatted file.

    Tesla DeLorean
    Guru
    January 10, 2024

    Make those "NOLOAD" sections in the Linker Script ?

    Making a PC side C app that simply outputs S-Records from an array shouldn't be that hard, format in use since the late 1970's. I've written patching / packaging tools that just natively output .HEX files in Intel, Motorola or Tektronix formats.

    As Bob indicates SRECORD is a popular open source version.

    I'd suppose OBJCOPY could also be run on a section level basis

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    RHJAuthorBest answer
    Associate II
    January 10, 2024

    The real data array will be an array of structs about a K long, so it really needs to be compiled with a C compiler.

    However, this seemed to work (linker script):

    .text (NOLOAD) :

    {

    *(.init)

    *(.fini)

    } >FLASH

     

    Thanks again for your help.