Hi all,
I am using uVision 4 with the Sourcery GNU toolchain. Compiling and linking works, even debugging in simulation mode works. But if I download to the target, the entry address (PC after reset) and the stackpointer are completely wrong. I am using a STM32F107VC (Cortex-M3).
Here is the output of readelf:
$ arm-none-eabi-readelf.exe -S project.elf There are 18 section headers, starting at offset 0x3884c: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .isr_vector PROGBITS 08000000 008000 000108 00 A 0 0 4 [ 2] .text PROGBITS 08000108 008108 00fe2c 00 AX 0 0 4 [ 3] .bss NOBITS 20000000 018000 000094 00 WA 0 0 4 [ 4] ._usrstack NOBITS 20000094 018000 000100 00 WA 0 0 1 [ 5] .ARM.attributes ARM_ATTRIBUTES 00000000 017f34 00002f 00 0 0 1 [ 6] .comment PROGBITS 00000000 017f63 0003b2 00 0 0 1 [ 7] .debug_aranges PROGBITS 00000000 018318 0002e0 00 0 0 8 [ 8] .debug_pubnames PROGBITS 00000000 0185f8 002d10 00 0 0 1 [ 9] .debug_info PROGBITS 00000000 01b308 00b459 00 0 0 1 [10] .debug_abbrev PROGBITS 00000000 026761 001d16 00 0 0 1 [11] .debug_line PROGBITS 00000000 028477 002162 00 0 0 1 [12] .debug_frame PROGBITS 00000000 02a5dc 003af8 00 0 0 4 [13] .debug_str PROGBITS 00000000 02e0d4 00419c 01 MS 0 0 1 [14] .debug_loc PROGBITS 00000000 032270 00651e 00 0 0 1 [15] .shstrtab STRTAB 00000000 03878e 0000be 00 0 0 1 [16] .symtab SYMTAB 00000000 038b1c 002d30 10 17 121 4 [17] .strtab STRTAB 00000000 03b84c 002b40 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) $ arm-none-eabi-readelf.exe -x .isr_vector project.elf Hex dump of section '.isr_vector': 0x08000000 00000120 c5fc0008 00000000 00000000 ... ............ 0x08000010 00000000 00000000 00000000 00000000 ................ 0x08000020 00000000 00000000 00000000 00000000 ................ 0x08000030 00000000 00000000 00000000 00000000 ................ 0x08000040 00000000 00000000 00000000 00000000 ................ 0x08000050 00000000 00000000 00000000 00000000 ................ 0x08000060 00000000 00000000 00000000 00000000 ................ 0x08000070 00000000 00000000 00000000 00000000 ................ 0x08000080 00000000 00000000 00000000 00000000 ................ 0x08000090 00000000 00000000 00000000 00000000 ................ 0x080000a0 00000000 00000000 00000000 00000000 ................ 0x080000b0 00000000 00000000 00000000 00000000 ................ 0x080000c0 00000000 00000000 00000000 00000000 ................ 0x080000d0 00000000 00000000 00000000 00000000 ................ 0x080000e0 00000000 00000000 00000000 00000000 ................ 0x080000f0 00000000 00000000 00000000 00000000 ................ 0x08000100 00000000 00000000 ........
At address 0x08000000 there is the address of top of stack which is configured to 0x20010000 in my linkner script. So this seems to bee correct in the elf-file (little endian). When I download the image to the target, R13 (SP) is initialized with 0x2000a450, which is not what is in the elf!
At address 0x08000004 there should be the address of the reset handler. According to the map-file, this is linked to address 0x0800fcc4. In the elf-file, we read 0xc5fc0008 (little endian). Since Cortex-M3 only supports thumb, the LSB is set to 1 to indicate thumb-mode. When downloading the image to the target, R15 (PC) contains 0x0800046c which is wrong again!
Any ideas, hints and tips on what could go wrong with downloading highly appreciated!
Many thanks in advance!
-- Regards, Marco