SOLVED: [SLOEBER] program crashes

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
kostbill
Posts: 51
Joined: Mon Aug 07, 2017 7:56 am

Re: Libmaple problem, program crashes with call to malloc.

Post by kostbill » Wed Aug 16, 2017 7:19 pm

Rick Kimball wrote:
Wed Aug 16, 2017 7:01 pm
kostbill wrote:
Wed Aug 16, 2017 6:56 pm
Rick,
What repository did you use? Roger's or Daniel's?
Also, the latest versions?
Also, in what IDE are you working on?
I ask again @kostbill:

Have you tried Roger's core (stm32duino the libmaple one) with your blue pill running in the Arduino IDE? This core:
https://github.com/rogerclarkmelbourne/Arduino_STM32

I just tried the lastest core with a malloc test program and it works fine.

@kostbill Please explain your current setup and the problem with it or this thread will be deleted.
Rick, all your questions are answered here but I will write them again.

- I am working on a BluePill.
- I am using Sloeber, 4.01 and 4.10.
- Malloc does not work. I am working with Pito's bubblesort.
- When I am using Roger's latest. It doesn't work on Sloeber. IT DOES WORK on Arduino IDE.
- When I am using Daniel's repository, it works on Sloeber.
- When I am using one of Roger's older repositories, it still doesn't work on Sloeber.
- In all the cases that it doesn't work, I am programming with JTAG or Serial upload.
- Also, in all the cases that it doesn't work, I am running the program normally and I am debugging it.

If I omitted something let me know, I don't think it is necessary to delete this thread.
You can't expect me to summarize everything I wrote in the last 6 pages in every new post I am writing.

kostbill
Posts: 51
Joined: Mon Aug 07, 2017 7:56 am

Re: Libmaple problem, program crashes with call to malloc.

Post by kostbill » Wed Aug 16, 2017 7:21 pm

victor_pv wrote:
Wed Aug 16, 2017 5:23 pm
What version of the core is the oldest you have tried? (like the date, or link on github)
I don't know how to find the date. How can I find the oldest one?
and can you post the simplest sketch that causes the crash for you and the board you select?
Any sketch that uses a malloc will do, you may use Pito's bubblesort:
http://www.stm32duino.com/viewtopic.php ... 839#p27839
About what to look at the ld files, just check if for the board you are using the flash and ram start addresses and size are correct, and then check in the repo the history for those files for that board to see when was the last change and what was it.
OK, so per your advice I checked some things and I found something, perhaps it is something useful:
BluePill has 20KB of SRAM.
In some of these scripts, we find that ram(rwx) provides only 17K:
https://github.com/rogerclarkmelbourne/ ... /ram_c8.ld,
https://github.com/rogerclarkmelbourne/ ... em-ram.inc,
https://github.com/rogerclarkmelbourne/ ... -flash.inc

Code: Select all

MEMORY
{
  ram (rwx) : ORIGIN = 0x20000C00, LENGTH = 17K
  rom (rx)  : ORIGIN = 0x08005000, LENGTH = 0
}
and in some of them 20K:
https://github.com/rogerclarkmelbourne/ ... m-jtag.inc,
https://github.com/rogerclarkmelbourne/ ... jtag_c8.ld

Code: Select all

