cancel
Showing results for 
Search instead for 
Did you mean: 

Using __attribute__((__section__())) stops code running?

mwp
Senior
Posted on November 23, 2012 at 03:16

Hi all,

Bit of a strange one... When i include this line in one of my C source files, my software no longer starts up after reset correctly (jumps off into no-mans land).

const
unsigned 
char
settings[0x4800] __attribute__((__section__(
''.settings''
), used));

With this line commented out, everything works just fine. Anyone know why this would be the case? Relevantsections of the linker scripts:

MEMORY
{
/* main program ram (48Kb) */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0xC000
/* startup boot jump (20 bytes) */
MINI_BOOT (rx) : ORIGIN = 0x8000000, LENGTH = 0x14
/* manufacturing data (2028 bytes) */
MANUF_DATA (rw) : ORIGIN = 0x8000014, LENGTH = 0x2048 - 0x16
/* settings data storage (18Kb) */
SETTINGS (rw) : ORIGIN = 0x8000800, LENGTH = 0x4800
/* user data storage (2Kb) */
USER_DATA (rw) : ORIGIN = 0x8005000, LENGTH = 0x800
/* extra boot loader code (22Kb) */
BOOT_LOADER (rx) : ORIGIN = 0x8005800, LENGTH = 0x5800
/* main program flash (216Kb) */
FLASH (rwx) : ORIGIN = 0x800B000, LENGTH = 0x35000 
/* end at 0x8040000 */
}

SECTIONS
{
/* FLASH **************************/
.settings :
{
. = ALIGN(4);
KEEP(*(.settings))
. = ALIGN(4);
} > SETTINGS
.user_data :
{
. = ALIGN(4);
KEEP(*(.user_data))
. = ALIGN(4);
} > USER_DATA 
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) 
/* Startup code */
. = ALIGN(4);
} > FLASH
.text :
{
. = ALIGN(4);
*(.text) 
/* remaining code */
*(.text.*) 
/* remaining code */
*(.rodata) 
/* read-only data (constants) */
*(.rodata.*)
*(.glue_7)
*(.glue_7t)
*(.vfp11_veneer)
*(.gcc_except_table)
. = ALIGN(4);
/* These are for static initializers, constructors, and destructors */
KEEP(*(.init))
KEEP(*(.fini))
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
.ARM.exidx :
{
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
} > FLASH
. = ALIGN(4);
_etext = .;
_sidata = _etext;
........................

Thanks in advance!
6 REPLIES 6
Posted on November 23, 2012 at 04:25

Take a look at the .MAP file to see where things are placed, and how that differs in working vs non-working scenarios. Look at the listings to see what the code flow looks like.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mwp
Senior
Posted on November 23, 2012 at 12:02

Ok, ive found the issue.

Im writing the .bin to the device rather than the .elf.

With the problem line included, the .settings region is included in the .bin which throws off the .text location.

Ill have to do it another way...
kkarasti
Associate II
Posted on February 27, 2013 at 21:09

I'm having the same problem but since this is my first STM32 project, I can't seem to come to a solution. But here's the core problem, if I don't use the _attibute_ then things run fine but I can only save data to a flash location once. So I was thinking the _attibute_ command would allow me to write multiple times. Maybe they are two unrelated things?

Basically I need to save runtime data to flash to be retrieved after power cycle. I've tried all sorts of things and just can't get it.

Posted on February 27, 2013 at 21:49

You can't architect a flash writing solution in your application with the linker.

You need to erase memory before it can be written too a second time. If you want to write more things to the same page you need to advance the pointer beyond the data already committed.

You need to look at the FLASH_xxx functions and review the PM (Programming Manual) for the part you are utilizing.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kkarasti
Associate II
Posted on February 27, 2013 at 21:53

Thanks will do some reading. I was wondering about the linker script because it seemed I could write once when using the default script. But some reading I did pointed me that way. With the STM8, you can just write and rewrite as much as you want so that was getting me.

kkarasti
Associate II
Posted on February 27, 2013 at 22:08

Heh. Just erasing the page before writing again was all there was too it! Jeesh!