[FX3] Fail to call sprintf function for float on C project

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, I've studied the Printing Floating Values using FX3 SDK – KBA231244 and its example project.

I've modified my C project with:
1. Followed example project to modify the system's fx3.ld & my project's cyfxtx.c.
2.  Added "#include <sys/unistd.h>" & "#include <stdio.h>" in my project.

But show error: sbrkr.c:(.text+0x18): undefined reference to `_sbrk'
undefined sbrk.JPG

I knew the article said: The Sprintf() function internally calls the _sbrk system call. Add the definition of _sbrk, from the cyfxcppsyscall.cpp file (available in the BulkLoopAutoCpp project in the FX3 SDK), to the firmware.
However, I cannot find the cyfxcppsyscall.cpp in my C project, so I don't know how to modify it.
PS. I found the cyfxcppsyscall.cpp in the same directory as the fx3.ld, and it's content has already added the _sbrk function.
sbrk.JPG

Does the cyfxcppsyscall.cpp cause the issue? If yes, how to implement it on C project?

Any help will be highly appreciated!
Hughes 

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello Hughes,

However, I cannot find the cyfxcppsyscall.cpp in my C project, so I don't know how to modify it.

>> You can find the cyfxcppsyscall.cpp  in the BulkLoopAutoCpp firmware of the FX3 SDK (attachment)

Please let me know if you are using the fx3.ld file and cyfxtx.c file attached with the KBA

PS. I found the cyfxcppsyscall.cpp in the same directory as the fx3.ld, and it's content has already added the _sbrk function.

>>Please let me know if _sbrk definition is copied to the main source file of your firmware (.c file) from cyfxcppsyscall.cpp file

Does the cyfxcppsyscall.cpp cause the issue? If yes, how to implement it on C project?

>> You can refer to the  project attached with the KBA

Regards,
Rashi

View solution in original post

3 Replies
lock attach
Attachments are accessible only for community members.
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello Hughes,

However, I cannot find the cyfxcppsyscall.cpp in my C project, so I don't know how to modify it.

>> You can find the cyfxcppsyscall.cpp  in the BulkLoopAutoCpp firmware of the FX3 SDK (attachment)

Please let me know if you are using the fx3.ld file and cyfxtx.c file attached with the KBA

PS. I found the cyfxcppsyscall.cpp in the same directory as the fx3.ld, and it's content has already added the _sbrk function.

>>Please let me know if _sbrk definition is copied to the main source file of your firmware (.c file) from cyfxcppsyscall.cpp file

Does the cyfxcppsyscall.cpp cause the issue? If yes, how to implement it on C project?

>> You can refer to the  project attached with the KBA

Regards,
Rashi
HuYa_4249091
Level 4
Level 4
25 replies posted 25 sign-ins 10 replies posted

Dear Rashi:

Thanks for your reply! I've solved this issue!

By the way, I'm curious about heap memory which we created for sprintf( ).
The original memory has allocated the RTOS heap area(32KB), and I can use CyU3PMemAlloc( ).
What's the different between the two heap?

Thanks!
Hughes

0 Likes

Hello Hughes,

In the KBA, second stage bootloader area is used for allocating runtime heap for sprintf() function as second stage bootloader memory area is used only when the application uses second stage bootloader.

RTOS Heap Area is used by  the RTOS provided heap allocator. This is used by CyU3PMemInit(), CyU3PMemAlloc(), CyU3PMemFree(). So, in order to avoid conflict, it is good to use memory area like second stage bootloader (if the application doesn't use it).

Regards,
Rashi