Creating a New USB project with KSDK and Processor Expert support in KDS

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

Creating a New USB project with KSDK and Processor Expert support in KDS

No ratings

Creating a New USB project with KSDK and Processor Expert support in KDS

Hello KSDK fans:

 

As you may know, KSDK provides comprehensive software support for Kinetis MCUs to accelerate application development. Besides providing Hardware abstraccion layer and peripherals drivers it can be Processor Expert capable.

 

Here is an example on how to create a new project with KSDK and Processor Expert support.

 

It shows a simple USB HID example that is ready to add your application code by using either KSDK drivers or Processor Expert support.

 

I hope this can help you.

 

Regards,

 

Isaac Avila

Labels (1)
Attachments
Comments

Hello Avila,

I was trying to run this example but on the code we have two "USB_App_Class_Callback" function. So, what is the right one ?

Can you help me ?

Best Regards

Rodrigo Campello

Hi Rodrigo,

It is the same function (it is an error when copying this function into document). I updated document and if you have any doubt please let me know it.

Best Regards,

Isaac

I'm trying to accomplish something similar to what this guide shows but different enough that it doesn't help that much.  I have the TWR-K21F120M and I need to implement USB MSD using Processor Expert components with no OS.  Is there any resource you can point me to in order to accomplish this?

maybe this helps:

USB for the TWR-K21F120M | MCU on Eclipse

It is for CW, but the components are both for CW and KDS.

I don't have the board with me right now. I might be able to find time next week to provide a KDS project for it (but no promise yet).

I hope this helps,

Erich

Hi Kevin,

Since TWR-K21F120M has been supported by SDK 1.2, so you may refer to How to implement a USB Device MSD demo based on KSDK PEx components and KDS 3.0 for details.

Hope that helps,

Best regards,

Kan

Erich,

I had tried at one point to implement your example but had some issues.  I import the project, and go to build it using "FLASH" Build Configuration and I get "Nothing to build for project TWR-K21F120M_USB_CDC" in the console. I also get the following warnings:

  • Invalid project path: Include path not found (\ARM_GCC_Support\ewl\EWL_C\include).
  • Invalid project path: Include path not found (\ARM_GCC_Support\ewl\EWL_Runtime\include).

If I go into Project > Properties, I have this message shown "Orphaned configuration. No base extension cfg exists for org.eclipse.cdt.cross.arm.gnu.sourcery.windows.elf.debug.1399443770"

***EDIT*** - I used a different build configuration and I can get it close but now I have the "fatal error: ansi_parms.h: No such file or directory"

I'm not sure how to address these errors.

Do you have much experience with the USB_LDD/LDDs in general? Is Freescale phasing out the fsl_... components and moving to ...LDD in KSDK 1.2?

Thanks,

Kevin

Hi Kan,

I setup a project using that tutorial and I got it built and running but I can't get the drive to show up when I connect the second micro USB port to my PC.  I tried using the Mini USB port on the TWR-SER module as well.

Kind of unrelated, but do you know why it is that if I start a project using the TWR-K21F120M Board configuration I can use all the fsl_... components but if I start a project with the Processor off of the TWR-K21F120M instead, it tells me that the fsl_... components aren't compatible with the processor?  Is this correct?

Thanks,

Kevin

Hi Kevin,

I just built the MSD device demo on TWR-K21F120M as  the tutorial , it works as expected, just note when you connect the second micro USB port to PC, you have to change the J8 settings on board, from 1-2 to 2-3. the platform version is 700-27470 REV X1, SCH-27470 REV A. Please check if the same board on your  hand. I also attach the project in the tutorial for your reference, the name of that project is msd_device_twr_k21f.zip.

For the second question, I think  it is because some the KSDK's driver is related with the platforms, for example, PLL init code. so PEx would check when you specify a board or just MCU at the start. if the specified board is supported by ksdk, the peripheral drivers and HAL drivers will be available, if you just specify the MCU or some unsupported platform, the KSDK component will be filtered anyway.

Hope that makes sense,

Have a great day!

Best Regards,

Kan

How does  this function  "USB_Class_HID_Send_Data()" works?
it just keeps sending  words such as A when i used this function.

how to send just a A not As .

Hello Heng,

This function sends HID data specified by third and fourth parameters (app_buff - buffer where data is saved and size - number of bytes to send). Once data is sent, application layer receives a callback event USB_DEV_EVENT_SEND_COMPLETE that means transfer has been sent. (You can look for this information on USB Stack Device Reference manual located in KSDK doc folder).

Remember that for HID class, there are reports that specifies how HID data is interpreted.

I don't understand quite well what you are refering with "how to send just an A not As .", are you trying to use HID class like a keyboard device or you need something more like a CDC class?

