SOLVED: [SLOEBER] program crashes

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
victor_pv
Posts: 1739
Joined: Mon Apr 27, 2015 12:12 pm

Re: SOLVED: [SLOEBER] program crashes

Post by victor_pv » Thu Aug 17, 2017 1:44 pm

@Roger, Rick, there is more to this, from the Arduino IDE standpoint.
From what I see Arduino IDE had the same problem not including syscalls_sam3.c for the SAM cores, instead of using whole-archive like we did for some time, they were forcing syscalls_sam3.c.o in the parameters to the linker.
Then eventually they found another way around, and is what's implemented in their platform.txt file.
This thread shows how and why they were doing it first (forcing the file to be included by the linker)
https://github.com/arduino/Arduino/comm ... e22a101e7e

This show when they found a different way around, using a new set of flags for the linker:
https://github.com/arduino/Arduino/pull/4810

We did not have those flags, but someway in Arduino IDE we are lucky enough that syscalls get linked while for the SAM it was not linking.

I tested adding the same flags, and it works. I get these 2 addresses for buffer and dumb in Rick's example, which match with where my heap is:
20000C0C
20000C10

Whether we want to include this in the main repo, I don't care, but I wanted to post here for everyone that uses Sloeber, and in case any future change to the Arduino ide, the source or anything results in syscalls.c not being linked with Arduino either, so hopefully we can find this post.

I will update the first post with this additional solution for anyone using Eclipse or another IDE facing the issue.

User avatar
Rick Kimball
Posts: 1056
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: SOLVED: [SLOEBER] program crashes

Post by Rick Kimball » Thu Aug 17, 2017 1:56 pm

victor_pv wrote:
Thu Aug 17, 2017 1:44 pm
We did not have those flags, but someway in Arduino IDE we are lucky enough that syscalls get linked while for the SAM it was not linking.
It works in Arduino for our core because syscalls.c is in the variant subdirectory. Any .c files in the variant sub directory are linked as objects not as a library. Those objects are placed in the linker command line before the library references. See the {objects_files} in the combine recipe

recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group {object_files} "{build.path}/{archive_file}" -Wl,--end-group

Because of this we don't need to resort to doing the -u trick or any other tricks.

Code: Select all

$ find variants/ -iname 'syscalls.c'
...
variants/generic_stm32f103c/wirish/syscalls.c
...
-rick

victor_pv
Posts: 1739
Joined: Mon Apr 27, 2015 12:12 pm

Re: SOLVED: [SLOEBER] program crashes

Post by victor_pv » Thu Aug 17, 2017 2:29 pm

They do have the objects file in their recipe too, but perhaps they have more than they need:

recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={build.mcu} -mthumb {compiler.c.elf.flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group {compiler.combine.flags} {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc

User avatar
Rick Kimball
Posts: 1056
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: SOLVED: [SLOEBER] program crashes

Post by Rick Kimball » Thu Aug 17, 2017 2:37 pm

I haven't looked at the sloeber code in detail, however I see from your post they added this:

... {build.variant.path}/{build.variant_system_lib} ...

I'm going to guess that they take the files in the variant subdirectory and put them into a library instead of adding each .o file to the the object_files variable.
-rick

victor_pv
Posts: 1739
Joined: Mon Apr 27, 2015 12:12 pm

Re: SOLVED: [SLOEBER] program crashes

Post by victor_pv » Thu Aug 17, 2017 6:53 pm

To clarify, that's the recipe for the DUE in Arduino, in the platform.txt file, not something specific to Sloeber.
I'll have to check what do they have as library, but I know there is a syscall_sam3.c file with the functions in one of the folders.
One other difference with our code, they have a syscalls.h header file, while we don't, but even without that file if I add the "-u..." flags, syscall was being included correctly and the sketch running without crash.

User avatar
Pito
Posts: 1627
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: SOLVED: [SLOEBER] program crashes

Post by Pito » Thu Aug 31, 2017 9:42 am

@Victor: Thanks!!! :)
With adding the {compiler.combine.flags} -u flags into platform.txt the malloc() now works with latest Libmaple and F1 (ie. F103ZE) under Sloeber.
Pukao Hats Cleaning Services Ltd.

luca_stm32
Posts: 23
Joined: Wed Apr 26, 2017 12:39 pm

Re: SOLVED: [SLOEBER] program crashes

Post by luca_stm32 » Wed Nov 22, 2017 8:15 pm

I'm using ESP8266 library from here: https://github.com/bportaluri/WiFiEsp
I'm using Bluepill and Sloeber, but when I load the scketch on STM32, the micro crashes (with Arduino IDE the schetck works).
I found the problem: ringbuffer function use new function:

Code: Select all

RingBuffer::RingBuffer(unsigned int size)
{
	_size = size;
	// add one char to terminate the string
	ringBuf = new char[size+1];  <---- !
	ringBufEnd = &ringBuf[size];
	init();
}
If I declare ringBuf as array, the scketch works.

@Pito: I would like to add {compiler.combine.flags} -u in platform.txt as you did. Can you show me exactly where I have to insert the string inside platform.txt?
Thanks.
Regards.
Luca

Post Reply