0

I'm seeing some weird behaviour in the Kiel compiler. This is the reset code, I'm using a generic STM32F103C8 board (which uses an M3 core), and the SystemInit function (which is provided by the Kiel libraries) has somehow ended up at an odd address (0800043D), you can see from the screenshot below that the pointer at 080001F8 contains this value and sure enough, when the instruction at the PC (BLX r0) is executed, a hard fault occurs. Has anyone seen this happen before? How can I get it to put the SystemInit function at an even address?

Also, my main() function seems to have ended up at an odd address as well... Shouldn't the compiler align these for me?

These 2 lines from the map file are interesting:

0x08000000   0x000000ec   Data   RO         1224    RESET               startup_stm32f10x_md.o
0x080000ec   0x00000008   Code   RO         1269  * !!!main             c_w.l(__main.o)

Bug?

Charlie Skilbeck
  • 1,081
  • 2
  • 15
  • 38
  • What is the value of `r0` just before `BLX r0` is executed? – barak manos May 15 '16 at 15:09
  • 0800043D, which is loaded from 080001F6 – Charlie Skilbeck May 15 '16 at 15:16
  • These lines from the map file are interesting: 0x08000000 0x000000ec Data RO 1224 RESET startup_stm32f10x_md.o 0x080000ec 0x00000008 Code RO 1269 * !!!main c_w.l(__main.o) – Charlie Skilbeck May 15 '16 at 15:16
  • And what do you see when you view this memory address as source code? – barak manos May 15 '16 at 15:17
  • added them to the question for formatting – Charlie Skilbeck May 15 '16 at 15:17
  • That doesn't answer my question. – barak manos May 15 '16 at 15:21
  • Can't really disassemble at an odd address, it looks like random instructions, but the SystemInit function label is at that address -1 – Charlie Skilbeck May 15 '16 at 15:21
  • Sorry, my comment about the map file crossed over with your question about disassembly – Charlie Skilbeck May 15 '16 at 15:22
  • Try to manually change `r0` to (what you say is) the correct address right before `BLX r0` is executed. What do you observe now? – barak manos May 15 '16 at 15:23
  • Yep, then it jumps to SystemInit correctly – Charlie Skilbeck May 15 '16 at 15:23
  • What is the equivalent C code for those two assembly lines (if you happen to have it)? Can you please search `SystemInit` in the map file, and say what you see next to it? Note that it might appear in more than one place. – barak manos May 15 '16 at 15:28
  • 1
    [Any](http://stackoverflow.com/q/15764833/3156750) [function](http://stackoverflow.com/q/14120711/3156750) [address](http://stackoverflow.com/q/15045144/3156750) [must](http://stackoverflow.com/q/29381889/3156750) [have](http://stackoverflow.com/q/16079189/3156750) [the](http://stackoverflow.com/q/16647084/3156750) [lsb](http://stackoverflow.com/q/37004954/3156750) [set](http://stackoverflow.com/q/28110605/3156750) - that's how Thumb interworking works, and on Cortex-M3, all code must be Thumb. Is what's at 0x0800043c executable code? – Notlikethat May 15 '16 at 16:09
  • Notlikethat - thanks, if you answer it, I'll accept it – Charlie Skilbeck May 15 '16 at 16:32
  • For the record, the actual problem was that I had a large array of data which was not marked as const, so it was trying to put it in sram, but it didn't fit. A full rebuild threw up the "it won't fit" error, not sure why it didn't show up when doing a normal build. – Charlie Skilbeck May 15 '16 at 22:13

0 Answers0