Problems with printf on (CE210741) UART Full Duplex and printf() Support with PSoC 3/4/5LP

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

cross mob
VaCe_2419971
Level 2
Level 2

Hi,

I use CY8CKIT-59 and I try to use printf() as demonstrated in  CE210741, but instead to send characters back to terminal, I save them before into a buffer.

So I receive from terminal 4 bytes (0xac, 0x0d, 0x00, 0x00) - the value of 3500 in decimal.

Then I calculate the number from the buffer:

TimerPeriod=rx_buffer[0]+256*rx_buffer[1]+65536*rx_buffer[2]+16777216*rx_buffer[3]

Then I send back a confirmation message back to terminal:

printf("Test printf function. long:\"%ld\"\r\n", TimerPeriod);

On terminal I receive the number 172 in decimal (0xac) which is wrong

If I exercise in front of that:

            UART_PutString("Received from UART:");

            UART_PutChar(rx_buffer[0]);

            UART_PutChar(rx_buffer[1]);

            UART_PutChar(rx_buffer[2]);

            UART_PutChar(rx_buffer[3]);

            UART_PutString("\r\n");

I get not only the proper values stored in rx_buffer, but magically prinf functions works well too. I get 3500 instead of 172.

I have the heap space set to 0x300.

I attach for your convenience the archived project.

Can anybody offer some help?

Thanks.

0 Likes
1 Solution

The target device communicates with the PC USB host via the Kitprog. The Kitprog serves as a USB-UART bridge and hence even if you power your board externally, without the Kitprog, there is no direct link between the target device UART lines and the PC USB host lines as shown below:

usb uart bridge.PNG

This is the reason you didn't see anything on the terminal. More information on the Kitprog can be found here: http://www.cypress.com/file/157966/download

Regards,

Dheeraj

View solution in original post

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You need to set Project->Buid Settings->ARM->Linker "use newlib nano float formatting" to true.

Bob

0 Likes

Hi and thanks for your reply.

Setting "use newlib nano float formatting" to true, didn't help. After further investigation I think the problem is not with the printf function, but rather with some internals of the UART.

I attach another archived project which receives UART data I enter from a terminal, puts it in rx_buffer array, then it calculates the uint32 TimerPeriod value of the received data. Then it sends that value back to terminal with printf.

The first time I enter the data it displays a wrong value. But if I continue to enter the same data again several times, the value is displayed correctly. The problem with the wrong value being displayed occurs only when I enter new data for the first time and the change involves more than the first byte to be sent from terminal through UART.

The problem I have and determined me to ask for your help is that when I use the debugger, every time and every data I enter, the result is displayed correctly, no erroneous display. Hence the debugger is not helping much with the investigation.

You can try it with the attached code.

Thank you.

0 Likes

Update:

I downloaded a fresh UART full duplex example (CE210741), I changed the device for the one I have (CY8C5888LTI-LP097) and changed the pins to match the target:

- LED on P2.1

- Switch on P2.2

- Rx on P12.6

- Tx on P12.7

I programmed the kit with no other modification and it works as described, all typed characters returned to terminal.

However, I discovered that if I disconnect the USB cable from the programmer and I power externally the kit, the application doesn't run at all. After I introduce the characters at terminal and hit Enter, the "Error" LED turns ON and of course no characters are received back.

Is it the kit programmed with the example delivered in CE210741 meant not to work independently? Is it some sort of IP protection, or it may be related to the problem I found?

Regards.

0 Likes

Update 2:

Please disregard the printf function, this is not the issue.

After further investigation the issue looks to be that implementation of UART component is assuming that it will be used for bootloadable applications only.

I started a new project with the goal of replicating the example CE210741, but without all  unnecessary config and .h files. Only UART, ISR, and SW + LED pins. The main.c was largely copy/paste from CE210741. Test results were like before, when USB cable is plugged, data was transmitted back to Terminal, and without USB cable, the error LED was turned ON and no data received.

After building the project, I noticed the presence of UART_BOOT.c. The stated purpose of being generated " This file provides the source code of bootloader communication APIs for the UART component."

While I understand some applications will need this feature, in my opinion, for the purpose of stand alone application this is more like a hindrance. Again, in my opinion, this "feature" interferes and a regular (not bootable data) UART transfer depends on the presence of the KitProg.

Could anyone please give an idea for a workaround?

Thanks.

0 Likes

The target device communicates with the PC USB host via the Kitprog. The Kitprog serves as a USB-UART bridge and hence even if you power your board externally, without the Kitprog, there is no direct link between the target device UART lines and the PC USB host lines as shown below:

usb uart bridge.PNG

This is the reason you didn't see anything on the terminal. More information on the Kitprog can be found here: http://www.cypress.com/file/157966/download

Regards,

Dheeraj

0 Likes