element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Documents Codewarrior Tutorial for FRDM-K20D50M: USB MSD Host
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: FreescaleTools_and_Software
  • Date Created: 8 Aug 2013 1:26 PM Date Created
  • Last Updated Last Updated: 8 Aug 2013 1:42 PM
  • Views 641 views
  • Likes 0 likes
  • Comments 0 comments
Related
Recommended

Codewarrior Tutorial for FRDM-K20D50M: USB MSD Host

This tutorial was extracted from Erich Styger blog http://mcuoneclipse.wordpress.com with his agreement.

imageimage

 

 

The Freedom boards FRDM-KL25Z RevE and FRDM-K20D50M make it easier to use it as USB Host device, as they come with a special jumper to provide 5V to the USB device, so my earlier ‘hack’ is not needed any more :-) . After I had USB MSD Host working for the FRDM-KL25Z, it was much harder to get the USB stack working for the FRDM-K20D50MFRDM-K20D50M board, because somehow the example Freescale provided with their USB stack refused to work properly on my board. After debugging it for several nightly hours, I decided to take my working Processor Expert project for KL25Z and added support for the K20. And the good news is: since tonight this is working :-) .
 

FRDM-K20D50M as USB MSD Host 

FRDM-K20D50M as USB MSD Host
 

 

USB Host Jumper

By default, the FRDM boards do not supply 5V to the USB connector. But that 5V is required to attach a device like memory stick to power the MSD device from the host (the FRDM board). On the FRDM-KL25Z RevE I can set a jumper to provide the 5V to the bus:
 

USB Host Jumper on the FRDM-KL25Z RevE

USB Host Jumper on the FRDM-KL25Z RevE
  

A similar jumper is present on the FRDM-K20D50M board:
 

FRDM-K20D50M with USB Host Jumper

FRDM-K20D50M with USB Host Jumper
  

Example Application

The example application runs a command line shell over OpenSDA virtual COM (USB CDC):
 

FRDM-K20D50M with USB MSD Host

FRDM-K20D50M with USB MSD Host
 

USB enumeration is shown with a RGB LED which blinks either green or red. As file system the application runs FatFs. Below are some points to consider if you want to build your own application from scratch:
 

Clock Settings

The clock needs to provide 48 MHz to the USB peripheral. As the FRDM-K20D50M has an external 8 MHz crystal, I configure this in the CPU settings:
  

FRDM-K20D50M configured to use 8 MHz Crystal

FRDM-K20D50M configured to use 8 MHz Crystal
 

The clock is configured for PEE mode to produce an 48 MHz PLL output:
 

MCG in PEE mode with 48 MHz PLL Output

MCG in PEE mode with 48 MHz PLL Output

 
The System Clocks are configured as below:
 

System Clocks

System Clocks
 

:!: Do not forget to set the PLL/FLL clock choice to ‘PLL clock’ with 48 MHz, otherwise USB will *not* work. I missed that myself, and have lost many hours of debugging :-( .

  
Processor Expert USB Component

The FSL_USB_Stack Processor Expert component is configured as below:
 

FSL_USB_Stack Component Settings

FSL_USB_Stack Component Settings
 

The FSL_USB_MSD_Host component settings only needs to know for which CPU it is:
 

FSL_USB_MSD_Host Component Settings

FSL_USB_MSD_Host Component Settings
  

MSD Host Application

I’m using a FreeRTOS task to perform the USB processing with interrupts: 

 

 

   
/*

* host.c

*      Author: Erich Styger

*/

 

#include "host.h"

#include "msd_commands.h"

#include "CLS1.h"

#include "FRTOS1.h"

#include "FsMSD1.h"

 

static void print(unsigned char *str) {

  CLS1_SendStr(str, CLS1_GetStdio()->stdOut);

}

 

static void CheckStatus(void) {

  switch (FsMSD1_GetDeviceStatus()) {

     case USB_DEVICE_IDLE:

       break;

     case USB_DEVICE_ATTACHED:

       LEDR_Off();

       LEDG_On();

       print((unsigned char*)"Mass Storage Device Attached\n" );

       break;

     case USB_DEVICE_SET_INTERFACE_STARTED:

       break;

     case USB_DEVICE_INTERFACED:

       break;

     case USB_DEVICE_DETACHED:

       LEDR_On();

       LEDG_Off();

       print((unsigned char*)"\nMass Storage Device Detached\n" );

       break;

     case USB_DEVICE_OTHER:

       break;

     default:

       print((unsigned char*)"Unknown Mass Storage Device State\n");

       break;

  } /* switch */

}

 

static portTASK_FUNCTION(HostTask, pvParameters) {

  (void)pvParameters; /* not used */

  for(;;) {

    FsMSD1_AppTask();

    CheckStatus();

    FRTOS1_taskYIELD();

  }

}

 

void HOST_Init(void) {

  FsMSD1_HostInit();

  if (FRTOS1_xTaskCreate(HostTask, (signed portCHAR *)"Host", configMINIMAL_STACK_SIZE+100, NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) {

    for(;;){} /* error */

  }

}

   
That’s it :-) 

 
 

 

 

Summary

With this I have now USB MSD host working for the FRDM-K20D50M. The most complicated part is to set up the clock settings which are not that simple. But after knowing what needs to be done, this is pretty easy, especially with the help of Processor Expert. The example project is attached to this message.

 
Happy MSDing :-)

Attachments:
FRDM-K20_MSD_Host.zip
  • cortex-m4
  • freescale
  • freedom_board
  • Cortex-M
  • kinetis
  • frdm-k20d50m
  • usb
  • cortex
  • host
  • arm
  • freedom
  • kinetis-k
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube