MK22FN128 USB VCOM

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

MK22FN128 USB VCOM

1,653 Views
akimata
Contributor IV

Hello,

I'm struggling with USB vcom example for quite a lot of time, it worked me when i used exactly the same chip as on FRDM-K22F board which is MK22FN512VLH12, but i decided to switch to little cheaper microcontroller to save some money but example is no longer working.

I did some changes in example to run on my custom boards(using internal clocks) and it  works just fine on my custom board with MK22FN512 but when i load it to MK22FN128 it no longer works :smileysad:. Could u please point me in the right direction or tell me another solution how to add simple vcom to my application? 

Also this driver takes 18Kb of RAM  and MK22FN128 got 24kb but it's split into 16kb and 8kb so probably i need to change some things to make this work?

pic1.PNG

I setup memory as shown above but it ends up with an error:

pic2.PNG

Is it safe to reduce heapsize from 0x2000 to 0x1200 using this application or it will cause problems?

pic3.PNG

Oh and i forgot that i can't change clocks using clock tool in examples when changing mcu, because it wants to overwrite previous common drivers, after that operation example no longer compiles, any solution to that? 

Thanks for any help :smileyhappy:

0 Kudos
Reply
11 Replies

1,313 Views
mjbcswitzerland
Specialist V

Hi Grzegorz

The K22FN128 is an F9 K22 and so quite different to the K22FN512, which is an F7 type K22. This is on top of the fact that you have reduced from 128k SRAM to 24k SRAM, which may have consequences for the existing application (do you know how much memory your will require for the complete operation?)

I expect that you will need to use a different SDK package and so build up the project again based on that.

In case you continue having difficulties see the uTasker open source project (on Git hub) which has industrial proven USB CDC and a generic library that operates on all parts (avoiding porting needs between them). If you have professional demands consider also the uTasker professional version with support since it will ensure project success and gives efficient, low memory footprint solutions, including USB-CDC (supporting up to 6 instances on the K22 and USB composites).

Regards

Mark

Complete Kinetis solutions, training and support: http://www.utasker.com/kinetis.html
Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
- http://www.utasker.com/kinetis/tinyK22.html

0 Kudos
Reply

1,313 Views
akimata
Contributor IV

I'm sure that my application will fit on 24k SRAM but the problem is that SDK for K22FN128 does not have usb examples(actually it does but only for FRDM-K22F board which uses diffrent chip) which is the main problem here. I'm not that good to write my own usb driver.

What u mean by that these chips are quite diffrrent? I looked into datasheets and most of the things looks almost the same with small changes.

I'm using USB to mainly receive serial commands.  Will i be able to do that using utasker? Because only files i see are .bin which i can't really look into and modify  and build into my existing project.

The source of USB drivers doesn't really matter for me as long i can build it into my existing project to receive serial commands. If you could tell me how exactly i can use utasker USB in my application i would be really grateful because i'm not familiar with uTasker at all.

0 Kudos
Reply

1,313 Views
mjbcswitzerland
Specialist V

Hi

The two chips have different user manuals specifically due to various details that are different - not all are specific to USB but to other peripherals and capabilities and so the drivers also need some adjustments to suit.


The uTasker project contains USB-CDC to command line interface. You can test it by loading following the binary file to your FRDM-K22F board:
www.utasker.com/kinetis/FRDM-K22F/uTaskerV1.4.8_FRDM-K22F.bin

In addition it performs USB to UART bridging with end-to-end flow control and so is not an example of USB-CDC operation but instead a complete solution for typical USB-CDC requirements.

The source code is on Github (the binary files are pre-built applications and not intended to be used as source code).

You can get some more information at http://www.utasker.com/docs/uTasker/USB_User_Guide.PDF
whereby USB-CDC looks like a UART to the application and so the user doesn't need to change any code when switching command line interfaces between UART an USB-CDC. In addition it allows USB operation to be simulated in Visual Studio to already test and debug all code in a more efficient environment, or to analyse the USB operation of the driver or the chip itself.

Regards

Mark

0 Kudos
Reply

1,313 Views
akimata
Contributor IV

But still i have no clue how can i build your example into my code, i need simple solution so it seems it won't be useful for me at this point. The easiest way should be to make frdm-k22f vcom example work with mk22fn128(because i already got everything wrriten for this example) but not sure if that's even possible.

Yeah mk22fn512 and mk22fn128 are a bit different but nothing that i'm not aware of, so after memory location change it should work but it don't.

