FX3 - How to use sprintf function?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
HuYa_4249091
Level 4
Level 4
25 replies posted 25 sign-ins 10 replies posted

Hi all:

I want to use sprintf() in EZ USB Suite - FX3 FW, but it met compiler fail.

I've added "#include <stdio.h>", but it still fail...

error.jpg

Hope someone could provide any suggestion.

Thanks a lot!

Hughes

0 Likes
1 Solution
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

Please use the API CyU3PDebugStringPrint(); for implementing snprintf();. This API make use of following parameters as shown in its definition.

extern CyU3PReturnStatus_t

CyU3PDebugStringPrint (

        uint8_t *buffer,                          /**< Buffer into which the data is to be printed. */

        uint16_t maxLength,                /**< Buffer size. */

        char    *fmt,                              /**< Format specifier string. */

        ...                                             /**< Variable argument list. */

        );

I have implemented your requirement as shown below.

char c1[20];

uint8_t n =5;

CyU3PDebugStringPrint ((uint8_t*)c1, 20, "He has %d books.\n", n);

CyU3PDebugPrint(4,c1);

I got the following output in teraterm.

pastedImage_6.png

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

1 Reply
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

Please use the API CyU3PDebugStringPrint(); for implementing snprintf();. This API make use of following parameters as shown in its definition.

extern CyU3PReturnStatus_t

CyU3PDebugStringPrint (

        uint8_t *buffer,                          /**< Buffer into which the data is to be printed. */

        uint16_t maxLength,                /**< Buffer size. */

        char    *fmt,                              /**< Format specifier string. */

        ...                                             /**< Variable argument list. */

        );

I have implemented your requirement as shown below.

char c1[20];

uint8_t n =5;

CyU3PDebugStringPrint ((uint8_t*)c1, 20, "He has %d books.\n", n);

CyU3PDebugPrint(4,c1);

I got the following output in teraterm.

pastedImage_6.png

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna