freertos™ and the sdk for kinetis mcus - nxp...
TRANSCRIPT
External Use
TM
FreeRTOS™ and the SDK
for Kinetis MCUs
FTF-SDS-F0120
A P R . 2 0 1 4
Prof. Erich Styger | DMTS & Technical Marketer
TM
External Use 1
Session Introduction
• This session introduces the new Kinetis SDK, and how it can be
used with FreeRTOS and the new Kinetis Design Studio.
• This session gives an overview, how to install, setup and optimize
FreeRTOS applications for Freescale Kinetis devices.
• This session is presented by the maintainer of the FreeRTOS ports
for Freescale devices, with 20 years of experience in software and
tools development.
TM
External Use 2
Session Objectives
• After completing this session you will be able to :
− Effectively describe, at a high level, the Freescale Kinetis SDK with
FreeRTOS and its usage inside an Eclipse based IDE.
− Apply the knowledge gained in this presentation to start using the Kinetis
Design Studio with Processor Expert, Kinetis SDK and FreeRTOS.
− Use the knowledge to customize and optimize applications using the
Open Source FreeRTOS Operating system for Low Power.
TM
External Use 3
Agenda
• Kinetis SDK (KSDK)
− Architecture
− Drivers
− Bare Metal, RTOS
− FreeRTOS
− RTOS Abstraction
• Installation and Setup − Directory Structure
− Tool Setup
• Customization and Optimization
− RTOS Configuration
− Low Power Support
• Demonstration
− Kinetis Design Studio
− RTOS Trace
KSDK & FreeRTOS
Installation & Setup
Customization &
Optimization
Demonstration
TM
External Use 4
Kinetis SDK
with FreeRTOS
TM
External Use 5
Kinetis SDK (KSDK)
UART
Kinetis Microcontroller Hardware
RTOS
Application
SPI I2C Bit I/O
USB
Stack
RTOS AL
HAL
Processor
Expert
USB Tmr
Middleware
TM
External Use 6
Kinetis SDK RTOS Abstraction
• Common Interface for RTOS/Bare Metal
− Application
− Kinetis SDK
RTOS Abstraction Layer
MQX uCOS-II/III FreeRTOS
Kinetis SDK
CMSIS
RTOS Bare Metal
Declarations Tasks
Events Synchronization
Locking Message
Queues
Memory
TM
External Use 7
RTOS Abstraction
• Declarations − Synchronization objects, event handler, queue handler, task handler
• Task (FreeRTOS Tasks) − task_create(), task_destroy(), time_delay()
• Synchronization (FreeRTOS counting semaphore) − sync_create(), sync_wait(), sync_poll(), sync_signal(), sync_signal_from_isr(),
sync_destroy()
• Locking (FreeRTOS recursive Mutex) − lock_create(), lock_wait(), lock_poll(), lock_release(), lock_destroy()
• Events (FreeRTOS binary semaphore) − event_create(), event_wait(), event_set(), event_set_from_isr(), event_clear(),
event_check_flags(), event_destroy()
• Message Queue (FreeRTOS Queues) − msg_queue_create(), msg_queue_put(), msg_queue_get(), msg_queue_flush(),
msg_queue_destroy()
• Memory − mem_allocate(), mem_allocate_zero(), mem_free()
TM
External Use 8
Example: 'traditional' FreeRTOS Task
#include "FreeRTOS.h" /* FreeRTOS interface */
static xTaskHandle mainTaskHndl;
static void main_task(void *param) {
for(;;) {
gpio_toggle_pin_output(LED_RED);
vTaskDelay(1000/portTICK_RATE_MS);
} /* for */
}
static void CreateTask(void) {
if (xTaskCreate(
main_task, /* task function */
"Main", /* task name for kernel awareness */
configMINIMAL_STACK_SIZE, /* task stack size */
(void*)NULL, /* optional task startup argument */
tskIDLE_PRIORITY, /* initial priority */
&mainTaskHndl /* task handle */
) != pdPASS) {
for(;;){} /* error! probably out of memory */
}
}
TM
External Use 9
Example: FreeRTOS Task with Kinetis SDK
#include <fsl_os_abstraction.h> /* SDK RTOS abstraction */
#define SDK_TASK_STACK_SIZE 200 /* Task size (in 32bit units) */
#define SDK_TASK_PRIO 0 /* task priority */
static void sdk_task(void *param); /* prototype of the task */
FSL_RTOS_TASK_DEFINE(sdk_task, SDK_TASK_STACK_SIZE, "sdk", false);
static task_handler_t sdk_task_hdl; /* task handle */
static void sdk_task(void *param) {
for(;;) {
gpio_toggle_pin_output(LED_BLUE);
time_delay(1000);
}
}
static void SDK_CreateTask(void) {
if (task_create(sdk_task, SDK_TASK_PRIO, NULL, &sdk_task_hdl)!=kSuccess) {
for(;;); /* error! */
}
}
TM
External Use 10
Installation and Setup
TM
External Use 11
Setup with Kinetis Design Studio
Download and Install Kinetis Design Studio (setup exe)
KDS comes with an installer of the Kinetis SDK
Download and Install FreeRTOS for KSDK (zip archive)
Done!
• Default Installation Location (Windows)
− C:\Freescale\KDS_1.0
− C:\Freescale\KSDK_1.0.0
TM
External Use 12
FreeRTOS for Kinetis SDK
• Zip file
• To be extracted into KSDK installation folder
TM
External Use 13
KSDK and RTOS Directory Structure
TM
External Use 14
Project Flow with KPS, KSDK and FreeRTOS
Create New KSDK Project
Enable FreeRTOS in KSDK
Add FreeRTOS to Project
Configure RTOS
Done!
TM
External Use 15
Kinetis Design Studio Project with SDK + FreeRTOS
• Creating SDK + FreeRTOS KDS project (no Processor Expert)
• Choose Menu File > New Kinetis Design Studio Project
• Provide Project Name, press Next
• Choose Device, press Next
TM
External Use 16
SDK and Processor Expert
• Have Kinetis SDK enabled
• Press Finish
TM
External Use 17
FSL_RTOS_FREE_RTOS
• Add FSL_RTOS_FREE_RTOS to preprocessor for C Compiler
TM
External Use 18
Add RTOS Files
• Add links to the project
− FreeRTOS\src
− FreeRTOS\port\gcc
TM
External Use 19
Assign RTOS Vectors
• Assign FreeRTOS vectors in startup code
− vPortSVCHandler
− vPortPendSVHandler
− vPortTickHandler
TM
External Use 20
FreeRTOSConfig.h
• RTOS Configuration File, specific per project
• Clock Configuration, Stack Size, Memory Size, …
TM
External Use 21
Processor Expert KDS KSDK+FreeRTOS Project
• Graphical Configuration
• Automatic Code Generation
• Consistency checks
• Easy integration of
− Existing application code
− SDK drivers
− Extra driver code
• Supports all Kinetis devices
TM
External Use 22
Optimization
TM
External Use 23
RTOS Low Power Hook
• IDLE time between tasks running
• RTOS calls Idle() hook
• Opportunity to enter Low Power Mode
TM
External Use 24
RTOS Low Power and ARM SystTick Interrupts
• ARM SysTick used for
− Time Base
− Preemption
• Limits duration of Low Power mode duration
TM
External Use 25
Tickless Mode with FreeRTOS
• Enable Tickless Idle Mode
• Configurable Idle Time Ticks before Sleep
• Configurable Application Decision Hook
TM
External Use 26
ARM SysTick Limitation
• 24-bit Counter (Down-Counter)
• Bus Clock: 20 MHz limits tickless idle mode to 800 ms
• Freescale Kinetis-L: 16x Prescaler
TM
External Use 27
Tickless Mode with Kinetis Low Power Timer (LPTMR)
• Enable Low Power Timer
• 1 kHz Low Power Timer (16bit)
TM
External Use 28
Tickless Low Power Mode with LPTMR
• 16-bit LPTMR
• 65535 ms max Tickless Period
TM
External Use 29
RTOS and Application Profiling
• Runtime Statistics
− Performance
measurement
− CPU task time
• Trace Hooks
− Instrumented RTOS
− Trace Data collection
− Custom hooks
− External Viewer
TM
External Use 30
RTOS Trace
TM
External Use 31
User Event Signal Plot
TM
External Use 32
Demonstration
• Example Project
− Kinetis Design Studio
− Processor Expert
− Kinetis SDK
− FreeRTOS
• Download and Debug
− FRDM-K64F
− Trace Collection
− Trace Viewer
TM
External Use 33
Summary
• Kinetis SDK
− Drivers for Kinetis MCUs
− Bare Metal or RTOS
− RTOS Abstraction: FreeRTOS
• Kinetis Design Studio
− Kinetis SDK Projects
− Processor Expert Project
− Edit, Build, Debug
• FreeRTOS Customization and Optimization
− FreeRTOSConfig.h
− Low Power Tickless Idle Mode
− RTOS Trace
TM
External Use 34
For Further Information
• FreeRTOS website − www.freertos.org
• Components, Examples and Tutorials for Kinetis devices − www.mcuoneclipse.com
• Contact − Prof. Erich Styger
TM
© 2014 Freescale Semiconductor, Inc. | External Use
www.Freescale.com