Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
Using sprint() Function in EZ-USB® FX3™ - KBA90264
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:
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.