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:
void myDebug(int num, const char * format, ...)
va_start (args, format);
res = vsprintf(buffer, format, args);
if (res >= 0)
CyU3PUartTransmitBytes ((uint8_t *)&buffer, res, &apiRetStatus);
If you comment out the vsprintf line, the error disappears, indicating that vsprintf is the culprit.
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.
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.
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);
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.