Help with USB

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with USB

7,538 Views
arunkumar1989
Contributor I

Hello ,

I am currently trying out the USB module on my K60(MK60FN1MOVLQ12),in device mode.

Basically,i want to accomplish two things:

1.a simple loop back i.e i write something in hyper terminal and the same content should be echoed back to the same terminal.

2.Text written in hyper terminal should be echoed on an LCD

I have read a few forums and it seems we need to add a few user made processor expert modules?

If someone could point me to an example using this /or similar controller,that would help me a lot.

I have tried using the USB_LDD component but i always mess up with the timings.

I have looked at a few tutorials(links below) but some of their PE components are not there in my current PE component library :smileysad:

http://mcuoneclipse.com/2012/10/07/tutorial-usb-cdc-with-the-kl25z-freedom-board/

http://www.steinerberg.com/EmbeddedComponents/Examples/Examples.htm

Please Help

Labels (1)
0 Kudos
Reply
29 Replies

1,425 Views
arunkumar1989
Contributor I

Hello Erich,

Thank you for this.Will try it first thing when i reach work :smileyhappy:

I meant 4.0.3(i think it came with the K60  we purchased),but seeing that there is a 4.1.1,i will install that instead.

Will post again if i am facing any problems.

Thank you again,

Arun

Edit:

We do not have the 32 kHz crystal yet as we have no use fir the RTC for now,hope that will not be as issue with usb configurations?

0 Kudos
Reply

1,425 Views
BlackNight
NXP Employee
NXP Employee

no, you do not need that 32 kHz crystal for USB. I just configured it as it is present on the board.

0 Kudos
Reply

1,425 Views
BlackNight
NXP Employee
NXP Employee

Hi Arun,

if you are going to use my Processor Expert component(s), you do not need to install the USB stack: the USB components have the sources of 4.1.1 already intergrated. But of course you can have 4.1.1. installed too (it does not hurt).

4.0.3 is pretty old, so anyway good if you use 4.1.1.

0 Kudos
Reply

1,425 Views
arunkumar1989
Contributor I

Yep i am going to use your PE components.We are using CW 10.3 at the moment, the CW10.5 you mentioned in your blog an evaluation copy?

0 Kudos
Reply

1,425 Views
BlackNight
NXP Employee
NXP Employee

The components should work fine in 10.3, and they do not need any special license. So you can use them in the special/free edition without any problem. I have not used 10.3 after I switched to 10.4 earlier this year. I'm using 10.5 right now, but it seems that others have problems with that new Eclipse version. I suggest you try things with 10.3. I believe the projects should be pretty much backwards compatible. If you face an issue, let me know.

It is just that my project is set up for gcc (not for the legacy Freescale ARM compiler). Are you using gcc too in CodeWarrior?

0 Kudos
Reply

1,425 Views
arunkumar1989
Contributor I

No we are not using gcc,we use the inbuilt freescale tools which come when creating a project.

0 Kudos
Reply

1,425 Views
BlackNight
NXP Employee
NXP Employee

Then I recommend that you move up at least to 10.4. Gnu GCC is the default and standard compiler Freescale provides now. That compiler you use will be EOL.

0 Kudos
Reply

1,425 Views
carlosmendoza
Contributor III

Hello Arun,

I would highly recommend reading the following two tutorials by Erich Styger. He works for Freescale and is the author of the popular "MCU On Eclipse" blog. I was able to both understand and get the USB CDC (serial, virtual COM port) communications running for the KL46Z Freedom board through these tutorials.

Tutorial: USB CDC with the KL25Z Freedom Board | MCU on Eclipse

http://mcuoneclipse.com/2013/08/29/usb-for-the-freescale-arm-kinetis-kl46z-and-k21d50m/

Erich hasn't posted example code for the K60 regarding USB CDC communications. However, I would recommend you to do the following:

1) Download and install Erich's Processor Expert components. Erich usually has the most up to date Freescale components and he is constantly improving them. You can find these components by following this link:

mcuoneclipse/PEupd at master · ErichStyger/mcuoneclipse · GitHub

If you don't have a GitHub account then you can just download these components and all of his example code on a zip file by following this link and clicking on "Download ZIP":

ErichStyger/mcuoneclipse · GitHub

2) Download Erich's USB CDC example for the KL46. This is the most up to date example he has on using Freescales USB stack. You can find this example on GitHub by following this link:

mcuoneclipse/Examples/FRDM-KL46Z/FRDM-KL46Z48M_USB_CDC at master · ErichStyger/mcuoneclipse · GitHub

3) The easiest way for you to get your loop back functionality up and running will be to open up his KL46 example and edit the Processor Expert settings for the USB and CPU components. You will need to edit the clock settings and maybe the pins so they match the actual pins for the external oscillator on your K60 board. To help you understand which clock settings you need to edit and how to choose the right settings you should read Erich's tutorial for the KL25 microcontroller. The main detail is that the USB module on the Kinetis microcontrollers needs to run on a 48 MHz clock. Your K60 board might have an external 8 MHz oscillator. If this is the case, then you will have to configure the K60's Processor Expert component to generate the 48 MHz clock. For example, on the KL25 and KL46 chips this is done by selecting the options to multiply the external 8 MHz clock using the PLL module to obtain a 96 MHz clock and then passing this resulting clock through a clock divider to obtain the required 48 MHz clock.

4) After completing the clock and pin settings you just have to run the code on your K60 board. It should show up as a COM port on your computer. If you open a terminal app (I recommend RealTerm or PuTTY if you're using Windows) you will see that anything you type will be looped back to the terminal.

5) Look at the KL46 example code and learn the function calls that were used to send and receive data. In short, you just use the CDC1_SendString() function to send strings through the USB interface and CDC1_GetChar() to read one character at a time out of the receive buffer.

6) To test more advanced communications between the K60 and your computer I would recommend getting Visual Studio Express 2012 (it's free) and use C# to read and write to the COM port that belongs to the K60 chip. That's if you need to develop a project for Windows. Or if you're familiar with some other OS, language and IDE then just use whatever you're comfortable with.

It took me about a week to understand how the Freescale Processor Expert projects are setup on the CodeWarrior IDE and where all the code needs to go and why as well as why Processor Expert is so useful, etc.

Then, it took me about three days to understand the clock settings and I had to read Freescale's reference manual to check how the clocks worked on the KL46 and KL25 chips. You might have to do the same for the K60. But of course, having the KL46 example meant that I had a working setup from the start and I could comfortably mess around with the settings to actually understand why the clock needed to be setup that way. If you're in a hurry then you don't need to learn as much as I did, just enough to get you running. But learning that little bit extra will help you later on in other projects.

Lastly, it then took me about a day and a half to learn how to make a basic C# app to start designing all the other functionality that I needed between the KL46 and the computer.

I didn't have any previous experience on using the Kinetis or the Processor Expert platform or C# before I read those tutorials. However, I have used other basic microcontrollers and FPGAs in previous projects as well as Java for Android so that translated nicely for using C# to make a Windows GUI and for understanding all the clock settings. It goes without saying that it might take you much less time than me if you are already experienced in any of this topics.

I hope this post helps you. Have fun and be patient with yourself while you do dig through all this information.

Carlos

1,425 Views
arunkumar1989
Contributor I

Hello Carlos,

Thank you for such detailed info,yes my end game is to get communication setup from my hardware to a custom API(using VB,haven't decided on the correct software yet)so that i can give inputs via computer,but this is only secondary as i have to first have proper settings configured in my K60 core.

0 Kudos
Reply