Regards,

Isaac

Hi,

I try to setup a new USB project on the FRDM-KL25Z.

But I face a problem where the interrupt handler seems to not be sets properly.

I followed "Creating a New USB project with KSDK and Processor Expert support in KDS.pdf"

And replacing things for my uc and board KL25Z.

When I debug the project and then pause it, it is hang in the default IRQ handler.

pastedImage_0.png

Any one made works on KL25Z ?

I can use the demo project project directly and it works. But my project always freeze there.

regards,

Hi Isaac,

Is there a similar document available for CDC driver, for PEx based bare-metal KDS project? I will be targeting KL27Z and K80 devices.

Thanks,

-Irwin

Hello Irwin,

There is no similar document but you can follow this document and try to change HID application for USB CDC. If you analyze this document, USB application (HID) is taken from KSDK's examples, so you can replace this application for the one shown in CDC example.

You can check this post where i added PEx to a CDC example:KL43Z USB CDC in KDS & PEx

I hope this can help you,

Best Regards,

Isaac

Hi Isaac,

I was able to use the referenced document to implement USB CDC for KL27Z target, with PEX and KSDK 1.2. On the other hand, MK80 MCU is only supported with KSDK 1.3 and USB stack seems to be missing CDC implementation. How do I go about the implementation then? 

Thanks,

-Irwin

Hello Irwin,

In KSDK 1.3, there is support for MK80F256 and also there is a CDC example for it, you can look at: <KSDK_1_3_PATH>\usb\usb_core\device\lib\bm\kds\MK80F25615 for USB library and <KSDK_1_3_PATH>\examples\twrk80f150m\demo_apps\usb\device\cdc\virtual_com for CDC reference.

I hope this can help you!

Regards,

Isaac

Hi Isaac,

Thank you for pointing out the example project. I have followed it as closely as possible for implementation with PEX based KDS 3.0.0 project.  I am able to compile it without errors but enumeration does not complete.

APP_init(); throws an exception. One substitution I had to make in  APP_init() function to fix error is as follows:

     //    cdc_config.board_init_callback.callback = usb_device_board_init; // commented out as there is no board.h

             board_init_callback.callback = NULL;  // is this correct?

So, I am stuck with non-operational code for now. Any other suggestions?

Thanks,

-Irwin

Hello Irwin,

Indeed, in virtual_com example, the usb_device_board_init function does not have anything to be initialized, so for now, you can use the board_init_callback to be null.

What errors are you seeing on enumeration?

Regards,

Isaac

Hi Isaac,

After the code completes execution of APP_init(), it seems to encounter some unhandled interrupt:

1) Single stepping the code does not work when the exception occurs.

2) Pausing the execution puts the code in startup_MK80F25615.s file, line 333 (at b DefaultISR):

       DefaultISR:

           b DefaultISR

3) Windows displays the message that, "USB Device Not Recognized"

      "One of the USB devices attached to this computer has malfunctioned, and Windows does not recognize it. For assistance in solving this problem, click this message"

Now I know I have the correct drivers as I have been able to test example program and the one implemented in KL27Z (PEx and KSDK 1.2).

Thanks,

-Irwin

Hello Irwin

It is hard to debug without an USB capture, you can check this thread to see if this is what happends to you (This is for KSDK 1.3): KDS/KSDK K20 USB Driver Mutex Problem.

I hope this can help you!

Best Regards,

Isaac Avila

Hi Isaac,

That is exactly right! I tried the first solution proposed under KDS/KSDK K20 USB Driver Mutex Problem  and it is running fine now. Thank so very much!

Regards,

-Irwin

I am having a same issue with KL27Z target (KDS PEx project with KSDK 1.3). This had worked no problem with KSDK 1.2.

I also tried the fix proposed in KDS/KSDK K20 USB Driver Mutex Problem but that did not resolve it.

-Irwin

Hi Isaac,

I have run into a similar issue with KL27Z target now ( see my response above to Lo Pe, with screen-shot of the problem in his KL25Z). KDS/KSDK K20 USB Driver Mutex Problem does not help in KL27Z's case.

I see that code hangs up at line 946 of usb_cdc.c:

       usb_device_init(controller_id, (void *)&cdc_config_ptr->board_init_callback, &devicePtr->controller_handle);

This is called from within App_init() by:

      USB_Class_CDC_Init(CONTROLLER_ID, &cdc_config, &g_app_handle);

What could be going on in this case?

Thanks,

-Irwin

Hi Isaac,

My target MCU is MKL27Z128VLH4. I was initially using the KL27Z644 platform library. Which I have changed to:

  "${PROJECT_KSDK_PATH}\lib\ksdk_platform_lib\kds\KL27Z4\debug\libksdk_platform.a"

