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

Similar documents
MCUXpresso SDK USB Stack User s Guide

Getting Started with Kinetis SDK (KSDK) v.1.2

Kinetis SDK v Release Notes for KV5x Derivatives

Getting Started with Kinetis SDK (KSDK) v.1.3

Getting Started with Freescale MQX RTOS for Kinetis SDK and Kinetis Design Studio IDE

Kinetis SDK Freescale Freedom FRDM-KL03Z Platform User s Guide

Hands-On Workshop: New Kinetis Development Platform

Hands-On Workshop: Developing with the Kinetis Software Development Kit

Getting Started with MCUXpresso SDK

Freescale MQX RTOS TWR-K64F120M Release Notes

RN2483_Silica Documentation

Freescale Kinetis Software Development Kit Release Notes

Kinetis SDK Release Notes for the TWR-K24F120M Tower System Module

Using Code Composer Studio IDE with MSP432

Getting Started with Freescale MQX RTOS for Kinetis SDK and MDK-ARM Keil

Freescale MQX USB Stack for TWR-K24F120M GA User s Guide

MQX RTOS Release Notes for Kinetis SDK FRDM- KV10Z Freescale Freedom Development Platform

Software Installation Guide for S32 Design Studio IDE (S32DS): FRDM-KEAZ128Q80 FRDM-KEAZ64Q64 FRDM-KEAZN32Q64

A brief intro to MQX Lite. Real work: hands-on labs. Overview, Main features and Code Size

MQX RTOS Release Notes for Kinetis SDK v1.2.0 for KL33Z64 for FRDM-KL43Z Freescale Freedom Development Platform

Component validity and internal error checking functionality to ensure reliable operation

Kinetis SDK v Release Notes for the MK21DA5 and MKW24D5 Devices

Using FlexIO to emulate communications and timing peripherals

Getting Started with Freescale MQX RTOS for Kinetis SDK and ARM GCC

NXP Semiconductors, 6501 William Cannon Drive West, Austin, Texas Kinetis SDK 2.0 Transition Guide Rev.

Getting Started with Qorivva Fast

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission.

How to Implement USB Suspend/Resume Feature with MCUXpresso SDK USB Stack

Hands-On Workshop: ARM mbed

Emulating Dual SPI Using FlexIO

Getting Started with MCUXpresso SDK CMSIS Packs

Quick Start Guide. TWR-KV10Z32 Development Kit for Kinetis KV1x Family TOWER SYSTEM

XC866 Getting Started on EasyKit & Toolkits

Load Position-Independent Code (PIC) on a Kinetis Platform Using the IAR EWARM Compiler

Quick Start Guide. TWR-VF65GS10 For Vybrid Controller Solutions Based on ARM Cortex -A5 and Cortex-M4 Processors with the DS-5 Toolchain TOWER SYSTEM

Offline Flash Programmer for Kinetis K- and L-series MCUs

Kinetis Bootloader to Update Multiple Devices in a Field Bus Network

BASICS OF THE RENESAS SYNERGY TM

Freescale MQX RTOS for Kinetis SDK Release Notes version beta

Kinetis KE1xF512 MCUs

Keil TM MDK-ARM Quick Start for. Holtek s HT32 Series Microcontrollers

Freescale MKW40Z IEEE Software Quick Start Guide

Getting Started with MQX RTOS for Kinetis SDK

Console Framework Module Guide

AGH University of Science and Technology Cracow Department of Electronics

Hands-On Workshop: Freescale MQX Drivers and BSP s

Quick Start Guide Demo Distance2Go. July 2018

Quick Start Guide (QSG) for - FRDM-KEAZ128 - FRDM-KEAZ64 - FRDM-KEAZN32

Getting Started with Qorivva Fast

EZ Touchscreen CE Computer. User Manual

Getting Started with FreeRTOS BSP for i.mx 7Dual

Building an Embedded Processor System on Xilinx NEXYS3 FPGA and Profiling an Application: A Tutorial

Quick Start Guide for mbed enabling Freescale FRDM-KL25z Freedom board

Freescale MQX USB Device API Reference Manual

Data Structures. Home

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Eclipse Quick Reference Windows Hosted

Cookery-Book, V1.0, February XMC1400 BootKit HelloWorld

BASICS OF THE RENESAS SYNERGY TM

INTRODUCTION TO FLEXIO

TWR-KV10Z32 Sample Code Guide for IAR Board configuration, software, and development tools

