Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Software size is too big

Hello guys, i've tried small C lib, reduced device drivers and everything else but nothing works..

I am using Quartus V10.0SP1 and NIOSEDS V10.0SP1, A hello word simple program with a printf takes 4k of onchip mem... that's impossible right? I must be doing something wrong.

It's the hello word example when creating a new project

# include <stdio.h>
int main()
{
printf(" Hello world!");
return 0;
}

It always overlap the sections .rwdata, heap and others.. Even if my onchipmemory is 10K Bytes.

17 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    And when i start the program sometimes getchar() get some random numbers..

    --- Quote End ---

    Use getchar() at the beginning of your code to make the char buffer empty.

    while (getchar() != EOF)

    /* wait */;
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Oh, you really don't want to be using gets() - it will write past the end of your buffer at some point!

    The normal recommendation is to use fgets(), but that may not be appropraite here - your own loop calling getchar() is probably better.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Use getchar() at the beginning of your code to make the char buffer empty.

    while (getchar() != EOF)

    /* wait */;

    --- Quote End ---

    it seems like i never get end of file.. the program never comes back.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Mmm... I do the same and works fine.

    Maybe you have some device which continously puts data on stdin?

    Have you considered if the received chars show you some hint? Or are they completely random?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    They are completly random. I have some optimization configuration in my project.. the ones i posted in the 1st page, maybe it has something to do with it?

    Here

    template BSP/syslib:
    - uncheck  Support C++ em properties->C/C++ Build do BSP Template 
    - check Lightweight device driver no BSP Editor
    - check Reduced device drivers no BSP Editor
      - uncheck enable_clean_exit no BSP Editor
      - uncheck enable_exit no BSP Editor
      - configure  optimize level to Size on properties->C/C++ Build do BSP Template 
    - configure  Debug level to none on properties->C/C++ Build do BSP Template
      
    Software:
      - configure  optimize level to Size em properties->C/C++ Build do BSP Template 
    - configure  Debug level to none em properties->C/C++ Build do BSP Template
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    # include "sys/alt_stdio.h"
    # include <stdio.h>
    void put_uint(unsigned int x);
    int main()
    {
        unsigned int c;
        c=0;
        alt_putstr("Informe o bitrate e digite enter!\n");
         while (c!=10){
        c = getchar();
        put_uint(c);
        //alt_putchar(c);
          }
          return 0;
    }
    void put_uint(unsigned int x)
    {
        char b, *p = b + 9;
        unsigned int n;
        b = 0;
        do {
            n = x / 10;
            *--p = '0' + (x - n * 10);
        } while ((x = n) != 0);
        alt_putstr(p);
    }
    

    Is this how am i suposed to use your function? It shows a number for each keyboard key i touch but not the actual number that the key represents =p

    Sorry for this stupid questions but i am really new to the "low level" C..

    --- Quote Start ---

    something like (untested):

    void put_uint(unsigned int x)
    {
        char b, *p = b + 9;
        unsigned int n;
        b = 0;
        do {
            n = x / 10;
            *--p = '0' + (x - n * 10);
        } while ((x = n) != 0);
        alt_putstr(p);
    }
    will output an unsigned value to the terminal in decimal.

    The above will pull in the libc function to do divide (unless you added the hardware instruction and told gcc to use it).

    The 'divide by constant' can be replaced by a multiply and shift, but that requires the 64bit result from the multiply - which altera don't have support for on the older fpgas (needs the DSP based multiply) and might need a 64bit shift. Splitting the value into two 16bit values does make this possible (I've done that to avoid needing 64bit divide when converting 'long long'.)

    Writing printf() is just a SMOP (simple matter of programming).

    --- Quote End ---