Newlib, syscall.c and printf

Hard Maker hardmaker@gmail.com
Wed Feb 9 14:28:00 GMT 2011



El 08/02/2011 05:37 p.m., Federico Terraneo escribió:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 02/08/2011 04:38 PM, Hard Maker wrote:
>> Thank's for your answer Federico,
>>
>> I try with 8192 bytes of stack and this code and printf not work.
>>
>> extern unsigned int _HEAP_START;
>> extern unsigned int _HEAP_END;
>> int main(void)
>> {
>>      char txt[20];
>>      float fVal = 3.141596;
>>      setvbuf(stdin, NULL, _IONBF, 0);
>>      setvbuf(stdout, NULL, _IONBF, 0);
>>      setvbuf(stderr, NULL, _IONBF, 0);
>>
>>      InitHW();
>>
>>      lcd_gotoxy(0,0);
>>      snprintf(txt, 20, "Start: %X", (unsigned int)&_HEAP_START);
>>      _write(0, txt, strlen(txt));    // work
>>
>>      lcd_gotoxy(0,1);
>>      snprintf(txt, 20, "End:   %X", (unsigned int)&_HEAP_END);
>>      lcd_print(txt); // work
>>
>>      lcd_gotoxy(0,2);
>>      printf("Hi %.2f\n", fVal);    // not work
>>      fflush(stdout);
>>      while (1)
>>          ;
>>      return 0;
>> }
>>
>> Thank's for your answer.
>>
>> Sergio
>>
>> El 08/02/2011 11:03 a.m., Federico Terraneo escribió:
>> On 02/08/2011 02:23 PM, Hard Maker wrote:
>>>>> I'm using 1 KB of system stack and have 60KB free of heap. Anyone has
>>>>> this problem?
>>>>>
>> Hi, I'm not a newlib developer, just an user.
>> I've been using newlib with stm32 for quite some time, and printf works,
>> but takes up nearly 2KB of stack. Maybe the problem is this.
>>
>>
> Are you copying .data from flash to ram, and clearing .bss before
> calling main?
> To check, try to declare two global variables and print them, like this:
>
> #include<stdio.h>
>
> int a=12345; //Ends up in .data
> int b=0;     //Ends up in .bss
>
> int main()
> {
>      //Print a and b
> }
>
> If they don't have the right value, that's the problem.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQEcBAEBAgAGBQJNUal7AAoJECkLFtN5Xr9fkxYIAIHJRq6QlD06R3Rs5Ri6yEtf
> qlBdnRevFBbNNC880fMCmpZ6iYLFfILs5O35nOkD3LvvqE+LXN9o9xZyfX2N0mIQ
> R1mjtgiB9Bhqs0cDreTmlcyLv96eCrjWOXpsyAJMBseUkK4GT7gao0TvZFFXi2Xn
> q/5Cvdm2B3VOCoFKbGB4JM2m/v0N0JvK4OwLnW2tZd5S8J4OiyquPfgYsyNujOVH
> j5PCueSi6IBjV5hOi089PeYRWCYriwGtA+sve7+qqFv0MUNdkFtyostjW60b0UnB
> fVbpFjHqDso0hYmCDh0HJ3RH7L4HMGvr/0dwApClBrSUCBEZFaD3T+1rTQ+2Wdw=
> =82hy
> -----END PGP SIGNATURE-----
This work fine. But I suspect  about the stack setup or linker script. 
When I build the aplication if stack space grows, the applicacion grows 
too. Using 64 bytes of stack, the application is 49652 bytes long. When 
the stack is 8192 bytes, the application size is 82164 byte. This is ok? 
I'm not sure, as I see the only diference is the size used in ram, there 
are not diference in application code. But I don't have experience using 
arm or newlib.

thank's again

Sergio



More information about the Newlib mailing list