Question: How can I use the string formatting functions - sprint() and vsprintf() in FX3™?
The sprint() function is defined as part of the standard C library (libc) given with GCC in the FX3 software development kit. These functions internally use a few functions that are not defined by default. A reference implementation is provided in the cyfxcppsyscall.cpp file with the cyfxbulkloopauto_cpp example project (available at FX3_INSTALL_PATH\firmware\basic_examples \cyfxbulklpauto_cpp).
Include the sys/unistd.h header in your main C file. In addition, the sprint() function needs some runtime heap space. This space is marked by the __heap_start and __heap_end symbols, which need to be defined in the linker script file (fx3.ld).
You can allocate 32 KB for the runtime heap starting from the end of the DATA section before the RTOS heap section. This will run from 0x40038000 to 0x40040000. Make a copy of fx3.ld and add the following at the end of the SECTIONS:
. = ALIGN(4);
__heap_start = 0x40038000;
PROVIDE(__heap_start = __heap_start);
. = ALIGN(4);
__heap_end = 0x40040000;
PROVIDE(__heap_end = __heap_end);
PROVIDE(__heap_size = __heap_end - __heap_start);
You have now shifted the RTOS heap and the DMA buffer areas up by 32K (0x8000) because you inserted the runtime heap between them. In the cyfxtx.c file, change the CY_U3P_MEM_HEAP_BASE value from ((uint8_t *)0x40038000) to ((uint8_t *)0x40040000). Now, you can use sprint() in the usual way in your FX3 projects.