cancel
Showing results for 
Search instead for 
Did you mean: 

Branch with link instruction does not jump to SystemInit()

kjoly
Associate II
Posted on November 28, 2013 at 19:24

Hello,

We are a robotics association from ENSEIRB-MATMECA (Bordeaux, France). We are developping some boards and a template project for STM32 devices.

One of our boards embed a STM32F103C4 microcontroller. We use the startup script from gcc ride7  startup_stm32f10x_ld.s.This startup script work until the line ''bl SystemInit'' is reached. Then, the system doesn't jump to SystemInit() function as he is expected to do and the bootloader is listening again (reset).

Here is the link instruction:

/home/kevin/ausbee-test/Software/Toolchain/arm-none-eabi/bin/arm-none-eabi-gcc -o /home/kevin/ausbee-test/Software/output/project.elf -mthumb -mcpu=cortex-m3 -Wall -Wextra -mcpu=cortex-m3 -mfix-cortex-m3-ldrd -mthumb-interwork -DSTM32F10X_LD -Wl,--gc-sections -Wl,--Map=test.map  -T/home/kevin/ausbee-test/Software/System-CM3/link.ld /home/kevin/ausbee-test/Software/System-CM3/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_ld.o /home/kevin/ausbee-test/Software/System-CM3/CMSIS/CM3/CoreSupport/core_cm3.o /home/kevin/ausbee-test/Software/System-CM3/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.o /home/kevin/ausbee-test/Software/Project/src/main.o

The test.map file contain the SystemInit symbol.

We use GCC ARM embedded toolchain (

https://launchpad.net/gcc-arm-embedded

). Our template project work with other devices such as STM32f105.

Do you have any idea where this bug come from?

Thanking you in advance.

#stm32-startup
7 REPLIES 7
Posted on November 28, 2013 at 23:11

Real hard to tell without the code in hand, or some actual diagnostic output. There could be an issue with the distance of the branch too SystemInit(), or there could be something in it that causes it to fault. Ideally you'd have a Hard Fault handler which could decode the processor state at the fault and point you at a specific instruction, and register settings.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kjoly
Associate II
Posted on November 29, 2013 at 00:01

Thank you very much for your reply. I didn't provided the code because it is the one available in CMSIS:

http://stm32radio.googlecode.com/svn-history/r60/trunk/stm32radio/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_ld.s

http://elk.informatik.fh-augsburg.de/pub/stm32lab/libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Template/system_stm32f10x.c

We don't have any JTAG or SWD but I have made a very simple test: if I put an infinite loop before ''bl SystemInit'' in startup_stm32f10x_ld.s, the MCU get stuck and the bootloader is not listening. If I put this loop at the beginning of SystemInit() and remove the previous one, the boot loader is listening again and again ... I concluded that the SystemInit() is not called.

Posted on November 29, 2013 at 00:21

Executable code, .HEX, assume that I don't have your code or ability to build my own in exactly the fashion you have it.

Consider what you are doing in your linker script (.LD), if it's accurately describing the smaller memory in your part, and setting the stack pointer to something within the scope of that memory.

At a guess I'd say the initial PUSH in SystemInit() is exploding.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kjoly
Associate II
Posted on November 29, 2013 at 09:12

The linker script come from here:

http://m.florian.free.fr/articles/montages/stm32_template/stm32_flash.ld

Of course I have changed the values in RAM (10K) and FLASH (32K). I let the Stack_Size to 1024 and it should be enough I guess.

All the project is here: 

https://github.com/Kev-J/ausbee/tree/master/Software

If you want to try it, it works with kconfig, type ''make menuconfig''.

That's weird because exactly the same configuration works on STM32F10X Connectivity Line.

Thank you very much for your answers.

kjoly
Associate II
Posted on November 29, 2013 at 09:27

Observe the value of _estack

https://github.com/Kev-J/ausbee/blob/master/Software/System-CM3/link.ld.in

The value expressed in the .MAP, and as the first word in .HEX/.BIN, or in SP/R13 in the debugger prior to failure.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kjoly
Associate II
Posted on November 30, 2013 at 00:25

Problem solved! Thank you very much!

As you said, the problem was _estack. My linker script was adapted from one for a specific device so the _estack was statique at link. I just set it dynamic with:  _estack = ORIGIN(RAM) + LENGTH(RAM);