Alternative to sprintf?


#1

I noticed using sprintf increases the code size tremendously (~20kb or so).
Is there an alternative in chibios using less memory or pulling in fewer libs?
It is for OLED display.

Maybe I am missing something?

Thanks in advance

I have seen this kind of workaround in several places. I guess I have to use that?

if (value != pvalue) {
    int i = value;
    int i0 = i/10;
    c[offset+2] = '0'+i-10*i0;
    i = i0;
    i0 = i/10;
    c[offset+1] = '0'+i-10*i0;
    i = i0;
    i0 = i/10;
    c[offset+0] = '0'+i-10*i0;
    // Make sure there is a space between text and value
    c[offset-1] = ' ';
    pvalue = value;
}

#2

I don't know enough background information to come with a conclusive answer, but it seems to me that sprintf should be part of the Axoloti OS, the part which is flashed and remains the same regardless of the user patch. The STM32F427 chip has lots of Flash memory (1 megabyte) but precious little RAM where the patches live (256 kilobytes in total, of which not all is available for patches), so anything that does not have to be in RAM, such as library functions such as sprintf, should be in Flash memory.

So it seems a bit of an oversight in terms of the Axoloti OS. Then again I don't know, maybe there is a technical reason for this.

In response to your code question, it's certainly possible to do write code as in your example for a specific usecase, in some cases it can be an advantage if you need special treatment of certain values or want to print things out in a specialized way.