October 2013
Overview of Tower system, CodeWarrior v10.3 and MQX 4.0 Easy OS configuration with GUI based interface Using BSP clone wizard to start with BSP porting Kernel debugging with task aware debugger tool Using Processor Expert together with MQX Estimate flash and RAM size usage for MQX based application Using performance tools for MQX 2
David Connelly Applications Engineer on the MCU Applications Team Based in Austin, TX 15 Years with Freescale 12 Years with Automotive Microcontrollers 3 Years with MCU Applications BSEE Rochester Institute of Technology (RIT) 3
Simple and Scalable Designed to be customized by Feature, Size, and Speed Lightweight services Smaller and faster vs. regular MQX services Allows control of RAM/ROM utilization New, custom components can be added Scalable Code Density ideal for MCU & MPU ROM size ranges from 10K to 150K RAM size starting at 2.5K Powerful and Integrated Full priority-based, pre-emptive scheduler Powerful real-time performance Fully re-entrant, including interrupt service routines Hand-optimized context switch & low-level interrupt times Time-critical services optimized for speed & deterministic performance Component validity and internal error checking functionality to ensure reliable operation 5
RTOS manages the time of the microcontroller Features of a RTOS: Allows multi-tasking Scheduling of the tasks with priorities Synchronization of the resource access Inter-task communication Time predictable Interrupt handling 6
Navigate to C:\Freescale\Freescale_MQX_4_0\config\twrk70f120m\cw10 and drag twrk70f120m.wsd to CW10.3 7
The MQX libraries projects for TWR-K70F120M has been imported as a working set. Select working set 8
Before building MQX libraries, you can try to delete the library files under D:\Freescale\Freescale_MQX_4_0\lib\twrk70f120m.cw10, so after building, you will know where MQX stores the libraries and header files for application usage. 9
Choose Project -> Build Working Set -> twrk70f120m and wait for libraries build completion 10
BSP Board Support Package Required Libraries PSP Processor Support Package (aka RTOS or MQX) RTCS Real-Time TCP/IP Communication Suite Shell Command Line Interface USB USB protocol stack MFS File System Optional Libraries AN3907 Using MQX Libraries 11
Check the file contents under folder D:\Freescale\Freescale_MQX_4_0\lib\twrk70f120m.cw10\debug again, libraries and header files are back!!! 12
Navigate to folder D:\Freescale\Freescale_MQX_4_0\demo\web_hvac\cw10\web _hvac_twrk70f120m Drag the.project file into CodeWarrior projects 13
Deselect working set and you will see the web-hvac demo 14
Choose Int Flash SramData Debug target Right click->build Configuration->Set Active Then hit to build the demo 15
K70 tower kit consists of TWR-K70FN1M TWR-SER Two elevator board: functional elevator and dummy elevator Face the side with white strip to function elevator, then insert TWR-K70FN1M and TWR-SER into functional elevator, you can insert into any of the elevator slot Put dummy elevator to the other side of TWR-K70FN1M and TWR-SER to complete the assembly 16
Connect USB cable to TWR-K70FN1M (J13) and laptop Click Debug configuration Select the Int Flash SramData Debug target and debug 17
If asked to update firmware, short J10, unplug and reinsert USB cable and click ok. Boards may already be updated. 18
After firmware updated, remove jumper on J10, unplug and reinsert USB cable. Install OSJTAG driver then click ok. 19
After downloading, code stops at main() where you see MQX entry point _mqx(). 20
Right click My Computer->Manage->Device Manager Find the CDC Virtual Serial Port 21
Click Windows Start Button->TeraTerm Then Select COMx port from previous step Then Setup->Serial Port Use 115200 8, N, 1 22
Set COM port settings as 115200bps 8N1 23
Set IP address for laptop, set it in the same subnet as TWR- K70FN1M, you can find the exact IP address setting for board in HVAC.h 24
Board IP address and subnet mask setting in HVAC.h 25
After hitting button, you will see a shell in the terminal window, you can type help to list available commands in shell You can also ping board with ping 192.168.1.202 On Terminal prompt, type ping 192.168.1.202 26
Type board IP address 192.168.1.202 in your web-browser 192.168.1.202/mqx.html 27
Click hvac demo, then choose hvac status Press SW1 or SW2 to see status change After changing temp, notice Fan/Furnace/AC settings 28
Open one of the MQX libraries, such as BSP library, then open user_config.h file All available MQX configuration options are displayed in several sheets based on its associated section BSP MQX RTCS MFS Shell USBH 30
Navigate folder D:\Freescale\Freescale_MQX_4_0\mqx\examples\nandflash\c w10\nandflash_twrk70f120m, drag.project file into CW10.3 Build the project and you will see error message displayed. This means you need to enable NAND flash driver using MQX configuration tool and recompile MQX libraries. 31
Reopen user_config.h file, select BSP sheet and change BSPCFG_ENABLE_NANDFLASH to TRUE and recompile BSP library Right click, bsp, Build Project 32
You are now setup to run nandflash demo on TWR-K70FN1M. This shows an example of features that can be enabled by recompiling the BSP. We will not load nandflash in today s demo, continue to the next Lab. 33
1. Select a baseline BSP to modify. 2. Clone selected BSP (and PSP) projects, configuration, and source code. 3. Prepare BSP-specific Debugger Configuration. 4. Modify BSP-specific include files. 5. Modify startup code. 6. Modify source code. 7. Create default initialization for I/O device drivers. 35
Existing BSP for Kinetis Kinetis 50MHz part twrk20d50m twrk21d50m Kinetis 72MHz part twrk20d72m Kinetis 100MHz part rev1.x twrk40x256 twrk53n512 twrk60n512 Kinetis 100MHz part rev2.x twrk40d100m twrk60d100m Kinetis 120MHz part twrk60f120m twrk70f120m Refer to AN4445 - Kinetis 100 MHz Rev 1.x to Rev 2.x Migration Guide for difference! Refer to AN4526 - Kinetis 100 MHz Rev 1.x to Kinetis 120MHz Migration Guide for difference! 36
Open BSP clone wizard Start->All Programs->Freescale MQX 4.0->MQX BSP Cloning Wizard Choose board name, MQX base and board base 37
Choose projects that need to be cloned and generate those projects, this may take some time. Only Select CodeWarrior 10.x, and a couple of examples Yes No Yes No 38
Key BSP project files bsp.h and <board_name>.h Main BSP header files, configuration constants, etc. <target_name>.lcf Linker command files (one for each memory configuration) init_hw.c (bsp_init.c in older BSPs) PLL, memory, FlexBus initialization init_bsp.c BSP timer, watchdog and IO drivers initialization init_gpio.c IO pin initialization routines called by IO drivers vectors.c Startup code (boot vector) and initial interrupt table Parameter Files init_<dev>.c Default initialization parameters structures for given IO device driver enet_ini.c Ethernet-specific initialization structures and functions mqx_init.c Default MQX initialization parameters structure Other bsp_prv.h Private structures and API functions cw.c CodeWarrior related initializations and CW startup functions overridden cw2.c MQX C entry code, main function 39
Navigate to folder D:\Freescale\Freescale_MQX_4_0\config\<Cloned K70 board>\cw10 and drag <Cloned K70 board>.wsd into CW10.3 Select working set for cloned K70 board 40
Collapse BSP files folder, all these files are supposed to be changed for a specific board. Each I/O device has a init_<dev>.c file mqx_main.c includes the _mqx() entry point OS tick interrupt routine and I/O driver installation is done in init_bsp.c We now have our own custom working set directory (.wsd) in /config And custom BSP, PSP, examples, etc! 41
Getting Started with Freescale MQX RTOS Getting Started with Runtime TAD Tool for Freescale MQX RTOS 43
MQX Task Aware Debugging plug-in (TAD) is an optional extension to a debugger tool which enables easy debugging of multi-tasking applications. It helps to visualize internal MQX data structures, task-specific information, I/O device drivers and other MQX context data. 44
The MQX TAD is available for the following platforms: Freescale CodeWarrior Classic which includes Development Studio for ColdFire version 7.x and Development Studio for Power Architecture MobileGT version 9.x. Eclipse-based CodeWarrior Development Studio version 10.x. IAR Embedded Workbench for ARM versions 5 and 6 and for ColdFire version 5 ARM-MDK uvision 4 45
Navigate to folder D:\Freescale\Freescale_MQX_4_0\mqx\examples\lwdemo\cw1 0\lwdemo_Customer_Board_K70 and import lwdemo Build the demo and choose debugger configuration 46
47
Select connection type you want to use in the Remote system list. If your connection is not available in the list define new one using New... menu Select Hardware and Simulator, Connection name and System type. In System tab specify Initialize target: as /lib/<board>/bsp/dbg/init_kinetis.tcl and Memory configuration: as /lib/ <board>/bsp/dbg/<board>.mem 48
Make sure the MQX OS Awareness is enabled in the Debugger tab. Press the Debug button in Debug configuration Window. The CodeWarrior will be switched to a debug perspective and will stop the program in the main() function. The MQX is not fully running in the main() point, so continue the application execution until the MQX is initialized to get the TAD features enabled. 49
TAD plug-in DLL is installed into the selected CodeWarrior tool automatically during Freescale MQX RTOS setup process. You may not need this step In case the plug-in was not properly installed (for example to a newly installed CodeWarrior studio, perform the following steps to install TAD manually: Close The CodeWarrior 10.x IDE Locate the tools/codewarrior_extensions/cw MCU v10.x directory in the Freescale MQX RTOS installation folder (by default C:/Program Files/Freescale/Freescale MQX x.y) Navigate to <install_dir>/tools/codewarrior_extensions/cw MCU v10.x directory Open the command like console and execute the command: install_cw10_plugin.bat <CW10.x install dir> Re-start the CodeWarrior 10.x IDE. 50
Navigate to MQX->Lightweight Events, Memory Pools, Memory Blocks To view the different TAD features 51
Task summary Stack usage summary 52
Memory pool summary 53
Info: Starting from MQX version 3.8.1, there is a new option for MQX debugging. With so called RuntimeTAD plug-in, the source of information displayed by TAD screens can be reconnected from a debugger to a run-time communication over serial line, CAN or direct BDM/JTAG access. 54
All Kinetis BSP projects are Processor Expert Ready and Processor Expert drivers are enabled in MQX RTOS environment You should have already imported the new Working Set (.wsd) you created previously. This is in <MQX install>\config\<clone k70 board>\cw10 56
Expand bsp_<clone k70 board> view Show processor expert view Generate code 57
Navigate to folder D:\Freescale\Freescale_MQX_4_0\demo\pe_demo\cw10\pe_d emo_customer_board_k70 and drag.project file into CW10.3 58
Expand bsp_<clone k70 board> project view Processor Expert Driver 59
Click on PE components to see the properties 60
Processor expert gives you a easy way to add device drivers to MQX BSP In BSP example one timer and one GPIO component are included Properties of component can be changed easily, for example GPIO pin 61
GPIO1 component in BSP drives LED s on tower board For exact GPIO used, refer to TWR-K70F120M Tower Module user s manual 4 Input/Output Connectors and Pin Usage Table 62
PWM configures channel 0 in Flex Timer 0 a PWM of 4096 timer-ticks 63
Build PE BSP and PE demo Debug the PE demo Check PWM output on A40, LED1 will toggle 64
Expand processor expert project view Search ADC_LDD in components library window 65
Right click on the component Select add to project 66
Double click on ADC_LDD Select ADC1 Enable interrupt service Select ADC1_DM1 channel, this is the ADC channel connected to Potentiometer on board 67
Enable static sample groups Open conversion time window Select 19.23us for conversion time 68
Click methods Tab Click to generate code for methods 69
The generated ADC LDD component code. 70
Expand pe_demo project view Hide processor expert view 71
Add new ADC task in main.c 72
Add task function and code 73
Add ADC1 event function code ADC1 channel is connected to TWR-K70FN1M potentiometer 74
Build the pe_demo project Test the new functionality in the application and the new LDD driver 75
The code size script file analyzes the generated xmap file produced by CodeWarrior or IAR Embedded Workbench or ARM-MDK Keil build tools and creates codesize report in an HL format. Freescale MQX 4.0\tools\codesize.exe Usage examples: codesize.exe -c cwcf7 <MAP_file> codesize.exe -M -c cwcf10 <MAP_file> codesize.exe +MFS -PSP -BSP -c cwcf10 <MAP_file> codesize.exe -c cwcf10 <MAP_file1> -c cwmpc9 <MAP_file2>... 77
Navigate to D:\Freescale\Freescale_MQX_4_0\demo\web_hvac\cw10\web _hvac_twrk70f120m\int Flash SramData Debug, copy intflash_sramdata_d.afx.xmap to D:\Freescale\Freescale_MQX_4_0\tools 78
Revisit the web-hvac demo 79
The MQX performance tool is a plug-in for CW10.3 IDE which can be used to display various run-time information about an MQX application. The information can also be retrieved from performance data file saved during any debugger session from Task-aware Debugger plug-in (TAD). 81
The current version of the MQX Performance Tool distributed with the MQX includes the following features Timeline graph of task switches, interrupts, synchronization objects, etc. Task Stack view which displays size of stacks and used stack sizes of all tasks. CPU Usage view displaying a pie chart of CPU runtime allocation among different tasks. Performance Data viewer. 82
Each view can be set to Online or Offline mode: In the Online mode, the Performance Tool uses data obtained through TAD and debugger connection from the MQX kernel log. To use the Performance Tool, the MQX application must have kernel logging enabled. In the Offline mode, the performance data file saved during a previous debugger session can be analyzed with Performance Tool views. In order to save the performance data file, the application should have the kernel logging enabled. Any time during a debugger session, use the MQX->Save Performance Data menu in the CodeWarrior IDE to save the data file for later analysis. 83
Open main.c in lwdemo project MQX_KERNEL_LOGGING need to be defined for using performance tool 84
Enable kernel logging with GUI based configuration tool Note: if MQX_USE_LOGS does not show up in GUI, right click user_config.h->open With->Text Editor and add the following #define MQX_USE_LOGS 1 #define MQX_KERNEL_LOGGING 1 Rebuild BSP and PSP library 85
In your imported lwdemo project, open the main.c file and increase the size of the kernel log being created. This is needed in order the Performance Tool has enough entries to display a meaningful information. The default value is set quite low to ensure application runs properly also on platforms with small RAM resources. Change to a big log size. 86
In the MQX tools menu select Timeline view. The timeline opens in an offline mode by default with no data to be displayed. Click the Toggle offline and online mode button to switch to online mode. Toggle online or offline 87
The graph shows task switches in your application. Icons represent various events logged by the MQX kernel such as interrupts, synchronization calls, message sending etc. 88
89
90
Overview of Tower system, CodeWarrior v10.3 and MQX 4.0 Easy OS configuration with GUI based interface Using BSP clone wizard to start with BSP porting Kernel debugging with task aware debugger tool Using Processor Expert together with MQX Estimate flash and RAM size usage for MQX based application Using performance tools for MQX 91