Checking the download statistics of my Processor Expert components on http://www.steinerberg.com/EmbeddedComponents/, there is a clear winner: FSL_USB_Stack 🙂
It has been a while I presented that universal USB CDC component in this blog. The component has received a larger re-architecture, I wanted to support more than just USB CDC. For this, the CDC part is now present in a separate sub-component:
FSL_USB_CDC_Device Class Component
Everything related to the CDC class is now inside the FSL_USB_CDC_Device sub-component:
This means that now the CPU is set inside the CDC component.
FSL_USB_Stack Component
The FSL_USB_Stack component now features added USB classes. The component comes now with the CDC class, as I’m still working on the HID and MSD components:
Sending lots of data, and fast…
Several users have reported issues with the original Freescale USB stack: if you send a lot of data in a fast way, data got corrupted. Up to the fact that a terminal application on the host might crash or block. It took me a while to get down to the root cause of this: a buffer overwrite originated by the USB interrupt. The same problem happens with the original Freescale source code. It was more likely to happen on slower microcontroller.
Good news: Today I have identified the problem and it is now fixed 🙂 At least for my self and on a student board/machine where the problem was present, it is fixed now.
Migration
Switching to the new component architecture is easy even for existing projects. Once the new components are loaded, set the used microprocessor in the FSL_USB_CDC_Device sub-component. As the CDC functions are inside a different component, make sure e.g. CDC1_GetChar()
is called instead of the earlier USB1_GetChar()
. A similar change I had to do in the FSShell component, so make sure you load this one too.
The new FSL_USB_Stack component (which includes the FSL_USB_CDC_Device) is available here. The examples I have created and published on the web will be updated over the course of the next days (well: nights).
Happy Stacking 🙂
I know they’re not there yet, but when they are will selecting both HID and CDC (for example) create a composite device, or will they be mutually exclusive. And what was the bug?
LikeLike
For now they are mutually exclusive. I need to see how I can create a composite device with it later. And the bug was that App_USB_Class_CDC_Interface_DIC_Send_Data() could be called while the previous transaction is still in progress. Solved with a transactionOngoing flag.
LikeLike
Great, I’m happy to see more work go into this because I found it very useful. I have noticed some bean errors when using the CDC bean with a 52259. The code compiles fine, but CW10.2 shows about 10 errors similar to the following:
INTERNAL ERROR: at line 2: Command %set cannot be used in this type of script. It can be used in component script only. (file: Beans\FSL_USB_Stack\FSL_USB_Stack.chg) pe52259 Processor Expert Processor Expert Problem
LikeLike
Yes, that’s a strange error of processor Expert, and more of a bogus problem in my view. It should go away if you close the project and reopen it again.
LikeLike
Hi, I have a problem, when I add component to the project then appears:
” Description Resource Path Location Type
INTERNAL ERROR: at line 2: Command %set cannot be used in this type of script. It can be used in component script only. (file: Beans\FSL_USB_Stack\FSL_USB_Stack.chg) OS1 Processor Expert Processor Expert Problem”
thank you for your help
LikeLike
Read one comment up, Erich replied to this when I mentioned it last week. The error does not prevent the project from working, and it does go away when you close and re-open the project.
LikeLike
thanks, close the project and reopen it woks fine!
LikeLike
Yes, not sure what kind of bug this is in Processor Expert. As a general tip: I have seen cases where Processor Expert seems to be stuck on errors: closing and re-opening the project is a hot-fix which solves the the problem in 99% of the cases.
LikeLike
Hi!! nice work!! I have a question, the function to call periodically is CDC1_App_Task?
When I want to read a byte from buffer I should use USB1_RecvChar or CDC1_RecvChar?
LikeLike
Yes, you need to call the CDC1_App_Task() periodically. This ensures that data packets are sent (and received) from the USB bus. Kind of USB bus polling from the application. You can use either USB1_RecvChar() or CDC1_RecvChar() (the USB1 is a simple define to the CDC1 version). I recommend to use the CDC1 version.
LikeLike
Thank you for your answer. But I have a lot errors again. I only setup the clock settings and add CDC component to the project.
Take a look of this snapshot.
http://www.mediafire.com/?cpuwec6x0bgtxs3
LikeLike
Hi Candelo,
from the screenshot it is hard to tell what the probelm is.
A few points to check:
– are you using the latest components from GitHub (https://mcuoneclipse.com/2013/05/09/processor-expert-component-peupd-files-on-github/)?
– I see you are using a ColdFire JM128. I do not have one at hand right now, but can you check that you have selected ‘Init_USB_OTG_COLDFIRE1’ as USB Init component?
– Try my JM128 project on GitHub (https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples)
I hope this helps. Otherwise send me your project to my email address mentioned on the ‘About’ page of this blog.
LikeLike
Pingback: USB CDC with the FRDM-K20D50M | MCU on Eclipse
Great work, Erich! The components you created were of tremendous help for our previous project, based on the 50 Mhz K20 processor. Right now, I am looking to port the PE component on the 120 Mhz, K22 processor (MK22FX512). Any pointers or tips on how to do it and what the common pitfalls are?
Cheers,
Alex
LikeLike
Hi Alex,
thanks 🙂
Unfortunately I do not have a K22 available. My experience with other ports of the USB stack that the important things is to use the right bits to enable/disable the USB interrupts. I might just read the data sheet and add that support to the component(s), but I won’t be able to test it. What do you think?
LikeLike
Erich,
I am working on it currently and will try to get it working. I saw in your Git repository, that there are a number of FSL_USB_CDC_* files there, both under the Drivers/ , Drivers/sw and Drivers/Common. Could you help me out by telling me which files need to be edited? I should mention that this is the first time I try my hand at PE component editing.
Obviously, if you want to take a stab at it, I’d have no problem testing it myself and reporting back the findings.
Thanks,
Alex
LikeLike
Hi Alex,
I checked the data sheet, and it looks the K22 is using the same USB module and interrupts as the K21. So I suggest that you select in the USB component as device the K21F120, and give it a try?
LikeLike
I can confirm that selecting the K21 works for the 50MHz K22 part. I expect the 120MHz will work as well.
LikeLike
ok, that’s good news. So I can add the K22F50 now to the list 🙂
LikeLike
Hi Erich,
I’ve had a go with the K21F120 setting, but no luck. I think it’s related to the clock settings, as it doesn’t recognize the MCU’s clock paths. I’ve added a screenshot for easier reference: http://i212.photobucket.com/albums/cc303/alexx_88/usb_clock_settings.png
I’ll try to correct the settings manually, in the generated USB0.c file. The Kinetis that I aam working with is the MK22FX512VLK12
Cheers,
Alex
LikeLike
You might have a look at my K21 example: you need to configure the clock (e.g. PLL output) so it gets a 48 MHz clock to the USB module:
https://mcuoneclipse.com/category/boards/twr-k21f120m/
LikeLike
I’ve went through all of the settings and it seems that the only possible thing left is related to hardware, specifically to the length of the data lines.
In any case, thanks for your help. 🙂
LikeLike
Hi Alex,
I have added a setting of K22F120M to the USB stack (CDC only). The commit is here:
https://github.com/ErichStyger/mcuoneclipse/commit/faf2eb6d68a504761cd4bbb3926d3709e3e8c529
What do you mean with ‘length of data lines’?
LikeLike
I’ll test the new component out and report back the findings.
Regarding the PLL output, I initially though that it’s just a PE error determined by the incorrect processor setting. After looking closely, I saw that I was lacking PLL output and enabled it from the PE CPU config.
I was referring to the length of the D+ and D- traces on the board. They have slightly different lengths (by 0.7 in) and both feature 2 vias which could determine some electrical problems in the signal. Basically, the peripheral receives the USB Reset signal, but no setup packets afterwards.
Alex
LikeLike
Hello Alex,
Did you get the USB working on the K22?
The MSD example gives me a “3TR Timeout”.
I’m using a MK22FX512VLK, so it’s a 1st gen Kinetis.
The same code on the FRDM K22 Board runs ok! Do you think that both MK22FX512 and MK221M0 first generation K22 have a bug?
Best regards,
Jose
LikeLike
Hi José,
yes, I have the USB stack working on my MK22FX512VLK12. It is that device I use on my sumo robot, see
I’m using the FSL_USB_Stack component (which is a modified Freescale USB V4.1.1 stack version).
I’m using the USB CDC device class with it.
LikeLike
Hi José,
A quick follow up: I just realized that the K22F120M was not properly supported in the list of devices. I have committed a quick fix on GitHub: https://github.com/ErichStyger/McuOnEclipse_PEx/commit/09ca11865d77f04c9c0298b790529b5d7c529797
LikeLike
Hi Erich,
Can you use MK22FX512VLK USB has MSD host? Can FSL_USB_Stack support it or does it handle CDC only?
I’m using a 30ppm crystal, can it be the problem? I’m getting 83ns period so the clock seems ok, but i’m not sure about jitter…
I don’t have a 32.768KHz crystal, but FSDK uses LPTMR with LPO clock and USB Stack V5 bare metal uses PIT, so I don’t think that’s a problem.
BTW, how can the same code run perfectly on FRDM K22?!
I will try the V4.1.1 during today and I will keep you posted.
Best regards,
José
LikeLike
the FSL_USB_Stack supports MSD host too, but I have not run it on the MK22FX512VLK yet. Your crystal should not be a problem. I don’t have the FRDM-K22F in my hands right now, so I cannot tell. So far it was not possible to run non-SDK Processor Expert components with it, but I saw a possible hack how to support this. I should be hopefully able to try it out tomorrow if time permits.
Erich
LikeLike
Hi Erich,
I made a new USB MSD project based on V4.1.1. I couldn’t get it working. It stops waiting for a communication reply.
I’m thinking that it is a hardware problem. At first I misunderstood the VOUT33 pin function and I didn’t connect it (I thought it was used only when internal voltage regulator is used too). I have made a tweek on my board to get 3V3, but and now Cstab is missing on that pin. I checked it using the oscilloscope and the problem is that voltage varies from 3V to 4V during communication.
I think that’s why I’m getting this “3TR Timeout” error on V5 stack
(check freescale community thread/329494).
“Hi, just got feedback from Application Engineer on this issue.
as replied, usually, the 3TR issue is caused by the signal quality…”
So maybe that’s what’s causing signal quality issues… Tomorrow I will try to solve this problem and I will share my results.
Cheers,
José
LikeLike
Hi Erich!
Problem SOLVED!!
I just needed to disable MPU!!!
Please check freescale community thread/329494
Cheers,
José Ribeiro
LikeLike
Hi José,
so it is then the same issue as with the FRDM-K64F (see https://mcuoneclipse.com/2014/10/25/usb-cdc-with-the-frdm-k64f-finally/).
Thanks for reporting! I will add the K22FN to the supported devices of the USB stack with the next release.
thanks!
Erich
LikeLike
Hello Erich,
Sorry to have you bouncing all around with my many comments but I think here is the best place to post my trouble I am having with the FSL_USB_Stack and CDC components. I am using a MK20DX256VLH7 and I wish to achieve CDC and MSD hybrid usb device. For now, I am going for the CDC part first and I seem to have troubles with this: “Generator: FAILURE: at line 5: Error in including “Drivers\FSL_USB_Stack\FSL_USB_Stack_Config.h” (file: Drivers\FSL_USB_Stack_Files.prg)” plus about 60 other errors of the same type. And yes, in the “Drivers” folder, it seems the “FSL_USB_Stack” folder is missing. I have CW IDE 10.6 and the latest and greatest GIT version of your work.
Please advise,
Mevon
LikeLike
Hi Mevon,
it looks you are using the source files from GitHub? I had to remove the FSL_USB_Stack folder from Git on request from Freescale. But there is a workaround: download the *.PEupd files (see https://mcuoneclipse.com/2013/05/09/processor-expert-component-peupd-files-on-github/) and install them, then you have all the files needed.
I hope this helps?
LikeLike
Yes! I all works now! 🙂 I didn’t get the “import” part I though you only had to add in the “C:\ProgramData\Processor Expert\CWMCU_PE5_00” folder the *.PEupd files. I hope Freescale will give you a raise because you are doing a lot for the Kinetis community and I would vote for you as Director of Software Engineer Deployment! Raise for the King!
Mevon
LikeLike
🙂 🙂 🙂
LikeLike
Hi Erich,
I’m looking to build an application with PEx that would include the MSD and CDC at the same time (with the K20 series 50 or 72), how do you recommend I begin my work? I was hoping to add over your components and have maybe a Critical Section or some semaphore to share the usb access between the two processes, do you think adding a CDC component over the FSL Usb stack in MSD and using the same critical sections for the two could work?
Please advise,
Mevon
LikeLike
I’m looking into the msd_and_cdc example of the composite app given with the usb 4.1.1 stack. I know it would be magical thinking that someone would make a PEx component out of it and specially for the K20 50 and 72… 😀 😀 😀 If somebody could teach me (*wink wink*), I could write an article on the subject! I know I want to learn more about PEx object creation and can’t really wait for the KDS to come out and only find out it cannot help me with my cpu choice.
Mevon
LikeLike
Creating and maintaining such a component would be an excellent thing, but this requires time and efforts (which I currently do not have, I need to do my paid job too ;-). The Freescale web has training material on Processor Expert component creation (google for Processor Expert CDE).
LikeLike
Good progress today, I can say Im glad I “transmuted” the msd_and_cdc project for the K21 to a K20. I chose bare metal for now, I grasp a lot more on how things are done internally.
LikeLike
So the cake is a lie, the cake is lie, the cake is a lie… :S Just installed the KDS just to find out it’s just another name for Processor Expert inside Eclipse provided to you by Freescale… 😦 I don’t know what I was expecting but not a mere copy of the CW IDE under a different name, I had my hopes too high for an “Assistant” that would walk me through the basic design with simple questions and auto-magically give me a complete solution like baking muffins in the oven… I guess they are just starting fresh under a different name.
LikeLike
I think you are oversimplificating the things here. KDS is pretty much EclipseKepler+Processor Expert, but it is very much different than CW. The debugger is completely different.
LikeLike
Hi Erich,
I was trying out the new KDS and build a CDC device with your PEx components. For some reason I had better results then with the CW_IDE 10.6 I have tried before and my MK20DX128VLH5 board (teensy3) is detected by win7-x64 as an Unknown Device now. The problem is when I try to install the driver, it says the CDC.inf generated (or the one with the usb 4.1.1 stack) is not compatible with 64 bits architecture my windows has (error: “The folder you specified doesn’t contain a compatible software driver for your device. If the folder contains a driver, make sure it is designed to work with Windows for x64-based systems.”). I will try the procedure on this site http://curiouslynerdy.com/2009/10/usb-communications-device-class-on-64-bit-windows/ but I was wondering if you had any advice for me now?
Thanks in advance,
Mevon
LikeLike
Hi Mevon,
I have used that .inf file (generated in the Generated_Code of the processor expert project) without problems both on Win7 and Win8 64bit systems. I know that the .inf file inside the 4.1.1 stack was not working for me, but the one inside the Generated_Code did. Have you tried this one?
Erich
LikeLike
Hello Erich,
Yes I tried both with no success. I’m beginning to think it might have to do with my clock settings because when I plug it in a win8, device manager describes it as an “Unknown Device (Invalid Response)”. I know my board has a 16MHz xtal so maybe it’s something I didn’t set right in the CPU component.
LikeLike
Yes, for me in the past these were the issues. Can you verify your settings that you generate a 48 MHz PLL clock, and that this is routed in the CPU component (on the bottom) to the USB block, and that the USB peripheral has the clock enabled?
For example, have a look here:
LikeLike
Ok, I followed the instructions in the link but no luck yet. I did get to make the led blink but only after disabling all the initializing functions of both usb components. Also, I could say that the blinking seems a little slower of what it should be ( 500ms on + 500ms off (in code) = more then 1 sec (in reality)) . Adding only the stack init and call init works but no valid usb device is found. When I add the CDC init, the device seems to fall in limbo as in the tensyduino programmer sees it in constant reset and the blinking stops. I have disabled the usb interrupt requests and now the blinking is back but still got an unknown device that win7 tells me needs a x64 driver for it. I have this message in the properties : “Windows has stopped this device because it has reported problems. (Code 43)”, and the VID and PID are 0000. When I program it with arduino and the blink example, I do get the COM port and everything is all good. I tried changing the pid and vid in the PEx component and driver to the T3s but still windows sees 0000 for both. I know there’s also a MINI54TAN usb chip to program the MK20DX50 but it shouldn’t be in the way for enumeration (http://www.pjrc.com/teensy/schematic.html). Or maybe it is, where could I put a delay to make the enumeration later in the boot sequence so it could wait a little after reset before going on with the CDC init?
LikeLike
Really hard to tell from the remote. The Init() function shall not take long at all. Can you debug it to see where it is stuck? Maybe a stack overflow (can you increase the stack size?)?
LikeLike
Hi Erich,
by “generated in the Generated_Code of the processor expert project” you mean in the “Documentation” folder? Because I don’t have a .inf in the “Generated_Code” folder.
LikeLike
Yes, I meant the Documentation folder. Sorry about that mix-up.
LikeLike
Still can’t get it to work on my Teensy3 😦 Can you help me configure properly the Cpu component for a 16 MHz external crystal? Originally, this board is running at 96 MHz with the PLL so I use PEE in the MCG settings, core and bus clock settings are at 48 MHz and flash is at 24 MHz. I disabled the NMI, watchdog and most of all the interrupts but maybe I’m missing something somewhere I can figure out what. Maybe I should even buy a Teensy board for you so you could help me better… This board has full arduino integration and support but nothing for CW_IDE or KDS. Just having basic PEx configuration would be huge step for the T3 community. Please, help! 🙂 I can even write all the articles needed for you so you can publish them on this site!
LikeLike
Hi Mevon,
combining two USB devices is for sure not something like adding semaphores, as there is one interrupt for all the end points, so you need to dispatch the packets accordingly.
LikeLike
Yeah, over simplify to auto-magically receive my truly wishes or so 😛 (thats the secret… lulz) Hum now for sure it won’t be that easy but I still plan to start my work from your CDC component, see where the stacks splits off from your work and the composite app, like taking the head of a giraffe and stick it on an elephant’s body, easy peasy! I’m sure going to read this one: https://mcuoneclipse.com/2013/03/31/tutorial-creating-a-processor-expert-component-for-an-accelerometer/, try to find where you do all the protocol of your usb endpoints and put in a switch case, got to find out how to add some parameters to the component and link it to the SD or FAT system component. For all I care, the MSD part could be running in the background and maybe the FAT should be modified to accommodate concurrent access to the files (not sure but I think that’s why it has re-entrant properties) with a critical section?
work in progres
LikeLike
Your FSL_USB_Stack component works great for me as a CDC device. Do you have any plans to integrate the Printer Class? I’m working on going through the Freescale example project for a printer host, but really like the way yours integrates and works.
LikeLike
For now I have no plans to adopt the printer class, as I have no usage for it for now. I’m using a serial printer which works great for me (https://mcuoneclipse.com/2014/03/09/tutorial-thermal-printer-part-1-hardware-setup-with-frdm-board/). Can you tell for what you want to use the printer class.
LikeLike
Hello Erich,
Do you plan to make wrapper for USB MSD device, also?
There is support in freescales usb stack.
BR,
Zoran
LikeLike
Hi Zoran,
this already exists, see
Erich
LikeLike
Ups! I see you meant MSD device. I have implemented USB MSD host only for now. But USB MSD device should not be too difficult.
LikeLike
Great, so you will fix it 🙂
LikeLike