vsprintf() doesn't build in USB EZ Suite

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

When I try to use vsprintf() in USB EZ Suite I get this error (during link) ...

undefined reference to `_sbrk'    SlaveFifoSync        line 0    C/C++ Problem

   

 

   

Here's an example function to test it with:

 

   

#include <stdio.h>
#include <stdarg.h>

   

void myDebug(int num, const char * format, ...)
{
    char buffer[256];
    CyU3PReturnStatus_t apiRetStatus;
    int    res;

   

    va_list args;

   

    va_start (args, format);
    res = vsprintf(buffer, format, args);

    if (res >= 0)
    {
        CyU3PUartTransmitBytes ((uint8_t *)&buffer, res, &apiRetStatus);
    }
    va_end (args);
}

   

 

   

If you comment out the vsprintf line, the error disappears, indicating that vsprintf is the culprit. 

0 Likes
5 Replies
Anonymous
Not applicable

Please make sure you are using a C++ project for this since the linker file for this is different from the one used for C projects and it has a runtime heap defined.

   

sprintf() internally calls _sbrk(), the definition of this can be found in the cyfxcppsyscall.cpp file inside the BulkLoopAutoCpp project in the SDK. Include this definition in your code.

0 Likes
Anonymous
Not applicable
        hi, Do not do what you want in the following function? CyU3PDebugStringPrint You mean, do you need the support of the number of floating-point format? I'm sorry I was wrong. I'm sorry. This English is machine translation. Thanks   
0 Likes
Anonymous
Not applicable

If you're suggesting to use CyU3PDebugStringPrint, then that's not working for me. I need the formatted string in a buffer, not output to a UART.

0 Likes
Anonymous
Not applicable

apiRetStatus = CyU3PDebugStringPrint((uint8_t *)buffer, 256, (char *)format, args); This is accommodated formatted string in the buffer. not output to the UART. This is similar to the name in the function to be output to the UART. e.g. CyU3PDebugPrint(4, buffer);

0 Likes
Anonymous
Not applicable

I actually 'fixed' it by implementing the _sbrk function in my own code.
The _sbrk function is supposed to extend the heap .. I didn't think that would ever by necessary in my case, so I just log a warning whenever the function actually gets called, and return an error code (-1).
Turned out that function indeed never gets called (again: in MY case). But by having it there, it fixes my build problem.
 

   

Notice, btw, that this was actually mentioned in the Errata sections of the FX3's datasheet.
 

0 Likes