However, there is no core library for target device and I am still using:

  "${PROJECT_KSDK_PATH}\usb\usb_core\device\lib\bm\kds\MKL27Z644\debug\libusbd_bm.a"

Could this be the problem? Where is the USB core library for MKL27Z128VLH4 device if that is the case?

Thanks,

-Irwin

Hello Irwin,

if you look to Kinetis SDK v.1.3.0 Release note you will find a table (Table 2. Supported MCU devices and development boards) you will see that compatible target for MKL27Z128VLH4 is KL43 either in FRDM or TWR boards, so, you should use KL43's USB library and modify the CPU definition.

You can see the old document that is shown in this thread: USB CDC on KL27 processor , it talks about cloning a library for KL27. I will upload another document talking this same topic but for now, you can use this.

I hope this can help you!

Best Regards,

Isaac Avila

Thanks Isaac! Correct library resolved the hang-up issue. However, I can't explain why Windows is now not recognizing the CDC device!!

It gives the message:

"USB Device Not Recognized"

"One of the USB devices attached to this computer has malfunctioned, and Windows does not recognize it.

For assistance in solving this problem, click this message"

Regards,

-Irwin

Hello Irwin,

It is hard to know what is happening without an USB capture, I will hope that this same code will work for your K8x and your KL27 but somehow seems to be something else, I don't know if this is related to USB access to flash (please check this thread: PE-generated USB code does not seem to work ) or another topic.

I invite you to create a new thread in the community about this issue instead of using this document's space.

Best Regards,

Isaac Avila

Hi Isaac,

Pertaining to this thread itself, another issue uncovered is that the usbd_sdk_bm_lib_MK80F25615 board support project ( usb_dev_bsp.c) overwrites PEx clock component settings. How do I make sure that clockMan1:fsl_clock_manager settings are used? This is part of the problem where crystal hanging off the MCU does not start (verified it on FRDM-K82F board as well). I am using PLL for 144 MHz core clock and have modified usb_dev_bsp.c as in bold:

    if (USB_CONTROLLER_KHCI_0 == controller_id)
    {
#if (0)
///#if USBCFG_DEV_USE_IRC48M
        /* Select PLL output clock as an output of PLLFLLSEL clock multiplexor.  (Register: SIM_SOPT2, bits group PLLFLLSEL) */
        /* Note: This selector also influences clocking of others peripherals such as TPM, SDHC, LPUARTS, I2S/SAI, FlexIO, EWM, etc. */
        CLOCK_SYS_SetPllfllSel(kClockPllFllSelIrc48M);
        /* Select output of USB clock divider as a clock source for USBFS peripheral. (Register: SIM_SOPT2, bit USBSRC) */
        CLOCK_SYS_SetUsbfsSrc(instance, kClockUsbfsSrcPllFllSel);
        /* Set USB clock divider */
        CLOCK_SYS_SetUsbfsDiv(instance, 0U, 0U);
        /* USB Clock Gating */
        CLOCK_SYS_EnableUsbfsClock(instance);
        /* Enable IRC 48MHz clock module */
        usb_hal_khci_ungate_irc48m(base_addres);
        usb_hal_khci_enable_irc48m_recovery_block(base_addres);
#else
        /* Select PLL output clock as an output of PLLFLLSEL clock multiplexor.  (Register: SIM_SOPT2, bits group PLLFLLSEL) */
        /* Note: This selector also influences clocking of others peripherals such as TPM, SDHC, LPUARTS, I2S/SAI, FlexIO, EWM, etc. */
        CLOCK_SYS_SetPllfllSel(kClockPllFllSelPll);
        /* Select output of USB clock divider as a clock source for USBFS peripheral. (Register: SIM_SOPT2, bit USBSRC) */
        CLOCK_SYS_SetUsbfsSrc(instance, kClockUsbfsSrcPllFllSel);

        /* Set USB clock divider */

        switch (CLOCK_SYS_GetUsbfsSrc(instance))
        {
        case kClockUsbfsSrcPllFllSel:
            switch (CLOCK_SYS_GetPllFllClockFreq())
            {
            case 144000000U:
                CLOCK_SYS_SetUsbfsDiv(instance, 3, 0);
                break;

...

...

These changes still don't seem to be allowing PEx clock settings to entirely take effect. So, I would like your recommendation as how best to resolve this.

Thanks,

-Irwin

Hi Isaac,

I noticed that in the KSDK 1.2 there's only a driver for mouse and keyboard.  I need one for a Mass Storage device, is there one 

available and if not, is there documentation on how I could create one?

Thanks,

Neil

Version history
Last update:
‎06-29-2015 02:01 PM
Updated by: