Semihosting with newlib freeze

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
baoshi
Posts: 9
Joined: Wed May 15, 2013 5:49 am
Been thanked: 1 time

Semihosting with newlib freeze

Post by baoshi »

I've been trying semihosting, by changing LD variable in the Makefile to:
LD = $(TRGT)gcc -specs=rdimon.specs
The balance I need to do is just to add
initialise_monitor_handles()
in main() to get printf() working.

However, if I try use newlib at the same time, where
LD = $(TRGT)gcc -specs=nano.specs -specs=rdimon.specs
The program hangs at printf() statement.
It seems a bare-metal build without ChibiOS does not have this problem. I trace a bit and think the lack of __libc_init_array from the startup code probably causes this.

Any help will be appreciated.

Baoshi
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Semihosting with newlib freeze

Post by Giovanni »

Hi,

There should be no need for that function call, the startup file handles initialization and finalization functions by itself. Are those initializers correctly caught by rules.ld? you need to look at the map file.

Giovanni
baoshi
Posts: 9
Joined: Wed May 15, 2013 5:49 am
Been thanked: 1 time

Re: Semihosting with newlib freeze

Post by baoshi »

No, I checked, not existing in map file.
While from a SDK build, I can see
c:/apps/armgcc/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv6-m\libc_nano.a(lib_a-init.o)
c:/apps/armgcc/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv6-m/rdimon-crt0.o (__libc_init_array)
in the map file.

I did something wrongly?
Attachments
ch.zip
map file
(25.1 KiB) Downloaded 664 times
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Semihosting with newlib freeze

Post by Giovanni »

This is how that function works:

http://stackoverflow.com/questions/1526 ... init-array

In you case the initialization arrays are empty, functions in the array are called by the startup file:

Code: Select all

constructors    0x080000c0        0x0
                0x080000c0                __init_array_start = .
 *(SORT(.init_array.*))
 *(.init_array)
                0x080000c0                __init_array_end = .


What is the function to be called that isn't called exactly?
baoshi
Posts: 9
Joined: Wed May 15, 2013 5:49 am
Been thanked: 1 time

Re: Semihosting with newlib freeze

Post by baoshi »

I dig in a little further and it seems freeze at
std.isra()

call stack was
std.isra()
__sinit()
_puts_r()
puts()
main()

I have no clue what is missing here.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Semihosting with newlib freeze

Post by Giovanni »

You could look at the source code. Newlib is open source.

Also consider stack overflows, that trace is pretty deep.

Giovanni
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: Semihosting with newlib freeze

Post by DeusExMachina »

Have anybody solved this problem with semihosting? I have converted on-board st-link to j-link, added --specs=rdimon.specs to makefile and call initialise_monitor_handles(); on startup. However, printf hangs up and nothing is out on the monitor side.
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: Semihosting with newlib freeze

Post by DeusExMachina »

Chibios definetely has some conflict with newlib, since on bare metal semihosting works fine with openocd and st-link/jlink (I was even able to use gprof for profiling an embedded target). I checked both F072 and F407 bare metal targets which worked with minimal modifications.
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: Semihosting with newlib freeze

Post by DeusExMachina »

Just thought that it would be really cool to have an embedded console output via semihisting debugging interface... No mess with USB2UART adapters or USB drivers... And it works only when debugger is attached! No user interference is possible. It is even possible to open files on PC side and write data down as GPROF does!
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Semihosting with newlib freeze

Post by Giovanni »

Hi,

ChibiOS does not interact with newlib unless syscalls.c is included. I don't see how it can block something to work in the library.

Giovanni
Post Reply