cancel
Showing results for 
Search instead for 
Did you mean: 

How to save const data array in STM32F7 QSPI memory?

JChen.24
Associate III

Hi,

I am using STM32F746G_DISCOVERY board.

In the QSPI_PreInitConfig example, how to put const array data to QSPI flash? I try to declare as follows, but cannot pass compiler. error: 'img2' causes a section type conflict with 'GpioToggle'. I notice that section(".qspi") is used by function GpioToggle(), I should make array data share the same section in QSPI memory, not sure how to do it. The following is the code with compiler error.

 __attribute__((section(".qspi")))

 const unsigned char img2[2] =

 {

 0xFF, 0xFF

 };

7 REPLIES 7
/* Memory Spaces Definitions */
MEMORY
{
...
  QSPI (rx) : ORIGIN = 0x90000000, LENGTH = 1M
}
 
...
 
 .qspi :
 {
        *(.qspi)
        *(.qspi.*)
 } >QSPI
In .C
 
__attribute__((section(".qspi")))
 const unsigned char img2[2] =
 {  0xFF, 0xFF };
 
...
 
In .MAP
 
.qspi           0x90000000        0x2
 *(.qspi)
 .qspi          0x90000000        0x2 out/main.o
                0x90000000                img2
 *(.qspi.*)

Would take time/effort to set up a build system for the project you mention, I did this with existing GNU build environment I use.

Figure out why your compiler is annoyed, and associating this with GpioToggle(), et al

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JChen.24
Associate III

I created .qspi2 section in the linker file:

  .qspi :

 {

  . = ALIGN(4);

  _qspi_start = .;    /* create a global symbol at qspi start */

  *(.qspi)     /* .qspi sections */

  *(.qspi*)    /* .qspi* sections */

  *(.qspi2)     /* .qspi2 sections */

  *(.qspi2*)    /* .qspi2* sections */

  . = ALIGN(4);

  _qspi_end = .;     /* define a global symbols at end of qspi */

   

 } >QSPI

===========

and declare img2 as:

 __attribute__((section(".qspi2")))

 const uint16_t img2[2] =

 {

 0xFF, 0xFF

 };

===========

GpioToggle is still the same:

 static void __attribute__((section(".qspi"), noinline)) GpioToggle(void)

now compiler error goes away.

But the .list file does not show any memory allocated for img2[].

Still not sure how to allocate memory for img2[] in QSPI memory space starting at 0x90000000.

I can send project folder if you like.

Please help.

Perhaps if the text and data name spaces conflict

__attribute__((section(".qspi.data"))) // this will match against *(.qspi.*)

 const uint16_t img2[2] =

 {

 0xFF, 0xFF

 };

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JChen.24
Associate III

I changed to __attribute__((section(".qspi.data"))), but still don’t see img2 memory allocation.

Now I only use img2[] for .qspi section, GpioToggle function is moved outside .qspi section.

The beginning of list file shows as follows, .qspi has size of 0. Img2[] is not allocated in .qspi.

 ==================

Sections:

Idx Name         Size     VMA      LMA      File off Algn

 0 .isr_vector  000001c8 08000000 08000000 00010000 2**0

                 CONTENTS, ALLOC, LOAD, READONLY, DATA

 1 .text        00000f94 080001c8 080001c8 000101c8 2**2

                 CONTENTS, ALLOC, LOAD, READONLY, CODE

 2 .rodata      00000018 0800115c 0800115c 0001115c 2**2

                 CONTENTS, ALLOC, LOAD, READONLY, DATA

 3 .qspi        00000000 90000000 90000000 0002000c 2**0

                 CONTENTS

 4 .init_array  00000004 08001174 08001174 00011174 2**2

                 CONTENTS, ALLOC, LOAD, DATA

Linker can discard unused data objects. Use it somewhere.

Linker Script can be forced to "keep" sections, entry points, etc

  /* Ensure entry points are pulled in here */

  KEEP (*(.text.Init))

  KEEP (*(.text.Write))

  KEEP (*(.init))

  KEEP (*(.fini))

There's also the used attribute, although I found that to be less than effect.

 __attribute__((used))

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JChen.24
Associate III

Thanks for the help!

I figured out. I should put array in .h file, not c file.