Cortex M3 - Copying code from flash to ram without startup
Hi all,
I am using STM32F107 chip (Cortex-M3) with arm-gcc-launchpad toolchain with mac. (arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q1-update) 6.3.1 20170215 (release) [ARM/embedded-
The problem I see is that although I don't use any startup code and I don't have any function to copy the text section to ram, all the text section gets copied to the ram area. This becomes a problem when I use an initialized global array. The array gets copied to the end of the instructions in the ram area, however the processor thinks it starts from the ram base (which is what it should be - I think).
The question is, is there a way to tell the linker not to copy the text section to ram area? Also is this an expected behavior or is this some sort of bug?
Just to demonstrate here is what the flash are looks like with a simple C code that displays the array values from a port.
(gdb) x/64x 0x08000000
0x8000000 <vector_table>: 0x20008000 0x08000011 0x00000000 0x00000000
0x8000010 <main>: 0xb082b510 0xf04f4a13 0xf04f0300 0xe9c20400
0x8000020 <main+16>: 0x4a113400 0x699b4b10 0x0320f043 0x4b0f6193
0x8000030 <main+32>: 0x3222f04f 0x4b0d605a 0x3222f04f 0x2300601a
0x8000040 <main+48>: 0xe00b9301 0x490a4a09 0xf8519b01 0x60d33023
0x8000050 <main+64>: 0xf0004808 0x9b01f811 0x93013301 0x2b4f9b01
0x8000060 <main+80>: 0xe7ecd9f0 0x20000140 0x40021000 0x40011400
0x8000070 <main+96>: 0x20000000 0x00030d40 0x9001b082 0xe0029b01
0x8000080 <delay+8>: 0x3b019b01 0x9b019301 0xd1f92b00 0xb002bf00
0x8000090 <delay+24>: 0x00004770 0x00000001 0x00000002 0x00000003
0x80000a0: 0x00000004 0x00000005 0x00000006 0x00000007
0x80000b0: 0x00000008 0x00000009 0x0000000a 0x0000000b
0x80000c0: 0x0000000c 0x0000000d 0x0000000e 0x0000000f
0x80000d0: 0x00000010 0x00000011 0x00000012 0x00000013
0x80000e0: 0x00000014 0x00000015 0x00000016 0x00000017
0x80000f0: 0x00000018 0x00000019 0x0000001a 0x0000001b
This looks fine and the last part is the global initialized array. However if I look at the ram section I see:
(gdb) x/64x 0x20000000
0x20000000 <uint_array_
0x20000010 <uint_array_
0x20000020 <uint_array_
0x20000030 <uint_array_
0x20000040 <uint_array_
0x20000050 <uint_array_
0x20000060 <uint_array_
0x20000070 <uint_array_
0x20000080 <uint_array_
0x20000090 <uint_array_
0x200000a0 <uint_array_
0x200000b0 <uint_array_
0x200000c0 <uint_array_
0x200000d0 <uint_array_
0x200000e0 <uint_array_
0x200000f0 <uint_array_
There are around 40 bytes of data that I don't know what it is, then the vector table starts with 0x20008000 value and then I see the instructions. My array comes afterwards, but if you look at the labels, it thinks the array starts from 0x20000000 where it actually starts at roughly 0x200000bc area. (When executing the code, the first index of the array points to the ram location 0x20000000, thus the instructions get shown on the LEDs )
I have uploaded the files here:
https:/
Thanks,
Furkan
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- fcayci
- Solved:
- Last query:
- Last reply: