How to create an example usb_device_SD_card project of MK50DN512 in MCUXpresso?

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

How to create an example usb_device_SD_card project of MK50DN512 in MCUXpresso?

2,442 Views
yinni
Contributor III

Hello,

I would like to use the usb device function of MK50DN512. First I looked at the MK50DN512xxx10, there is a usb_device_msc_sdcard example under board twrk60d100m folder. I followed instruction given in "MCUXpresso SDK USB Stack User's Guide.PDF", imported the usb SDK example, modified pin_mux.c file that suits my system. But the created usb example is based on MK60 MCU, eventually I did not make it work with my MK50DN512.

I also attempted to create a new MCUXpresso K50 project with MCUXpresso_Config_Tools_v6, but failed because the software refuses to do so and just suggests me to create a project within MCUXpresso directly, that way that I have just failed.

Could someone help?

Thanks!

Labels (1)
0 Kudos
Reply
8 Replies

2,222 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

You can use MCUXpresso Cfg tools to generate clock, pin config and peripheral config code. At the right side of each config interface there is a code preview window. Click the export icon, the .c and .h file will be generate to certain folder. Or you can just select all and copy the content in code preview window.

Regards

Jing

0 Kudos
Reply

2,222 Views
yinni
Contributor III

Hi Jing,

Thanks for the suggestion. I have created a new project based on MK50DN512, and copied the files from twrk60d100m SDK example (usb_device_msc_sdcard_lite_bm), compiled and downloaded to my MK50DN512 board. When I connect the board to my computer, it turned out that my board can not be recognized as a USB device. I attached the error image and also the project. Would you be able to take a look?

Many thanks in advance!

0 Kudos
Reply

2,222 Views
mjbcswitzerland
Specialist V

Hi

You have a problem with USB - you need to show the USB interface on your HW and also the clock used.

If it isn't possible to generate an accurate 48.0000MHz USB clock this is the behavior expected.

For example, I see in your clock_config.h this

#define BOARD_BOOTCLOCKRUN_CORE_CLOCK              95977472U  /*!< Core clock frequency: 95977472Hz */

96.977472MHz is not suitable for USB operation and will fail - where does this define come from??
Are you trying to use FEE (which is not possible with USB)  rather then PLL based on a suitable oscillator or crystal?

Regards

Mark

uTasker project developer with experience of > 100 Kinetis based industrial/consumer product developments in > 20 countries.

2,222 Views
yinni
Contributor III

Hi Mark,

Thank you so much for the reply. I checked our K50 board and checked system clock of K50, and realized we don't have an external clock source. The existing system uses FEI mode, i.e. the MCGOUTCLK select FLL to generate core, bus, and flash clocks. 

BUT we have a 32.768KHz crystal for RTC! Then theoretically I can enable PLL, and select MCGPLLCLK for USB, set SIM_SOPT2_USBSRC to 1, change SIM_CLKDIV2[USBFRAC, USBDIV] to generate 48MHz usb clock. Is this right?

Regards,

Yinni

0 Kudos
Reply

2,222 Views
mjbcswitzerland
Specialist V

Hi Yinni

The PLL requires an input between 2 and 4MHz and so can't use the 32.768kHz crystal - the 32.768kHz crystal input can only be used as FEE reference, which won't work for USB.

You have the choice of adding an external 48MHz oscillator to the USB_CLKIN pin, changing the crystal or moving to a more modern chip (with similar pin-out) such as a K22 with crystal-less USB.

See overview of MCG and clocks at:

http://www.utasker.com/kinetis/MCG.html


Regards

Mark

2,222 Views
yinni
Contributor III

Hi Mark

There isn't a USB_CLKIN pin on K50, I wanted to use an external clock and PEE mode so that we can add USB function, and still use the example from k60 SDK (usb_examples_usb_device_msc_sdcard_lite_bm).

I added a 4MHz crystal between pin EXTAL0 and XTAL0, and tried switch MCG modes as:

                             FEI --> FBE -->  PBE --> PEE

Problem is I always stuck at CLOCK_SetPbeMode function (please check the attached).

I have changed CPU_XTAL_CLK_Hz and oscConfig_BOARD_BootClockRUN.freq to 4MHz. I couldn't see get pulses at pin EXTAL0. The project is attached too.

Many thanks in advance!

Regards,

Yinni

0 Kudos
Reply

2,222 Views
mjbcswitzerland
Specialist V

Yinni

If your crystal is not starting try changing the gain mode setting in MCG_C2.
If the wrong gain is set it is common that the crystal oscillator doesn't start - set the gain mode flag differently and it may then work.

Regards

Mark

0 Kudos
Reply

2,222 Views
mjbcswitzerland
Specialist V

Hi

If you have difficulties just use the free open source uTasker project which includes K50 USB-MSD to SD card as standard, including simulation of the K5x and the card in Visual Studio and ready to build MCUXpresso project.
All code, documentation and video guides in the links below.

Regards

Mark

Complete Kinetis solutions for faster/more efficient professional needs, training and support: http://www.utasker.com/kinetis.html
i.MX RT project compatibility: http://www.utasker.com/iMX.html
Including FreeRTOS integration for all Kinetis parts

Kinetis K53:
- http://www.utasker.com/kinetis/TWR-K53N512.html


uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market

Request Free emergency remote desk-top consulting at http://www.utasker.com/services.html

Open Source version at https://github.com/uTasker/uTasker-Kinetis

https://community.nxp.com/thread/512558
https://community.nxp.com/thread/352862
https://community.nxp.com/thread/498809

0 Kudos
Reply