UART in Standard Mode Example Code

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

cross mob
Anonymous
Not applicable

I would like to create a loopback for the UART just to get a feel for how it works.  Where can I find example  code for this?  Obviously the UART would need to be bi-directional and standard mode is fine.  No handshaking is needed.

   

 

   

On the CY8CKit-49-41xx and CY8CKit-49-42xx it seems the baud rate is limited to about 9600 for the standard rates.  Anything higher and the error is too large.  Is there a way around this without changing the crystal?  Can an SCB be used to generate better clocks for a higher baud rate? 

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

Use SCB-UART, connect externally Tx and Rx.

   

Set the buffer sizes to something like 40, baud rate to 115200

   

Set the IMO clock to 48MHz

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Where do you want to have the loopback? Should the PSoC send out data, which then gets looped back to it so you can print it to somewhere? Or should the PSoC receive data on Rx, which it then sends back on the Tx line?

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored
0 Likes
Anonymous
Not applicable

Yes, the data received on Rx will be transmitted back to the sender on the Tx line.  I will look for the example you point to.  Thanks

0 Likes
Anonymous
Not applicable

I downloaded the project file and opened it in Creator.  I changed the tx and rx pins to match the PSOC proto kit.  It compiles ok.  I also downloaded the CyUSB-Serial_SDK drivers and installed them.  The COM port for the proto kit shows up in the bootloader host screen as COM6.  But I can't figure out how to download the project to the proto kit.  When I click the program icon it pops up a dialog that says "Port Acquire Failed". 

   

 

   

Am I heading down the wrong road?

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

At first: check the baud-rate and other settings of both UART and your COM-port. Also check the mimic with the switch and the blinking LED as stated in the Kit's user guide.

   

Since we do not know exactly

   

Which Prototype kit you use

   

and which project you downloaded

   

it can be easier for us to trace down any bugs when you attach your complete project here so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file (do NOT use chrome, that still may not work).

   

 

   

Bob
 

0 Likes
Anonymous
Not applicable

I don't think you understand my post.  First, the project and board are the ones listed here in the thread already. 

   

 

   

CY8CKit-49-42xx and the UART loopback at '100 projects in 100 days' series: http://www.element14.com/community/message/75846/l/psoc-4-pioneer-kit-community-project04--usb-uart-...  USB-UARTexample project.zip

   

 

   

I don't see a point to uploading the project as yet because I have not been able to program or even find a way to program the prototyping kit board.  I am asking for instructions on how to do that.

   

 

   

BTW, I tried to follow the introductory videos found on the web site, but I found them to be very marketing oriented and could not find the technical content.  The first two videos were 100% fluff.  When I tried to watch video three and four I tried skipping over the fluff content and every time the video would hang and the page would need to be reloaded.  I would get error messages saying use a different browser (no mention about which one works better) until I had tried all three that I have, Chrome, Firefox and IE.  Is there a way I can download the video and watch it offline?  That should allow me to view any portion of the video without watching all the marketing fluff.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received


Using  the UART with this kit is a little harder than with the PSOC 4 pioneer kit because it contains the PSOC 5 for the usb interface and uart.  I have checked and found an example in this document http://www.cypress.com/?docID=48142. See section 5.4.2 it explains how to use the UART with this board.  As this board has limited resources I am not sure you will be able to read back your serial data. I would suggest that you get a PSOC 4 pioneer kit as it has more resources and is easier to debug in real time.  Also this document shows you how to get this board to program and work with the PSOC Creator 3.0.

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

Well, the project you downloaded is not designed for using a bootloader which is needed if you do not have got a MiniProg3.

   

 

   

Have a look at the examples for the Kit-049-42xx and understand how bootloading works. Then you may expand the current project by using a BootLoadable component and changing the project's properties appropiately.

   

The examples are needed because they have got the BootLoader project which has been initially programmed into the kit. The bootLoadable project refers to some files of the bootloader project.

   

 

   

Bob

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

An additionally downgrade: That project is made (as you can see from the pictures of the board) for the Pioneer Kit which has a UART-USB-bridge on board which is not the case for the Kit-049-4xxx.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I'm a little confused by the bootloader vs. bootloadable.  When a bootloadable project is created, I assume that does not include a bootloader.  So I also assume the existing bootloader does not copy over itself then.  So I can create a project with the bootloadable component and it will not clobber the bootloader.  But how then do I use the exiting bootloader again if the UART is used by the app.  Do I have to include the bootloader and use a switch or other condition to run the bootloader for a new program? 

   

 

   

So if I include the bootloader and it doesn't work correctly I have bricked the kit until I can use a MiniProg3 or other programmer with it, right? 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

