This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Organization of startup from internal flash of Cortex M3

Hi,

i want to understand how the startup of a cortex M3 works. When i debug the startup i saw that from adress 0x0 a big area with DCW comes, like here:

0x00000000 0268  DCW  0x0268
0x00000002 2000  DCW  0x2000
0x00000004 0505  DCW  0x0505
0x00000006 0000  DCW  0x0000
0x00000008 050D  DCW  0x050D
0x0000000A 0000  DCW  0x0000
0x0000000C 050F  DCW  0x050F
0x0000000E 0000  DCW  0x0000
0x00000010 0511  DCW  0x0511
0x00000012 0000  DCW  0x0000
0x00000014 0513  DCW  0x0513

Later followed from that:

0x000001CA 0000  DCW  0x0000
0x000001CC 051F  DCW  0x051F
0x000001CE 0000  DCW  0x0000
             __main:
0x000001D0 F000F802  BL.W __scatterload (0x000001D8)
0x000001D4 F000F83A  BL.W __rt_entry (0x0000024C)
             __scatterload:
0x000001D8 A00A  ADR  r0,{pc}+4  ; @0x00000204
0x000001DA E8900C00  LDM  r0,{r10-r11}
0x000001DE 4482  ADD  r10,r10,r0
0x000001E0 4483  ADD  r11,r11,r0
0x000001E2 F1AA0701  SUB  r7,r10,#0x01
             __scatterload_null:

but if i debug i saw that this section was first excuted:

0x00000500 0334  DCW  0x0334
0x00000502 0640  DCW  0x0640
   195:             LDR R0, =SystemInit
0x00000504 4809  LDR  r0,[pc,#36]  ; @0x0000052C
   196:             BLX R0
0x00000506 4780  BLX  r0
   197:             LDR R0, =__main
0x00000508 4809  LDR  r0,[pc,#36]  ; @0x00000530
   198:             BX  R0

Can anybody explain me how the startup exactly works and what is the meaning of the DCW part?

So which assembler directive calls the SystemInit?

Best regards

Volker

Parents
  • Hi Vokuit,

    The start up mechanism of a Cortex-M3 is very simple. It loads the initial value of the stack pointer (MSP) from the first word of the vector table and sets the initial value of the program counter (PC) from the second word. The only slight trick to remember is that function addresses must always have the LSB set to 1 (to indicate that the target instruction is in Thumb), so the first two words you are seeing are:

    0x20000268 - the initial value of the stack pointer

    0x00000505 - sets the initial PC to 0x00000504

    If you then look down at what is at t hat address, you will find the instructions:

    LDR R0, =SystemInit ; sets R0 to the value SystemInit

    BLX R0 ; calls the function at the address in R0

    It is this pair of instructions which calls the SystemInit function. When that function returns, you can see a similar pair of instructions which calls __main. This is the main entry point of the library and eventually the application will be called at main().

    I hope that gives you a start in working out what's going on!

    I would encourage you to have a look at the Cortex-M3 Devices Generic User Guide which you can find on infocenter.arm.com (along with a lot of other very useful documentation). Specifically, section 2.3.4 (Vector Table) shows the contents of the first two words which I mentioned above.

    Hope this helps.

    Chris

Reply
  • Hi Vokuit,

    The start up mechanism of a Cortex-M3 is very simple. It loads the initial value of the stack pointer (MSP) from the first word of the vector table and sets the initial value of the program counter (PC) from the second word. The only slight trick to remember is that function addresses must always have the LSB set to 1 (to indicate that the target instruction is in Thumb), so the first two words you are seeing are:

    0x20000268 - the initial value of the stack pointer

    0x00000505 - sets the initial PC to 0x00000504

    If you then look down at what is at t hat address, you will find the instructions:

    LDR R0, =SystemInit ; sets R0 to the value SystemInit

    BLX R0 ; calls the function at the address in R0

    It is this pair of instructions which calls the SystemInit function. When that function returns, you can see a similar pair of instructions which calls __main. This is the main entry point of the library and eventually the application will be called at main().

    I hope that gives you a start in working out what's going on!

    I would encourage you to have a look at the Cortex-M3 Devices Generic User Guide which you can find on infocenter.arm.com (along with a lot of other very useful documentation). Specifically, section 2.3.4 (Vector Table) shows the contents of the first two words which I mentioned above.

    Hope this helps.

    Chris

Children