FRDM-KL03Z User s Guide

GDFLIB User's Guide. ARM Cortex M0+

USB BF70x Bulk Library v.1.1 Users Guide Users Guide Revision 1.1. For Use With Analog Devices ADSP-BF70x Series Processors. Closed Loop Design, LLC

MicroZed: Hello World. Overview. Objectives. 23 August 2013 Version 2013_2.01

Connectivity Framework Reference Manual

Multifunction Serial Interface (PDL_MFS) Features. General Description. When to Use a PDL_MFS Component. Quick Start 1.0

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Using PE to quickly use common communication interfaces on Kinetis

TWR-KL43Z48M Quick Start Guide

MLIB User's Guide. ARM Cortex M4

Bootloader project Project with a Bootloader Component and communication Component.

Hands-On with STM32 MCU Francesco Conti

Freescale, the Freescale logo and CodeWarrior are trademarks of Freescale Semiconductor, Inc., Reg. U.S. Pat. & Tm. Off. Xtrinsic is a trademark of

Kinetis Bootloader v1.2.0 Release Notes

RX Family APPLICATION NOTE. Simple I 2 C Module Using Firmware Integration Technology. Introduction. Target Device.

Developing a simple UVC device based on i.mx RT1050

BASICS OF THE RENESAS SYNERGY PLATFORM

Bootloader project Project with a Bootloader component and communication component.

Release Notes. S32 Design Studio for ARM v1.1

Codewarrior for ColdFire (Eclipse) 10.0 Setup

3.1. User Guide. Processor Expert and Device Initialization. PROCESSOR EXPERT FOR FREESCALE ColdFire FAMILY. Freescale Semiconductor, Inc.

ASF4 API Reference Manual

Designing Your Own Soft Modules

Basic SigmaDSP Microcontroller Integration

Hibernation Module. Introduction. Agenda

TWR-KV10Z32 Sample Code Guide for CodeWarrior Board configuration, software, and development tools

F28335 ControlCard Lab1

MLIB User's Guide. ARM Cortex M4F

Renesas PE-HMI1 Synergy S7 with Clarinox SPP Application

XC2287M HOT Solution CAN Serial Communication using the CAN. Device: XC2287M-104F80 Compiler: Tasking Viper 2.4r1 Code Generator: DAvE 2.

Introduction USART & AVR EVK1100

Brooklyn Board by Silica Architech Documentation

USB BF70x HID Library v.1.1 Users Guide Users Guide Revision 1.1. For Use With Analog Devices ADSP-BF70x Series Processors. Closed Loop Design, LLC

ASF4 API Reference Manual

Introduction to Zynq

Exercise: PWM Generation using the N2HET

IoT Sensing SDK. Getting started with IoT Sensing SDK (ISSDK) v1.7 middleware. Document information. IoT Sensing SDK, ISSDK, MCUXpresso, middleware

Kinetis KL1x General-Purpose Ultra-Low- Power MCUs Up to 256 KB Flash and 32 KB SRAM

Application Note: AN00144 xcore-xa - xcore ARM Boot Library

Transcription:

Freescale Semiconductor Creating a New USB project with KSDK and Processor Expert support in KDS By: Technical Information Center Developing an USB application can involve to include some extra features besides the ones shown in USB examples for Kinetis SDK. You could use Kinetis SDK API functions to add new features to your USB project but there is also an option on adding processor expert support or combine both of them. This documents explains how to create a new USB example project for KSDK 1.2.0 and add Processor Expert to it. For this document, Freedom K64F and USB HID bare metal example will be used.