In a PSOC 4 pioneer kit the bootloader is stored in the PSOC 5 part on the board. In your project it is in the software on your computer when you are using the PSOC Creator. All of your projects must have a Bootable component on your Schematic or the unit will not function.  See example 36 of 100 projects in 100 days to better explain the bootloader and bootable information. Also you are not able to debug the CY8CKit-49-42xx in real time because you do not have the PSOC 5 part.  As I have suggested before I would start out with the PSOC pioneer kit to get use to the family and device and then try to use your CY8CKit-49-42xx.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Check this article at http://eewiki.net/display/microcontroller/PSoC+Bootloaders it explains the issue very well.  I decided that if I was going to use one of these boards I would need the CY8CKIT-002 PSoC® MiniProg3 Program and Debug Kit as I want to be able to debug the projects.

   

Bob

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

The following bootloaders were tested on the PSoC4 Pioneer Kit (CY8CKIT-042). 

                                                                                                                                                   
       
        Bootloader Files       
       
        Description       
       
        Device       
       
        Bootloader Pins       
PSoC4_I2C_Bootloader.zip

Bootloader waits 2 seconds for start signal from Host and then passes control to application code.  2.2k pull-up resistors are included on P4[1:0] on the PSoC4 Pioneer Board.

Bootloader I2C rate is 100kbps.  I2C slave address is 0x08.

 CY8C4245AXI-483

P4[0]: I2C_SCL

P4[1]: I2C_SDA

PSoC4_UART_Bootloader.zip

Bootloader waits 2 seconds for start signal from Host and then passes control to application code.

Bootloader UART operates at 56.7kbps, 8-bit data, no parity, 1 stop bit, no flow control.

 CY8C4245AXI-483

P0[4]: UART_RX

P0[5]: UART_TX

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

Let me clarify some differences:

   

The Pioneer Kit has got an additional PSoC5 chip which is programmed to be a programmer/debugger for the main chip, the PSoC4. There is no bootloader and the projects for the Pioneer board do not use a BootLoadable component. An essential point is the capability to debug Pioneer projects (setting breakpoints, inspecting variables etc.)

   

 

   

The Prototype Kit-049-42xx has got an USB-UART bridge which allows communication with the BootLoader component to program the chip anew. The BootLoader will NOT overwrite itself and when control is passed to the Bootloadable the interface is released and may be used freely.

   

Changing the BootLoader can only be done by re-programming the PSoC4 with a programmer like the MiniProg3. Any changes in the BootLoader project requires that the BootLoadable projects have to be re-compiled using the new information.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Ok, I just want to clarify one more point.  I've built a project with the bootloadable component and loaded it into the The Prototype Kit-049-42xx.  Now to use the bootloader again, I insert the kit into the USB port while holding the button and will see the blue LED blinking fast, right?  In other words, this functionality is part of the bootloader and needs nothing extra from my application. 

   

 

   

🙂

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

Yes, exactly! But you can have a look into the bootloader project and verify that the switch, a timer and the BootLoader are used.

   

 

   

Bob

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I that is correct !! Unless you have the external  Programmer and want to do debug. I was going to get one of these boards but didn't because of the need for the external  programmer to debug my applications. I already had that in the PSOC 4 pioneer board.

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

There is a hack to use the PSoC5LP on the Pioneer board as programmer (and debugger) for a PSoC4 including that one on a Prototype board.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Ok, I was able to compile the Bootloadable Blinking LED project and download it to the CY8CKit-49-42xx and it appeared to still work.  Not a great test since this was the program that was already on the kit board... however, in bootloader mode the LED blinks fast and it did change to the slow blink.  So I think that indicates a successful reprogramming.  

   

 

   

Then I tried downloading my modified project.  This was the UART loopback with the blinking LED objects (PWM and I/O pin for LED).  It compiles ok, but now I can't get the tools to recognize the bootloader.  I open the bootloader host window and the board shows up as COM6 as before, but the UART configuration is grayed out and all the action buttons and menu items are grayed out. 

   

 

   

I went back to the Bootloadable Blinking LED project with the same results.

   

 

   

This doesn't sound like anything wrong with my project itself, but rather something with the comms to the CY8CKit-49-42xx.  I tried plugging in a CY8CKit-49-41xx board that has not been programmed and get the same results.  I get the fast blinking LED and COM6 shows up, but the bootloader host window won't let me program it.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I found the problem, it was comms, I had a Putty terminal window open on COM6, lol.  So I'm past that problem.  But now I am getting an error when I try to program the kit.  "The flash row is not valid for the selected array."  I have archived the project and am attaching it here. 

   

 

   

Thanks for all the help. 

   

 

   

Rick

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I compiled the files you sent and I didn't get any errors.  I think your error is comming from your kit. I would get another one and try it again.

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

The originally programmed bootloader is write-protected. Probably you are trying to overwrite it. This should not happen.

   

Probably you are referring to a wrong bootloader .elf-fil in your new project.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I have tried two kits including one that has not been programmed at all.  Same result. 

   

 

   

