2
\$\begingroup\$

I am working with nordic nRF51422 uC with cortex M0 core and I have to store data in Non-Volatile Memory but to do that properly I need information where exactly code of the program is stored in flash.

The vector table is fixed at address 0x00000000 and it tells me the start of each interrupt service routine I have implemented but I struggle to find information what is the length of each ISR. It would be also useful to know where each function of the program starts and ends.

Summarizing, is there any easy way to spy how the code of program is mapped into flash? Is it compiler dependent? Can I set my own boundaries for each function? Are there any mechanisms that enable dynamically checking end address of the code while executing program on uC ?

asked Feb 24, 2015 at 11:35
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Specify which compiler you are using. If it's gcc, objdump will let you inspect, and linker scripts (something.ld) will let you specify, memory layout. \$\endgroup\$ Commented Feb 24, 2015 at 13:15
  • \$\begingroup\$ Yes I use gcc. Linker script is not so easy to understand when you have never seen and written such files. \$\endgroup\$ Commented Feb 24, 2015 at 19:07

1 Answer 1

2
\$\begingroup\$

The common approach is to make a const array that contains the appropriate values (initial SP, initial PC = adress of init code, addresses of the interrupt service routines) and use some compiler-dependant magic to force the linker to place this array at address 0.

An example in gcc (from my http://www.voti.nl/bmptk):

void (* const __vectors[ 8 ])(void) 
__attribute__ ((section(".vectors"))) = {
 (void (*)(void)) & __stack_end, 
 __startup,
 // interrupt verctors etc.
};

The __ attribute__ ((section(".vectors"))) marks this array as part of a section called "vectors". The matching linkerscript ensures that that section is placed first in the flash memory:

MEMORY
{
 rom (rx) : org = ROM_START, len = ROM_SIZE
 ram (rwx) : org = RAM_START, len = RAM_SIZE
 nul (rwx) : org = 0x20000000, len = 0k
}
. . . 
SECTIONS
{
 .text :
 {
 . = ALIGN(4);
 KEEP(*(.vectors));
 . . .
 # other sections come here (= the rest of your code)

In normal situations this is something that your tool vendor/builder/creator has done for you.

answered Feb 24, 2015 at 14:04
\$\endgroup\$
2
  • \$\begingroup\$ Ok, but lets suppose I have a lot of xxx.c files and in one of them I have implementation of myFuction(). Then after compilation I want to place machine code, that the function consists of at address 0xMyChoosenAddress. Is it possible ? \$\endgroup\$ Commented Feb 24, 2015 at 19:15
  • \$\begingroup\$ Yes, declare the function in a header which is included by the c file that contains the vectors array. The linker will fill in the address of your function (defined in another c file0. \$\endgroup\$ Commented Feb 24, 2015 at 20:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.