USB Component Splitted and Updated

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_Stack with Sub-Components

FSL_USB_Stack with Sub-Components

FSL_USB_CDC_Device Class Component

Everything related to the CDC class is now inside the FSL_USB_CDC_Device sub-component:

USB CDC Device Properties

USB CDC Device Properties

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:

USB Main Properties

USB Main Properties

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 🙂

Advertisements

59 thoughts on “USB Component Splitted and Updated

  1. 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?

    Like

    • 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.

      Like

  2. 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

    Like

  3. 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

    Like

    • 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.

      Like

      • 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.

        Like

  4. 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?

    Like

  5. Pingback: USB CDC with the FRDM-K20D50M | MCU on Eclipse

  6. 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

    Like

    • 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?

      Like

      • 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

        Like

        • 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?

          Like

      • 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. 🙂

        Like

      • 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

        Like

    • 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

      Like

  7. 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

    Like

  8. 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

    Like

    • 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

      Like

      • 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).

        Like

      • 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.

        Like

      • 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.

        Like

        • 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.

          Like

        • 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

          Like

        • 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

          Like

        • 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.

          Like

        • 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?

          Like

        • 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?)?

          Like

        • 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.

          Like

        • 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!

          Like

    • 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.

      Like

      • 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

        Like

  9. 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.

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.