Translation - Japanese: FX3 SDKを使用した浮動小数点値のprint出力 – KBA231244 - Community Translated (JA)
Question 1: Is it possible to print float or double variables using FX3 SDK?
Answer: Yes, it is possible to print float variable using FX3 SDK. You can print using the standard C library function sprintf().
The standard sprintf() function is used to store the formatted string into a buffer. The GCC linker script provided with the FX3 SDK (firmware/common/fx3.ld) does not initialize a runtime heap that is required for standard C library functions such as sprintf().
If you are using the standard C library functions, implementation for standard system calls needs to be provided and the fx3.ld file needs to be modified to create a heap.
See the BulkLoopAutoCpp example of the SDK (Path: SDK Installation path \Cypress\EZ-USB FX3 SDK\1.3\firmware\basic_examples) for a sample implementation of the required system calls, and the fx3cpp.ld file for a script sample with heap initialization.
Note: C++ linker file (fx3cpp.ld) in the SDK can be used only for the C++ based projects like BulkLoopAutoCpp example of the SDK
Question 2: Is it possible to print float or double variables in C based projects of FX3 SDK?
Answer: Yes, it is possible to print float variable in C based projects of FX3 SDK. The float values can be printed using standard C library sprintf() function and the CyU3PDebugPrint API of the SDK. However, firmware needs to be modified before using the sprintf() function as runtime heap needs to be initialized.
Do the following modifications:
Figure 1. Modifications to Project Settings
4. Now, use the sprintf() function in the firmware, and print floating numbers to UART using the CyU3PDebugPrint API.
Here is a sample code to print floating values using the CyU3PDebugPrint API.
Question 3: Is there any example code for printing floating values?
Answer: The USBBukSourceSink example of the SDK, modified as per the steps mentioned in Question 2, is attached with this KBA.