MEMORY
{
  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
  rom (rx)  : ORIGIN = 0x08000000, LENGTH = 64K
}
I am not sure which of these are used and which ones are not used.
By googling around I found one of Roger's posts which mentioned something about 3 kbytes but I don't remember if it was in SRAM or Flash and I cannot find it again :( .

Do you think that this could be an issue here?

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

Re: Libmaple problem, program crashes with call to malloc.

Post by Rick Kimball » Wed Aug 16, 2017 7:27 pm

kostbill wrote:
Wed Aug 16, 2017 7:19 pm
- When I am using Roger's latest. It doesn't work on Sloeber. IT DOES WORK on Arduino IDE.
So malloc works fine with the Arduino IDE.

If you use Roger's latest repository and the Arduino IDE and compile the example code with your KnxDevice and CLI modified libraries does that work?
-rick

kostbill
Posts: 51
Joined: Mon Aug 07, 2017 7:56 am

Re: Libmaple problem, program crashes with call to malloc.

Post by kostbill » Wed Aug 16, 2017 7:28 pm

Rick Kimball wrote:
Wed Aug 16, 2017 7:01 pm
Also, I just went through all the posts in this thread and I don't see anywhere that you have posted the changes you made to the KNX_Device or the CLI libraries. Please post those if you want help.
It really doesn't matter about the KNX changes. The problem is the malloc, which crashes even without the KNX library, in a fresh, clean repository without me even adding the KNX library.
The KNX library works nice when I compile with the Arduino IDE.

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

Re: [SLOEBER] Libmaple F1 problem, program crashes with call to malloc.

Post by Rick Kimball » Wed Aug 16, 2017 7:31 pm

Do the people at Sloeber provide support for all the various arduino cores it uses?
-rick

kostbill
Posts: 51
Joined: Mon Aug 07, 2017 7:56 am

Re: [SLOEBER] Libmaple F1 problem, program crashes with call to malloc.

Post by kostbill » Wed Aug 16, 2017 7:37 pm

Rick Kimball wrote:
Wed Aug 16, 2017 7:31 pm
Do the people at Sloeber provide support for all the various arduino cores it uses?
I don't know, I didn't ask anyone else, this forum is the first I am asking.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: Libmaple problem, program crashes with call to malloc.

Post by danieleff » Wed Aug 16, 2017 7:43 pm

kostbill wrote:
Wed Aug 16, 2017 7:28 pm
The problem is the malloc, which crashes even without the KNX library, in a fresh, clean repository without me even adding the KNX library.
The KNX library works nice when I compile with the Arduino IDE.
Have you read my post? viewtopic.php?f=41&t=2434&start=50#p33027

I guess this is a library order issue in the gcc linker step http://www.network-theory.co.uk/docs/gc ... ro_18.html , and _sbrk is defined somewhere weakly that crashes which is why no compiler error.

kostbill
Posts: 51
Joined: Mon Aug 07, 2017 7:56 am

Re: Libmaple problem, program crashes with call to malloc.

Post by kostbill » Wed Aug 16, 2017 7:55 pm

danieleff wrote:
Wed Aug 16, 2017 7:43 pm
kostbill wrote:
Wed Aug 16, 2017 7:28 pm
The problem is the malloc, which crashes even without the KNX library, in a fresh, clean repository without me even adding the KNX library.
The KNX library works nice when I compile with the Arduino IDE.
Have you read my post? viewtopic.php?f=41&t=2434&start=50#p33027

I guess this is a library order issue in the gcc linker step http://www.network-theory.co.uk/docs/gc ... ro_18.html , and _sbrk is defined somewhere weakly that crashes which is why no compiler error.
No Daniel I didn't, the truth is that I was a bit stressed because Rick was going to delete the thread and then I was not going to be able to read it and then I forgot.

But now that I read it and tested it, it seems to be working.
The first try was not successful, but I cleaned the project and it works!

Thank you very much Daniel!
Thanks everyone for their help.
Bill.

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

Re: [SLOEBER] Libmaple F1 problem, program crashes with call to malloc.

Post by Rick Kimball » Wed Aug 16, 2017 8:01 pm

So I installed Sloeber V4. When I compile a simple malloc test ... it appears to succeed .. however if you look at the console messages it is failing
Starting combiner
"arm-none-eabi-g++" -Og -Wl,--gc-sections -mcpu=cortex-m3 "-T/home/kimballr/Arduino/hardware/stm32duino/STM32F1/variants/generic_stm32f103c/ld/jtag.ld" "-Wl,-Map,/home/kimballr/workspace_neon3/malloc_test/Release/malloc_test.map" "-L/home/kimballr/Arduino/hardware/stm32duino/STM32F1/variants/generic_stm32f103c/ld" -o "/home/kimballr/workspace_neon3/malloc_test/Release/malloc_test.elf" "-L/home/kimballr/workspace_neon3/malloc_test/Release" -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 ./.ino.cpp.o /home/kimballr/workspace_neon3/malloc_test/Release/arduino.ar /home/kimballr/workspace_neon3/malloc_test/Release/arduino.ar -Wl,--end-group
/usr/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/thumb/v7-m/libnosys.a(sbrk.o): In function `_sbrk':
sbrk.c:(.text._sbrk+0x18): warning: undefined reference to `end'
Finished building: malloc_test.
However it just goes along its merry way even though end is used by _sbrk

If I used gdb to see what happens ...

Code: Select all

(gdb) finish 
Run till exit from #0  0x0800311e in _malloc_r ()
0x0800016a in setup () at ../malloc_test.ino:31
31	  buffer = (char *)malloc(1024);
(gdb) n
33	  buffer[0] = 'a';
(gdb) p buffer 
$1 = 0x20000010 <usblib+4> ""
(gdb) p &usblib
usblib      usblib_dev  
(gdb) p &usblib
$2 = (usblib_dev *) 0x2000000c <usblib>
(gdb) p &buffer
$3 = (char **) 0x20000c14 <buffer>
(gdb) p *buffer
$4 = 0 '\000'
(gdb) p buffer
$5 = 0x20000010 <usblib+4> ""
(gdb) 
The malloc returns the address that is being used by usblib+4 ... It is basically walking all over itself ...
-rick

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

Re: [SLOEBER] Libmaple F1 problem, program crashes with call to malloc.

Post by Rick Kimball » Wed Aug 16, 2017 8:15 pm

@kostbill, you need to modify your common.inc and add the 'end' symbol for this to work with Sloeber. Sloeber isn't using the same linker command line as the Arduino IDE. This produces a different binary and linking order from the Arduino IDE version, at least for the STM32F1 series. I have no idea about other cores or boards.

$ grep 'end =' /home/kimballr/Arduino/hardware/stm32duino/STM32F1/variants/generic_stm32f103c/ld/common.inc
_end = __bss_end__;
end = _end; <<<<<< I added this line

After you compile with this change the linker should be happy and not complain about a missing 'end' symbol.
If you use the nm command you should find the 'end' symbol as some address in your RAM address that is greater than the highest data and bss address

$ arm-none-eabi-nm -CS malloc_test.elf | grep 'B end'
20000f88 B end

This is not a problem with Roger's repository nor is a problem with malloc. This problem is being caused by the way Sloeber is working. It is also a problem in that a major error happened and Sloeber doesn't report it.

Please change the title of this thread to indicate that it is not an libmaple F1 malloc problem.

'Sloeber is dumb and has a problem' might be apt
-rick

Post Reply