1 Requirements. 1.1 Install KDS 3.0.0 (Kinetis Design Studio), you can download from www.freescale.com/kds 1.2 Install KSDK 1.2.0 (Kinetis Software Development Kit), you can download from www.freescale.com/ksdk 1.3 Install KSDK_1.2.0_Eclipse_Update you can find the update in C:\Freescale\KSDK_1.2.0\tools\eclipse_update. The instruction to make the updates are described in chapter 2 and 2.1 of C:\Freescale\KSDK_1.2.0\doc\rtos\mqx\MQX RTOS IDE Guides\MQX-KSDK-KDS- Getting-Started.pdf 1.4 It is necessary to build the following libraries: 1.4.1 Platform Library for MQX, ksdk_platform_lib_k64f12.a This project is located in ${KSDK_PATH/lib/ksdk_platform_lib/kds/K64F12 1.4.2 MQX Library, usbd_sdk_frdmk64f_bm_frdmk64f.a This project is located in ${KSDK_PATH/usb/usb_core/device/build/kds/usbd_sdk_frdmk64f_bm 2 Freescale Semiconductor

2 Create a New Kinetis Project 2.1 Go to menu File > New > Kinetis Project and wizard for new project will appear. Write a name for your project and click Next 2.2 On Devices window, select your target and click Next >. In this case, FRDMK64 is chosen. 3 Freescale Semiconductor

2.3 Next window allows user to select KSDK location along with Processor Expert support. Check Processor Expert option and click Finish button. 4 Freescale Semiconductor

2.4 Once project is created, go to menu Project > Properties > C/C++ Build > Settings > Cross ARM C Compiler > Includes and add following USB includes. You can copy and paste the paths below. ${PROJECT_KSDK_PATH/usb/adapter/sources ${PROJECT_KSDK_PATH/usb/adapter/sources/sdk ${PROJECT_KSDK_PATH/usb/usb_core/device/include/frdmk64f ${PROJECT_KSDK_PATH/usb/usb_core/device/include ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/audio ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/cdc ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/common ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/composite ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/hid ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/include ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/include/config ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/msd ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/classes/phdc ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/controller/khci ${PROJECT_KSDK_PATH/usb/usb_core/device/sources/controller ${PROJECT_KSDK_PATH/usb/usb_core/hal ${PROJECT_KSDK_PATH/usb/usb_core/host/include ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/classes/audio ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/classes/cdc ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/classes/hid ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/classes/hub ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/classes/msd ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/classes/phdc ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/classes/printer ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/controller/khci ${PROJECT_KSDK_PATH/usb/usb_core/host/sources/controller ${PROJECT_KSDK_PATH/usb/usb_core/include ${PROJECT_KSDK_PATH/usb/usb_core/otg/sources/driver/khci ${PROJECT_KSDK_PATH/usb/usb_core/otg/sources/driver/max3353/sdk ${PROJECT_KSDK_PATH/usb/usb_core/otg/sources/include ${PROJECT_KSDK_PATH/usb/usb_core/otg/sources/otg Note: These paths include all supported classes either for Host, Device or OTG controller. This way, you can create your own application based on a specific class or mode and all needed files are already included. (For this example, all paths related to Host, OTG, and device classes different to HID could be omitted) 5 Freescale Semiconductor

6 Freescale Semiconductor

2.5 Go to menu Project > Properties > C/C++ Build > Settings > Cross ARM C Compiler > Preprocessor and set next defines: FRDM_K64F FREEDOM 7 Freescale Semiconductor

2.6 Go to menu Project > Properties > C/C++ Build > Settings > Cross ARM C++ Linker > Miscellaneous, add next USB library: "${PROJECT_KSDK_PATH\usb\usb_core\device\build\kds\usbd_sdk_frdmk64f_bm\debug\libusbd_bm.a" 8 Freescale Semiconductor

2.7 Now the new project is completely self-dependent and ready to run. Press Apply to save changes and then OK. 9 Freescale Semiconductor

3 Adding USB Files and configuring PE components. 3.1 Once project settings are configured correctly, open Sources folder and add a new main header file. This is done by right-clicking on Sources folder and select New > Header File. 10 Freescale Semiconductor

3.2 Add next code to main.h file (It is based on dev_hid_mouse_frdmk64f_bm example): /****************************************************************************** * Constants - None *****************************************************************************/ /****************************************************************************** * Macro's *****************************************************************************/ #define MOUSE_BUFF_SIZE (4) /* report buffer size */ #define REQ_DATA_SIZE (1) #define HIGH_SPEED (0) #if HIGH_SPEED #define CONTROLLER_ID USB_CONTROLLER_EHCI_0 #else #define CONTROLLER_ID USB_CONTROLLER_KHCI_0 #endif /****************************************************************************** * Types *****************************************************************************/ typedef struct _mouse_variable_struct { hid_handle_t app_handle; uint16_t app_speed; uint8_t rpt_buf[mouse_buff_size];/*report/data buff for mouse application*/ uint8_t app_request_params[2]; /* for get/set idle and protocol requests*/ uint8_t mouse_init;/* flag to check lower layer status*/ mouse_global_variable_struct_t; /***************************************************************************** * Global variables *****************************************************************************/ /***************************************************************************** * Global Functions *****************************************************************************/ extern void TestApp_Init(void); 11 Freescale Semiconductor

3.3 Copy usb_descriptor.c and usb_descriptor.h files from C:\Freescale\KSDK_1.2.0\examples\frdmk64f\demo_apps\usb\device\hid\hid_mouse to Sources Folder, You can drag and drop these files and select copy files. 3.4 In usb_descriptor.c replace include file mouse.h by main.h 12 Freescale Semiconductor

3.5 Now, Double click over ProecessorExpert.pe icon and configure clock settings for this board. Core Clock should be at least 20MHz for correct USB performance. Click over clockman1:fsl_clock_manager component and go to Clock management > Clock settings > Clock configurations and select MCG settings tab. 3.6 In MCG Settings tab, select PEE as MCG mode and select PLL output frequency to 96 MHz. 13 Freescale Semiconductor

3.7 Go to System clocks tabs and configure Core, Bus, External and Flash clock according to your requirements. In this case, configurations is done as follows: 3.8 Now, it is necessary to add console component to current project. Go to Components Library and double-click on fsl_debug_console. You will notice how DbgCs1 component has been added to your project. 14 Freescale Semiconductor

3.9 DbgCs1 Components needs to be configured. Double click over DbgCs1:fsl_debug_console and configure UART modules as needed. For FRDMK64F, UART0 is connected to OpenSDA Interface and uses PTB16 and PTB17 pins for RxD and TxD respectively. 3.10 Save Processor Expert configuration and click Generate Processor Expert Code. 3.11 Once Processor Expert Code has been generated, hide processor expert view (Go to menu Processor Expert > Hide Views) and start editing application code on main.c. 15 Freescale Semiconductor

4 Create Application 4.1 Now, we are ready to add our application code (either using KSDK or Processor Expert). In this case, dev_hid_mouse_frdmk64f_bm_frdmk64f was taken as reference and main.c file was modified as follows: /* Including needed modules to compile this module/procedure */ #include "Cpu.h" #include "Events.h" #include "clockman1.h" #include "pin_init.h" #include "osa1.h" #include "DbgCs1.h" #if CPU_INIT_CONFIG #include "Init_Config.h" #endif /* User includes (#include below this line is not maintained by Processor Expert) */ #include "usb_device_config.h" #include "usb.h" #include "usb_device_stack_interface.h" #include "usb_class_hid.h" #include "main.h" #include "usb_descriptor.h" extern usb_desc_request_notify_struct_t g_desc_callback; static mouse_global_variable_struct_t g_mouse; /***************************************************************************** * @name move_mouse * @brief This function gets makes the cursor on screen move left,right * up and down * @param None * @return None ******************************************************************************/ static void move_mouse(void) { static int8_t x = 0, y = 0; enum { RIGHT, DOWN, LEFT, UP ; static uint8_t dir = (uint8_t) RIGHT; switch(dir) { case RIGHT: g_mouse.rpt_buf[1] = 2; g_mouse.rpt_buf[2] = 0; x++; if (x > 100) { dir++; case DOWN: g_mouse.rpt_buf[1] = 0; 16 Freescale Semiconductor

g_mouse.rpt_buf[2] = 2; y++; if (y > 100) { dir++; case LEFT: g_mouse.rpt_buf[1] = (uint8_t)(-2); g_mouse.rpt_buf[2] = 0; x--; if (x < 0) { dir++; case UP: g_mouse.rpt_buf[1] = 0; g_mouse.rpt_buf[2] = (uint8_t)(-2); y--; if (y < 0) { dir = RIGHT; (void) USB_Class_HID_Send_Data(g_mouse.app_handle, HID_ENDPOINT, g_mouse.rpt_buf, MOUSE_BUFF_SIZE); void USB_App_Device_Callback(uint8_t event_type, void* val, void* arg) { UNUSED_ARGUMENT (arg) UNUSED_ARGUMENT (val) switch(event_type) { case USB_DEV_EVENT_BUS_RESET: g_mouse.mouse_init = FALSE; if (USB_OK == USB_Class_HID_Get_Speed(g_mouse.app_handle, &g_mouse.app_speed)) { USB_Desc_Set_Speed(g_mouse.app_handle, g_mouse.app_speed); case USB_DEV_EVENT_ENUM_COMPLETE: g_mouse.mouse_init = TRUE; move_mouse();/* run the cursor movement code */ case USB_DEV_EVENT_ERROR: /* user may add code here for error handling NOTE : val has the value of error from h/w*/ default: return; 17 Freescale Semiconductor

/****************************************************************************** * @name USB_App_Class_Callback * * @brief This function handles the callback for Get/Set report req * * @param request : request type * @param value : give report type and id * @param data : pointer to the data * @param size : size of the transfer * * @return status * USB_OK : if successful * else return error *****************************************************************************/ uint8_t USB_App_Class_Callback ( uint8_t request, uint16_t value, uint8_t ** data, uint32_t* size, void* arg ) { uint8_t error = USB_OK; uint8_t index = (uint8_t)((request - 2) & USB_HID_REQUEST_TYPE_MASK); if ((request == USB_DEV_EVENT_SEND_COMPLETE) && (value == USB_REQ_VAL_INVALID)) { if ((g_mouse.mouse_init) && (arg!= NULL)) { move_mouse();/* run the cursor movement code */ return error; /* index == 0 for get/set idle, index == 1 for get/set protocol */ *size = 0; /* handle the class request */ switch(request) { case USB_HID_GET_REPORT_REQUEST: *data = &g_mouse.rpt_buf[0]; /* point to the report to send */ *size = MOUSE_BUFF_SIZE; /* report size */ case USB_HID_SET_REPORT_REQUEST: for (index = 0; index < MOUSE_BUFF_SIZE; index++) { /* copy the report sent by the host */ g_mouse.rpt_buf[index] = *(*data + index); case USB_HID_GET_IDLE_REQUEST: /* point to the current idle rate */ *data = &g_mouse.app_request_params[index]; *size = REQ_DATA_SIZE; 18 Freescale Semiconductor

case USB_HID_SET_IDLE_REQUEST: /* set the idle rate sent by the host */ g_mouse.app_request_params[index] = (uint8_t)((value & MSB_MASK) >> HIGH_BYTE_SHIFT); case USB_HID_GET_PROTOCOL_REQUEST: /* point to the current protocol code 0 = Boot Protocol 1 = Report Protocol*/ *data = &g_mouse.app_request_params[index]; *size = REQ_DATA_SIZE; case USB_HID_SET_PROTOCOL_REQUEST: /* set the protocol sent by the host 0 = Boot Protocol 1 = Report Protocol*/ g_mouse.app_request_params[index] = (uint8_t)(value); return error; /****************************************************************************** * * @name TestApp_Init * * @brief This function is the entry for mouse (or other usage) * * @param None * * @return None ** *****************************************************************************/ void TestApp_Init(void) { hid_config_struct_t config_struct; /* initialize the Global Variable Structure */ OS_Mem_zero(&g_mouse, sizeof(mouse_global_variable_struct_t)); OS_Mem_zero(&config_struct, sizeof(hid_config_struct_t)); /* Initialize the USB interface */ USB_PRINTF("begin to test mouse\r\n"); config_struct.hid_application_callback.callback = USB_App_Device_Callback; config_struct.hid_application_callback.arg = &g_mouse.app_handle; config_struct.class_specific_callback.callback = USB_App_Class_Callback; config_struct.class_specific_callback.arg = &g_mouse.app_handle; config_struct.desc_callback_ptr = &g_desc_callback; g_mouse.app_speed = USB_SPEED_FULL; USB_Class_HID_Init(CONTROLLER_ID, &config_struct, &g_mouse.app_handle); 19 Freescale Semiconductor

void APP_task() { USB_HID_Periodic_Task(); /*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ /* For example: for(;;) { */ TestApp_Init(); /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){ /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/ /* END main */ 20 Freescale Semiconductor

5 Run the application 5.1 Build your application, go to menu Project > Build Project. Alternately click the hammer button. 5.2 Go to menu Run > Debug Configurations 21 Freescale Semiconductor

5.3 Select the Debug Configuration that matches your connection type, in this example GDB SEGGER J-Link connection is used. 5.4 Open a terminal, select the appropriate port and set baud rate to 115200. 22 Freescale Semiconductor

5.5 Run the application, you will see begin to test mouse in terminal. 5.6 Connect an USB Micro-B cable on J22 from FRDMK64F board to a PC-Host. 5.7 After successful driver installation process on PC host, you can see how cursor is moving right, down, left and up according move_mouse() function. Now you have an USB project with KSDK and Processor Expert compatibility to develop your application. 23 Freescale Semiconductor

Other useful links KSDK GPIO driver with Processor Expert https://community.freescale.com/videos/3195 24 Freescale Semiconductor