FreeRTOS™ and the SDK for Kinetis MCUs - NXP...
-
Upload
nguyenhuong -
Category
Documents
-
view
233 -
download
0
Transcript of FreeRTOS™ and the SDK for Kinetis MCUs - NXP...
![Page 1: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/1.jpg)
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
![Page 2: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/2.jpg)
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.
![Page 3: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/3.jpg)
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.
![Page 4: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/4.jpg)
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
![Page 5: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/5.jpg)
TM
External Use 4
Kinetis SDK
with FreeRTOS
![Page 6: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/6.jpg)
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
![Page 7: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/7.jpg)
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
![Page 8: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/8.jpg)
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()
![Page 9: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/9.jpg)
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 */
}
}
![Page 10: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/10.jpg)
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! */
}
}
![Page 11: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/11.jpg)
TM
External Use 10
Installation and Setup
![Page 12: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/12.jpg)
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
![Page 13: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/13.jpg)
TM
External Use 12
FreeRTOS for Kinetis SDK
• Zip file
• To be extracted into KSDK installation folder
![Page 14: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/14.jpg)
TM
External Use 13
KSDK and RTOS Directory Structure
![Page 15: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/15.jpg)
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!
![Page 16: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/16.jpg)
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
![Page 17: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/17.jpg)
TM
External Use 16
SDK and Processor Expert
• Have Kinetis SDK enabled
• Press Finish
![Page 18: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/18.jpg)
TM
External Use 17
FSL_RTOS_FREE_RTOS
• Add FSL_RTOS_FREE_RTOS to preprocessor for C Compiler
![Page 19: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/19.jpg)
TM
External Use 18
Add RTOS Files
• Add links to the project
− FreeRTOS\src
− FreeRTOS\port\gcc
![Page 20: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/20.jpg)
TM
External Use 19
Assign RTOS Vectors
• Assign FreeRTOS vectors in startup code
− vPortSVCHandler
− vPortPendSVHandler
− vPortTickHandler
![Page 21: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/21.jpg)
TM
External Use 20
FreeRTOSConfig.h
• RTOS Configuration File, specific per project
• Clock Configuration, Stack Size, Memory Size, …
![Page 22: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/22.jpg)
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
![Page 23: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/23.jpg)
TM
External Use 22
Optimization
![Page 24: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/24.jpg)
TM
External Use 23
RTOS Low Power Hook
• IDLE time between tasks running
• RTOS calls Idle() hook
• Opportunity to enter Low Power Mode
![Page 25: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/25.jpg)
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
![Page 26: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/26.jpg)
TM
External Use 25
Tickless Mode with FreeRTOS
• Enable Tickless Idle Mode
• Configurable Idle Time Ticks before Sleep
• Configurable Application Decision Hook
![Page 27: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/27.jpg)
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
![Page 28: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/28.jpg)
TM
External Use 27
Tickless Mode with Kinetis Low Power Timer (LPTMR)
• Enable Low Power Timer
• 1 kHz Low Power Timer (16bit)
![Page 29: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/29.jpg)
TM
External Use 28
Tickless Low Power Mode with LPTMR
• 16-bit LPTMR
• 65535 ms max Tickless Period
![Page 30: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/30.jpg)
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
![Page 31: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/31.jpg)
TM
External Use 30
RTOS Trace
![Page 32: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/32.jpg)
TM
External Use 31
User Event Signal Plot
![Page 33: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/33.jpg)
TM
External Use 32
Demonstration
• Example Project
− Kinetis Design Studio
− Processor Expert
− Kinetis SDK
− FreeRTOS
• Download and Debug
− FRDM-K64F
− Trace Collection
− Trace Viewer
![Page 34: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/34.jpg)
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
![Page 35: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/35.jpg)
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
![Page 36: FreeRTOS™ and the SDK for Kinetis MCUs - NXP …cache.freescale.com/files/training/doc/ftf/2014/FTF-SDS-F0120.pdf · FreeRTOS™ and the SDK for Kinetis MCUs ... −Apply the knowledge](https://reader030.fdocuments.us/reader030/viewer/2022021516/5b1db0b87f8b9ab0188b4591/html5/thumbnails/36.jpg)
TM
© 2014 Freescale Semiconductor, Inc. | External Use
www.Freescale.com