Page 1 of 1

stack size

Posted: Mon Jan 09, 2012 3:09 am
by ChuckM
Ok silly n00b question but its buggin' me. I've been writing some addtional support for newlib so that I can use the stdio calls rather than the ch versions (things like printf, fread, etc) anyway, I've got a stubs file that does all the right stuff but newlib blows up the stack for the 'main' thread if you use it in there. I'd love to change the size of the initial stack for main (I can allocate a new stack for a new thread but argh)

--Chuck

Re: stack size

Posted: Mon Jan 09, 2012 6:47 am
by ChuckM
Ok, figured out how to change the stack size. (edit the linker script for my board change __main_stack_size__ from 0x400 to 0x1000)

But it still blows up if I try to call printf (as opposed to chprintf()). One would hope they could debug this with the STM utilities but alas on Linux they are sadly not very good.

--Chuck

Re: stack size

Posted: Mon Jan 09, 2012 11:53 am
by Giovanni
I think printf() tries to allocate memory internally so you have to make sure that all the newlib interfaces are working.

Giovanni

Re: stack size

Posted: Mon Jan 09, 2012 8:38 pm
by ChuckM
Well, on the newlib site they suggest you need to implement the basic system calls.

http://sourceware.org/newlib/libc.html#Stubs

I implemented them and added my own 'mini-heap' (statically allocated) so that presumably the malloc implementation would work correctly. I'll upload the stubs later (basically I copied this example and then for open added dev-entry structure which basically held a BaseChannel pointer. And my implementation of write then took that pointer and did chPutIO's on it. However, I don't get there. (using LED debugging :-))

--Chuck

Re: stack size

Posted: Mon Jan 09, 2012 8:47 pm
by Giovanni
Note that you don't have to have a dedicated heap, you may use chCoreAlloc() and feed the newlib allocator from the ChibiOS heap.

Giovanni