Hi,
following sprintf-function does not work in HiTop 5.20.0424 for NetStick (NXHX-500RE):
include
void main( void )
{
char cStr[ 255 ];
float fVal = 456.787;
sprintf( cStr, "%f", fVal );
while(1){}
}
The contents in cStr does not contain "456.787" but rather different characters (rubbish only).
sprintf with integer (%i) works well.
Regarding any questions:
1.) Why does sprintf with floating point not work, but the integer one?
2.) The compiler message said:
Include module "sprintf"
WARNING: No sourcefile found:
\GccSources\newlib-1.14.0\newlib\libc\stdio\sprintf.c
I have downloaded the newlib-1.14.0 from web, but where should I copy this library to?
I cannot found the directory or entry 'GccSources' in HiTOP.
Do I need this library?
Regards
micha1975er
Hi,
When the implementation of working sprintf function is done, I will post my feeling of success.
Thanks for comments ( :) )
Best regards
micha1975er
Hilscher Gesellschaft für Systemautomation mbH
Just to give you a little hint on how to modify sbrk to fit your needs, take a look at the following code:
#include#include extern char _heap_start; /* Defined by the linker */
extern char _heap_end; /* Defined by the linker */
static char* s_pchHeapEnd = &_heap_start;
static char* s_pchHeapMax = &_heap_end;caddr_t sbrk(size_t iIncr)
{
caddr_t pvBase = (caddr_t)-1;if( (s_pchHeapEnd + iIncr) <= s_pchHeapMax)
{
pvBase = s_pchHeapEnd;
s_pchHeapEnd += iIncr;
}return pvBase;
}caddr_t _sbrk_r(struct _reent* ptReent, size_t iIncr)
{
caddr_t pvBase = (caddr_t)-1;if( (s_pchHeapEnd + iIncr) <= s_pchHeapMax)
{
pvBase = s_pchHeapEnd;
s_pchHeapEnd += iIncr;
}return pvBase;
}
NOTE: memory allocation will not be thread safe. To make it threadsafe functions like __malloc_lock / unlock need to be implemented.
NOTE2: When using the reset registers script, the memory allocation will not be reset. To start from scratch you will always need to re-download the elf file to initialize all global variables inside the C-Library.
Regards
MT
M T
Hilscher Gesellschaft für Systemautomation mbH
Floating point conversion needs a working malloc implementation. You will need to implement an appropriate "sbrk_r" function for the malloc of newlib to work. (see syscalls in the newlib documentation). Without malloc floating point conversion will not work.
The library already comes with the compiler. I don't know where you downloaded it, but you won't be able to use another pre-compiled library with the compiler. It is built during cross-compiler-generation. GccSources is the path, where newlib was compiled at. HiFlop is not able to override this path and so you will need to place the source in the same folder, where it was at compile time at Hitex.
BTW: The library is compiled as release and I am sure, you won't see very much when trying to step through it, without some experience in ARM assembler and compiler optimizations.
Regards
MT