USB is almost the same on both chips(different voltage input). The best solution would be if someone could test frdm-k22f example on mk22fn128 chip.

0 Kudos
Reply

1,313 Views
mjbcswitzerland
Specialist V

Hi

Unfortunately I don't think that you have the experience to be able to use the uTasker code in our project so you may  need to debug and adapt the example that you have from the K22FN512. You already know that it doesn't run on the K22FN128 so you need to investigate why not and what needs to be changed.

Initially you need to start with an analysis of the clock configuration since it sounds as though the FRDM-K22F example is using the PLL, which doesn't exist in the K22FN128:

pastedImage_1.png

pastedImage_2.png
Top is from K22FN512 - bottom is from K22FN128 (note the absence of the PLL).

You can also try to configure the original FRDM-K22F project to use the IRC48M (crystal-less) because then the clocking would already be the same and then moving to the K22FN128 will be a smaller step.

In the uTasker project this is selected by a define:

#define USB_CRYSTAL_LESS                                         // use 48MHz IRC as USB source (according to Freescale AN4905 - only possible in device mode) - this should always be used if not external !!

but it may be that the FRDM-K22F examples don't support this and so needs to be copied from other sources or developed form the ground up. There is a reference to crystal-less mode (and potential erratas that need to be worked around) at: http://www.utasker.com/kinetis/MCG.html

Beware also that the K22FN128 can only be used as USB device and can't be used a USB host unless a dedicated 48MHz oscillator input is supplied!

In fact the reference binary that I linked to is already using crystal-less mode on the FRDM-K22F and so would also run on your K22FN128. I can send you an operating project for your chip (and board) but it would need the ability on your behalf to add the library code to your project. A simpler technique is usually to take your existing application code and insert it into the uTasker framework since this avoids any complications, gives optimised drivers and the capability to simulate the complete operation which reduces development time and effort (and saves costs in professional work).

Regards

Mark

0 Kudos
Reply

1,313 Views
akimata
Contributor IV

Thanks Mark,

Indeed it seems that the problem was with clock, i moved  clock_config files and fsl_clock files from MK22FN128 project into USB example and it worked without problems.

There is only one last problem, example takes more than 16kb or ram, which actually will overflow SRAM_upper. Temporary solution was to change heapsize and change global data placement which allowed me to compile and flash. I'm not sure if it's good solution or it will have consequences eventually.

pic55.PNG

0 Kudos
Reply

1,313 Views
mjbcswitzerland
Specialist V

Hi

I don't know details about the examples use of memory so it is wise to analyse what it is using it for and how to dimension it to suit your own needs. Using examples blindly for real project work (when you know that the memory is somewhat restricted) is never a good idea so this is an investment that is necessary for serious work to avoid risks and potential product failure later.

Beware that the new clock configuration may be using the IRC48M (also for USB)  but it may not be working in crysal-less mode. This will usually work on the lab bench but will not pass any USB compliance testing and will tend to cause unreliability in the field. If you are doing more than a school or hobby project which only needs basic functionality for a limited period of time you will need to ensure that the mode is applied correctly in the USB controller to ensure long term product reliability.

Regards

Mark

0 Kudos
Reply

1,313 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Grzegorz:

This is because K22fn128 doesn't have a PLL , USB clock not being exactly 48MHz.

The FLL has high jitter and not allow party USB certification.

The option for USB operation is the internal 48MHZ clock(IRC48).

You can refer to AN4905 for more information.

https://www.nxp.com/docs/en/application-note/AN4905.pdf 

Regards

Daniel

0 Kudos
Reply

1,313 Views
akimata
Contributor IV

I'm aware that FLL can't be used with USB, clock tool won't even allow me to set FLL as source for USB so that's not the case, main clock is sourced from FLL but USB is from internal 48Mhz clock. I'm pretty sure the example hangs on some KHCI functions i will post where exactly when i get back home.

Could u confirm somehow if frdm-k22f usb example will work on k22fn128 chip? 

0 Kudos
Reply

1,313 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Grzegorz:

Sorry, the default settings is for FN512, it won' t work.

you need to update the  linker file , flash size to 128.

Regards

Daniel

0 Kudos
Reply

1,313 Views
akimata
Contributor IV

As you can see on the pictures in the main post i changed MCUxpresso settings for 128kb flash, 24kb of ram, changing it will also change linker file so that's not the problem.

The main question is if there is any FN512 settings hardcoded into the example which will lead to problems.

0 Kudos
Reply