Semihosting with newlib freeze

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

Moderators: RoccoMarco, barthess

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

Semihosting with newlib freeze

Postby baoshi » Tue Jan 26, 2016 3:21 pm

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Semihosting with newlib freeze

Postby Giovanni » Tue Jan 26, 2016 3:33 pm

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

Postby baoshi » Tue Jan 26, 2016 4:17 pm

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 196 times

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Semihosting with newlib freeze

Postby Giovanni » Tue Jan 26, 2016 5:21 pm

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

Postby baoshi » Wed Jan 27, 2016 5:10 pm

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Semihosting with newlib freeze

Postby Giovanni » Wed Jan 27, 2016 5:15 pm

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
Location: South Korea
Has thanked: 3 times
Been thanked: 3 times

Re: Semihosting with newlib freeze

Postby DeusExMachina » Wed Nov 07, 2018 2:58 am

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
Location: South Korea
Has thanked: 3 times
Been thanked: 3 times

Re: Semihosting with newlib freeze

Postby DeusExMachina » Mon Nov 12, 2018 4:32 am

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
Location: South Korea
Has thanked: 3 times
Been thanked: 3 times

Re: Semihosting with newlib freeze

Postby DeusExMachina » Tue Nov 13, 2018 12:57 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Semihosting with newlib freeze

Postby Giovanni » Tue Nov 13, 2018 7:00 am

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


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 26 guests