- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I can't solve the problem with using float in family of printf() functions in my C project.
I use EZ-USB SDK 1.3 with SUPERSPEED EXPLORER KIT.
I want to use sprintf() and vsprintf() (with va_list) for creating debug messages.
But when i add printf() family functions into my project, I receive linker error (picture 1):
Picture 1
I read in different forums, that for using float int printf() there are two ways:
1. Add to my project cyfxcppsyscall.cpp file (with _sbrk definition) and #include <sys/unistd.h> file, where using sprintf().
Also add __heap_start and __heap_end definition in fx3.ld linker file.
It's not work - i also see undefined reference to '_sbrk'
2. Add linker flags: -specs=nosys.specs -specs=nano.specs -u _printf_float
See page:
In second
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Alexdobrikov-san,
I've just skimmed "cyfxcppsyscall.cpp", it seems to be a "c" source file,
but the extension ".cpp" may suggest c++.
So in case c++ (or g++) is called to compile this source file
the symbols will be quite different from what "c" is expecting.
I'd suggest you to try following (if you don't mind)
if any of these solves the problem.
(1) remove this source file from your project
(2) rename this source file to cyfxcppsyscall.c
(3) add "extern "C" { " and "}" at the beginning and the end of this source file.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
May be this is not your expecting answer, but I usually do something like
====================
float f_value ;
char sign = ' ' ; /* a space */
...
if (f_value < 0) {
sign = '-' ; /* minus */
f_value = -1.0 * f_value ;
}
sprintf(str, "%c%d.%02d", sign, (int)f_value, ((int)(100 * f_value + 0.5))%100) ;
====================
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, thank you for answer.
I want to use printf() family in situation something like this:
void UART_printf(char *arg_list, ...)
{
va_list arg_buffer;
va_start(arg_buffer, arg_list);
memset(uart_printf_buf, 0, sizeof(uart_printf_buf));
vsprintf(uart_printf_buf, arg_list, arg_buffer);
va_end(arg_buffer);
}*/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Alexdobrikov-san,
So, in your context, does this work?
====================
float f_value = 0.5 ;
char sign = ' ' ; /* you may not need this, if you don't get negative value */
if (f_value < 0.0) {
f_value = -1.0 * f_value ;
sign = '-' ;
}
counter = sprintf(&t->buffer[t->in], "%c%d.%02d",(int)f_value, ((int)(100 * f_value + 0.5) % 100) ;
====================
And with this method, you don't have to modify the compiler flags from the default, I hope.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Problem in sprintf():
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if i comment sprintf(), problem with _sbrk() get out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Alexdobrikov-san,
Can you at least remove -u _printf_float flag? others also may count...
Then could you try Clean and Build the project?
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I restore linker flags...
But have the same problem with undefined _sbrk()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Alexdobrikov-san,
I've just skimmed "cyfxcppsyscall.cpp", it seems to be a "c" source file,
but the extension ".cpp" may suggest c++.
So in case c++ (or g++) is called to compile this source file
the symbols will be quite different from what "c" is expecting.
I'd suggest you to try following (if you don't mind)
if any of these solves the problem.
(1) remove this source file from your project
(2) rename this source file to cyfxcppsyscall.c
(3) add "extern "C" { " and "}" at the beginning and the end of this source file.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Alexdobrikov-san,
In case, none of trials in my previous message worked,
could you restore your project to the condition before you tried to add float printf?
Then add "#include <stdio.h>" and my method, which does not require any float
printf/sprintf operation and try if it works for you?
Best Regards,
16-Nov-2018
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Mr. Motoo Tanaka!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd suggest you to try following (if you don't mind)
if any of these solves the problem.
(1) remove this source file from your project
(2) rename this source file to cyfxcppsyscall.c
(3) add "extern "C" { " and "}" at the beginning and the end of this source file.
It works!!!)
My mistake was that i add in project cyfxcppsyscall.cpp file , but must add .c file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Alexdobrikov-san,
I think that now it's not the problem of the source code,
but the compiler flags you modified.
By any chance, can you restore the compiler flags before you modified them?
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
some problems with my pale-moon...
In second way if i add linker flags, i see picture 3:
Picture 3
Error1 make
And i don't understand what i must do with this error?