Bobgoar: were you able to load the project into a board or you only tried building it? 

   

 

   

Bob Marlowe: The only place I see an ELF file mentioned is in the bootloadable component and that is pointing to what I believe is the right place.  It is in my project heirarchy.  How can I tell if it is not the right one?

0 Likes
Anonymous
Not applicable

What does the error "The flash row is not valid for the selected array." even mean?

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

The *ONLY* Bootloader project is that from the examples page for the CY8CKIT-049-42xx www.cypress.com/

   

This is the already programmed BootLoaderr. As long as you do not reprogram using a MiniProg3 you have to stick to that bootloader in your bootloadable projects.

   

I assume that the error comes from trying to overwrite parts of the bootloader.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Bob Marlow: I don't understand why you are talking about bootloader projects.  My project is "bootloadable", not "bootloader".  I was told this is the correct way to use the bootloader.  The project should be "bootloadable" which will not overwrite the bootloader.  My project does include the PWM component and drives P1_6 which is connected to an LED.  Is this the cause of the problem? Is the bootloader trying to use the same hardware? 

   

 

   

How do I find what is wrong with my project?  I am uploading it again.  The elf file is .\CortexM0\ARM_GCC_473\Debug\UART-Lpbk.elf   How does this file get created? 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Did you download the file http://www.cypress.com/?docID=48142?  It explains how to create the boot loader files in section 3.3.2.  Also see AN73854. If I had to guess some how the bootloader is corrupt on your board.  As for your question did I try to down load the program to my PSOC pioneer board no  I just rebuitt the program and got no errors. If I downloaded it into my board it would not be a true test as I don't have your board and have no way to determine if your

   
    Dependencies   
dependencies are correct in your bootlloader.  I think you need to get the Mini programmer to fix this issue.    
0 Likes
Anonymous
Not applicable

Did you read my earlier post that I tried this on *two* boards.  One I have been working with and the other I just took out of the package.  I have also proven that the board I am working with is still functional by successfully downloading the Bootloadable Blinking LED project.  So clearly the problem is with the project.

   

 

   

I don't understand the recommendation that I get a programming cable.  If the bootloader works, then I should be able to use it.  If it doesn't work, then why is it marketed as a tool?

   

 

   

The reason I am working with this board is because I am part of a project to port a Forth tool to the PSOC ARM family.  The main reason we are doing this is because of the $4 board.  At the moment I am trying to write a loopback UART program so I can turn the code over to someone else who will fold the assembly code into the Forth package.  I believe he is also working on a debugging tool to support these boards.  He doesn't want to use the Miniprog3 because it is proprietary.

   

 

   

I won't be buying more tools for the PSOC.  At this point I my plan is just to get the code tested and turn it over to the rest of the project team.  Then I believe I will move on to some other ARM chip.  I understand why Cypress has gone the route they have with the tools, but I find the documentation and the nature of the tool prevents me from actually understanding the chip and tools.  This is one of the goals of this project, to make the chips more accessible and interactive to facilitate understanding.

   

 

   

So is there anything we can do to get this working or should I just pass the code on in an untested state? 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Well I just  built the project again and it in only using Flash used: 4070 of 32768 bytes (12.4 %).
SRAM used: 1544 of 4096 bytes (37.7 %). I do not think you have over written the bootloader but it is possible. There is a similar program that uses a UART it is 100 projects in 100 days #40 it is a uart program that over writes the bootloader in the in the Psoc and it needs to be reinstalled. The Issue you have is one reason I have not ordered this board I like to debug my software and this board doesn't allow that.  I didn't want to put out $89.00 for the mini programmer 3 if you had that device you would be able to fix the flash issue. So you are using Forth I knew an engineer 33 years ago who thought that forth was the best programming language there was.  I thouht that it had died out by now.  Back then code was still written in assembly those where the days.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

If I where you I open a case with cypress under my case and see if they have anyother ideals. 

0 Likes
Anonymous
Not applicable

I think I had been misunderstanding you.  I thought you were saying I *had* overwritten the bootloader.  You are saying the project I am trying to download is *trying* to overwrite the bootloader.  That makes sense, although I can't think why. 

   

 

   

I started with the UART echo program from 100 projects.  It is pretty durn simple.  I added the PWM and LED so I could change the blink pattern and know for sure the board had been flashed.  I'm thinking that has something to do with the problem. 

   

 

   

I will take your suggestion and open a ticket with support.

   

 

   

Thanks to everyone for all your help. 

0 Likes
Anonymous
Not applicable

For the record,

   

I downloaded the project file submitted by gnuarm, updated components, recompiled and reprogrammed my PSoC 4 CY8CKIT-049-41xx successfully.

   

After programming the application, I opened a terminal program on the same port used by the bootloader host.

   

I resetted the chip by temporarily grounding the reset pin. The message "CY8CKIT-042 USB-UART" was displayed as expected.

0 Likes