- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.