SOLVED: [SLOEBER] program crashes

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

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

Post by Pito » Wed Aug 16, 2017 6:17 pm

Roger's latest repo , downloaded 10mins back, default opt, Sloeber, F1, MapleMini

Code: Select all

Allocating EXRAM32 memory..
@Rick: could you post your results (full) with the test sketch pls? (BEFORE YOU DELETE THIS THREAD).. (deleting is easy).
Pukao Hats Cleaning Services Ltd.

User avatar
Rick Kimball
Posts: 1014
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 6:23 pm

Here is the code I tested. The results are visual. I allocated two things. One a class and the other a buffer. I used the debugger to look at the addresses returned and the values that are populated in the allocated memory.

Code: Select all

class dumbclass {
  int foo;
  int bar;
  int counter;

public:
  dumbclass(void) : foo(0),bar(0), counter(100) {
  }

  int getDelay() {
    counter = (counter == 100 ) ? 900 : 100;
    return counter;
  }
};

char *buffer;
dumbclass *dumb;

void setup() {
  pinMode(LED_BUILTIN,OUTPUT);

  buffer = (char *)malloc(1024);

  buffer[0] = 'a';
  buffer[1023] = 'z';
  buffer[4] = 100;

  dumb = new dumbclass;
}

void loop() {
  digitalWrite(LED_BUILTIN,LOW);
  delay(dumb->getDelay());
  digitalWrite(LED_BUILTIN,HIGH);
  delay(900);

  buffer[1] = (buffer[1] == 10) ? 255 : 10;
}
And some debug values:

Code: Select all

(gdb) p buffer
$7 = 0x20000f90 "a\n"
(gdb) p buffer[0]
$8 = 97 'a'
(gdb) p buffer[1]
$9 = 10 '\n'
(gdb) p buffer[1023]
$10 = 122 'z'
(gdb) p &buffer[1023]
$11 = 0x2000138f "z"
(gdb) p &buffer[0]
$12 = 0x20000f90 "a\n"
....

(gdb) p dumb
$15 = (dumbclass *) 0x20001398
(gdb) p *dumb
$16 = {foo = 0, bar = 0, counter = 100}

-rick

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

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

Post by Pito » Wed Aug 16, 2017 6:25 pm

No, Rick, you mess this thread and you introducing a chaos :)
We asking our colleagues since ever tho run the above malloc test called BubbleSort.
Just run it and give us your results pls.
We appreciate your effort.
Pukao Hats Cleaning Services Ltd.

User avatar
Rick Kimball
Posts: 1014
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 6:33 pm

Please post the code that works with a BluePill
-rick

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

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

Post by Pito » Wed Aug 16, 2017 6:42 pm

Rick, pls be so kind and first read this thread carefully, before you decide TO DELETE IT.
There is all information required you would need to practically help Bill with his issue.
Pukao Hats Cleaning Services Ltd.

User avatar
Rick Kimball
Posts: 1014
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 6:50 pm

OK I was focused on kostbill's posts ... and the answers were all over the map ...

I found the thread where you posted a link to a demo bubble sort. I tested it and it works fine:

Code: Select all

Allocating EXRAM32 memory..
536874888
********
Generating 4000 32bit uints:
Checksum of generated random numbers: 3737197177307
Checksum of unsorted EXRAM32 content: 3737197177307
BubbleSorting 32bit uints:
Wait while BubbleSorting.. Loops 0 out of 4000
Wait while BubbleSorting.. Loops 1000 out of 4000
Wait while BubbleSorting.. Loops 2000 out of 4000
Wait while BubbleSorting.. Loops 3000 out of 4000
Elapsed: 2173  msecs
Checksum of sorted numbers: 3737197177307
Sorted last 10 in ascending order:
3990 1994165868
3991 1994355317
3992 1994787653
3993 1994815262
3994 1994870290
3995 1996675596
3996 1996946895
3997 1997629299
3998 1998548949
3999 1999650861
I don't think there is anything wrong with stm32duino/libmaple and its malloc.
-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 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?

User avatar
Rick Kimball
Posts: 1014
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 6:57 pm

Pito wrote:
Wed Aug 16, 2017 6:25 pm
We asking our colleagues since ever tho run the above malloc test called BubbleSort.
BTW: There is nothing special about your BubbleSort test compared to what I tested. Both allocate memory and verify that it gets allocated.
-rick

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 6:59 pm

In Eclipse the syscalls.c seems to be not compiled in.
If I force it:

Code: Select all

extern "C" void *_sbrk(int incr);

void setup() {
    _sbrk(0); // If I comment this out, no blinking

    Serial.begin(115200);
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    delay(1000);

    Serial.println((uint32_t)malloc(1));
}
than it malloc seems to work.

Libmaple, Eclipse/sloeber, Maple Mini.

The same code normally (without explicit call to _sbrk(0);) works in Arduino IDE.

User avatar
Rick Kimball
Posts: 1014
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: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.

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.
-rick

Post Reply