chibiOS 3 'chHeapAlloc' usage

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

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

Re: chibiOS 3 'chHeapAlloc' usage

Post by Giovanni »

That assertions indicates that an attempt to release a mutex not owned.

Could you post the stack trace at that point?

Giovanni
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: chibiOS 3 'chHeapAlloc' usage

Post by JoVM »

This is a trace from the main thread.

Code: Select all

#0  chSysHalt (reason=reason@entry=0x80036f0 <__func__.6584> "chMtxUnlock")
    at ../../../os/rt/src/chsys.c:164
#1  0x08001262 in chMtxUnlock (mp=mp@entry=0x20001630 <default_heap+16>)
    at ../../../os/rt/src/chmtx.c:327
#2  0x080018e2 in chHeapAlloc (heapp=0x20001620 <default_heap>,
    heapp@entry=0x0, size=size@entry=64) at ../../../os/rt/src/chheap.c:185
#3  0x08002b40 in initWithSizeAndIncRate (list=0x200007e8,
    list@entry=0x200007c8, size=size@entry=16, rate=rate@entry=50)
    at ArrayList.c:26
#4  0x08002b68 in initWithSize (size=16, list=list@entry=0x200007c8)
    at ArrayList.c:19
#5  init (list=list@entry=0x200007e8) at ArrayList.c:14
#6  0x080001e4 in main () at main.c:96

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

Re: chibiOS 3 'chHeapAlloc' usage

Post by Giovanni »

It makes no sense. Heap allocator is used in a lot of places so it cannot just fail that way, there must be something else not so evident.

Giovanni
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: chibiOS 3 'chHeapAlloc' usage

Post by JoVM »

@Giovanni: :D Is the mutex not owned by the thread? How can I check this?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chibiOS 3 'chHeapAlloc' usage

Post by Giovanni »

It cannot be not taken because chHeapAlloc() does that at very beginning....

This makes me think the problem is not so obvious. Do you use allocator functions in other places of the code? is it possible you have stack overflows?

Giovanni
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: chibiOS 3 'chHeapAlloc' usage

Post by JoVM »

OOOhhhh, I use alloc before halinit and chSysInit. I think this is a bad idea.

My __main_stack_size__=0x400. So I think I'm save here on stack size.
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: chibiOS 3 'chHeapAlloc' usage

Post by JoVM »

Sorry for the uphold. :oops:
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chibiOS 3 'chHeapAlloc' usage

Post by Giovanni »

Definitely a bad idea :)

Giovanni
Post Reply