Kinetis微控制器知识库

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Kinetis Microcontrollers Knowledge Base

讨论

排序依据:
Actually the latest FSL USB stack has become part of KSDK , so it is recommended customer design USB application based on KSDK, while there are some old parts like K70, K60F and KL25 are still not supported in KSDK yet, so USB stack ver 4.1.1 is somewhat of help for those who still develop application based on those parts. USB stack ver 4.1.1 supports K70 instead of K60F, but since they are both Kinetis 120MHz parts, so the porting is very easy, here I provide a porting guide for this part. The porting is based on K70 USB examples, either Host or Device. 1. Replace the device header file. Use MK60F12.h instead, which may be extracted from KINETIS_120MHz_SC(Kinetis 120MHz bare metal sample code) , and put this header file in the folder of "C:\Freescale\Freescale USB Stack v4.1.1\Source\Host\source\bsp\P3" for Host or "C:\Freescale\Freescale USB Stack v4.1.1\Source\Device\app\common\kinetis" for device, and modify derivative.h as  below: 2. Macro definition changes in MK60F12.h, MCU_MK60F12 is defined instead of MCU_MK70F12, so in this step we will have to change some code snippet related with MCU_MK70F12. Firstly search MCU_MK70F12 in the project, for example , in the Host demo USB_MSD project based on IAR, you may do that as below: and you may find some macro like "#ifdef MCU_MK70F12" or "#ifndef MCU_MK70F12", and change them as below: #ifdef MCU_MK70F12 ----> #if (defined MCU_MK60F12) || (defined MCU_MK70F12) #ifndef MCU_MK70F12 ----> #if (!defined MCU_MK60F12) && (!defined MCU_MK70F12) 3. IO driver modification. Since TWR-K70F120 has almost the same hardware as TWR-K60F120, there is no need to change the driver code after replacing the header file, except the serial port driver, referring to USB_MSD demo, the serial driver is in sci_kinetis.c, TWR-K70F120M uses PTE16 and PTE17(UART2) as the console, while TWR-K60F120M use PTE8 and PTE9(UART5) instead, so you have to change the driver as below to make printf work properly. void sci2_init(){ #if (defined MCU_MK60F12) || (defined MCU_MK70F12)     register uint_16 sbr, brfa;     uint_8 temp; #ifdef MCU_MK70F12     /* Enable the UART2_TXD function on PTD3 */     PORTE_PCR16 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin     /* Enable the UART2_RXD function on PTD2 */     PORTE_PCR17 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin     /* Enable the clock  */     SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;     /* Make sure that the transmitter and receiver are disabled while we      * change settings.      */     UART_C2_REG(UART2_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);     /* Configure the UART for 8-bit mode, no parity */     UART_C1_REG(UART2_BASE_PTR) = 0;    /* We need all default settings, so entire register is cleared */     /* Calculate baud settings */     sbr = (uint_16)((SYSCLK*1000)/(UART_BAUDRATE * 16));     /* Save off the current value of the UARTx_BDH except for the SBR field */     temp = UART_BDH_REG(UART2_BASE_PTR) & ~(UART_BDH_SBR(0x1F));     UART_BDH_REG(UART2_BASE_PTR) = temp |  UART_BDH_SBR(((sbr & 0x1F00) >> 8));     UART_BDL_REG(UART2_BASE_PTR) = (uint_8)(sbr & UART_BDL_SBR_MASK);     /* Determine if a fractional divider is needed to get closer to the baud rate */     brfa = (((SYSCLK*32000)/(UART_BAUDRATE * 16)) - (sbr * 32));     /* Save off the current value of the UARTx_C4 register except for the BRFA field */     temp = UART_C4_REG(UART2_BASE_PTR) & ~(UART_C4_BRFA(0x1F));     UART_C4_REG(UART2_BASE_PTR) = temp |  UART_C4_BRFA(brfa);       /* Enable receiver and transmitter */     UART_C2_REG(UART2_BASE_PTR) |= (UART_C2_TE_MASK    | UART_C2_RE_MASK); #else   //MCU_MK60F12         /* Enable the UART2_TXD function on PTE8 */     PORTE_PCR8 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin     /* Enable the UART2_RXD function on PTE9 */     PORTE_PCR9 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin                /* Enable the clock  */     SIM_SCGC1 |= SIM_SCGC1_UART5_MASK;     /* Make sure that the transmitter and receiver are disabled while we      * change settings.      */     UART_C2_REG(UART5_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);     /* Configure the UART for 8-bit mode, no parity */     UART_C1_REG(UART5_BASE_PTR) = 0;    /* We need all default settings, so entire register is cleared */     /* Calculate baud settings */     sbr = (uint_16)((SYSCLK*1000)/(UART_BAUDRATE * 16));     /* Save off the current value of the UARTx_BDH except for the SBR field */     temp = UART_BDH_REG(UART5_BASE_PTR) & ~(UART_BDH_SBR(0x1F));     UART_BDH_REG(UART5_BASE_PTR) = temp |  UART_BDH_SBR(((sbr & 0x1F00) >> 8));     UART_BDL_REG(UART5_BASE_PTR) = (uint_8)(sbr & UART_BDL_SBR_MASK);     /* Determine if a fractional divider is needed to get closer to the baud rate */     brfa = (((SYSCLK*32000)/(UART_BAUDRATE * 16)) - (sbr * 32));     /* Save off the current value of the UARTx_C4 register except for the BRFA field */     temp = UART_C4_REG(UART5_BASE_PTR) & ~(UART_C4_BRFA(0x1F));     UART_C4_REG(UART5_BASE_PTR) = temp |  UART_C4_BRFA(brfa);        /* Enable receiver and transmitter */     UART_C2_REG(UART5_BASE_PTR) |= (UART_C2_TE_MASK    | UART_C2_RE_MASK); #endif        #endif } #ifdef __CC_ARM int sendchar (int ch) #else void TERMIO_PutChar (char ch) #endif { #if (!defined MCU_MK60F12) && (!defined MCU_MK70F12)     #if (defined MCU_MK20D5) || (defined MCU_MK20D7) || (defined MCU_MK40D7)         /* Wait until space is available in the FIFO */         while(!(UART1_S1 & UART_S1_TDRE_MASK)){};                /* Send the character */         UART1_D = (uint_8)ch;       #elif(defined MCU_MK21D5)         while(!(UART2_S1 & UART_S1_TDRE_MASK)){};                /* Send the character */         UART2_D = (uint_8)ch;       #elif(defined MCU_MKL25Z4) || (defined MCU_MKL46Z4)         /* Wait until space is available in the FIFO */         while(!(UART0_S1 & UART_S1_TDRE_MASK)){};        /* Send the character */        UART0_D = (uint_8)ch;       #else         /* Wait until space is available in the FIFO */         while(!(UART3_S1 & UART_S1_TDRE_MASK)){};                /* Send the character */         UART3_D = (uint_8)ch;     #endif   #else #ifdef MCU_MK70F12     /* Wait until space is available in the FIFO */     while(!(UART2_S1 & UART_S1_TDRE_MASK)){};     /* Send the character */     UART2_D = (uint_8)ch; #else      /* Wait until space is available in the FIFO */     while(!(UART5_S1 & UART_S1_TDRE_MASK)){};     /* Send the character */     UART5_D = (uint_8)ch; #endif #endif } 4. Set the correct device type in IDE settings. For IAR, change the device family in view of project options. Now, you can start to run the USB demos on TWR-K60F120M, please note the above steps is ok for USB device stack, but USB Host stack has some code issue , as mentioned in [USB stack ver 4.1.1] a code issue in msd_mfs_generic host demo , so please fix the issue before going further. Hope that helps, Best Regards, Kan
查看全文
This manual explains how to create a project in CW and add components to Processor Expert. It also includes a couple of examples to print and get data with the printf and scanf functions from the stdio library by using Serial component (UART).
查看全文
General Purpose Input/Output module presented by Jose Maria Casillas, Freescale TIC. Module explanation and alternative pin´s functions. Short explanation on the Bit Manipulation Engine (BME). Hands-On: LED RGB. Push Button. Módulo GPIO (General Purpose I/O) presentado por Jose María Casillas, Freescale TIC. Explicar el modulo y las funciones alternativas de los pines. Breve descripción del Bit Manipulation Engine (BME). Hands-On: LED RGB. Push Button.
查看全文
UART Presentation (universal asynchronous receiver/transmitter) by Ali Piña, Freescale TIC. Module Explanation Connection Diagram Hands-On. Polling mode. Interrupt Mode. Presentación de UART  (universal asynchronous receiver/transmitter) by Ali Piña, Freescale TIC. a.       Explicación del modulo. b.      Diagrama de conexión. c.       Hands-On. Modo de Poleo Modo de Interrupción
查看全文
系统框图如下图示: 硬件设计支持如下扩展功能: (1)      USB、SD卡(SDHC接口) (2)      SWD调试+串口Printf。 (3)      SPI外设接口,支持NRF24L01、W5100、WIFI等。 (4)      两路差分ADC输入、一路DAC输出。 (5)      50M有源晶振,供MCU以及以太网PHY工作。 (6)      32.768K RTC时钟晶振。 (7)      SPI Flash、EEPROM(IIC接口) (8)      CAN接口。以太网应用。 (9)      TSI电容触摸按键。 (10)  GPIO:按键输入以及LED输出指示。 (11)  PWM输出。 (12)  FlexBus总线扩展: 扩展应用一:4.3寸LCD。 扩展应用二:FPGA扩展高速ADC采集。(设计进行中) 基于K60+SSD1963驱动4.3寸屏并移植ucGUI的测试实例,移植后的视频效果见如下链接: http://v.youku.com/v_show/id_XNzAwMTE5OTA0.html?firsttime=15 Pixels/sec: 16397220。
查看全文
Hi All, Embedded systems industry are tending to optimized their products to offers a better performance in power management, aiming for longer battery life, using low-power modes in the application without reducing functionality. With this in mind, it arises a requirement in these compact devices, power supply monitor. This document will include a brief description of some features available in different power modes of the Kinetis family and it will focus on how we can implement these features, using KSDK 2.0, to monitor power supply voltage and detect when this voltage has fallen at determined value. This document is based MCU K21 but the same principles can be applied to any Kinetis K and L family. It will use KDS 3.2 as IDE and TWR-K21F120M evaluation board as target.   Hope you can find it useful Best Regards Jorge Alcala
查看全文
1.基于CMSIS-DAP的脱机编程工具         飞思卡尔的FRDM开发板都板载OpenSDA仿真器,该仿真器基于MK20DX128VFM5芯片,内部由Bootloader和app所组成,当用户按下Reset按钮后再插上USB接口,此时会进入Bootloader模式,此时PC端会出现一个名为Bootloader的可移动存储器,用户可以通过拖入预编译好的*.SDA升级app,更新v114版本的app后,重新插拔USB即可生效,此时会枚举出虚拟串口,仿真器以及MSD的可移动存储器。Bootloader占用了MK20DX128VFM5内部从0开始到0x5000的地址,App从0x5000地址开始。        CMSIS-DAP(mbedmicro/CMSIS-DAP · GitHub)是ARM公司的一个开源项目,它提供了一个基于Web的开发环境(mbed | welcome), 开发环境提供了基于C++的开发库,用户可以通过Web编程,然后下载编译好的bin文件,通过CMSIS-DAP烧写到FRDM开发板中。CMSIS-DAP与OpenSDA类似,也是由Bootloader和app所组成,最大的区别是CMSIS-DAP的Bootloader占用的地址为0x0~0x8000。        由于CMSIS-DAP是Apache License开源的,通过修改其Bootloader代码可以比较容易的做出一个脱机烧写器参考。        1. 添加SWD的访问接口。        2. 修改链接文件,默认Bootloader是运行在0地址上的,而实际编程工具最好运行在0x5000或者0x8000这两个地址上,这样不需要通过仿真器对于MK20DX128进行编程即可更新其内容,同时也可以轻松在仿真器及烧写器间进行切换。        3. 修改MSD烧写文件的地址,默认Bootloader是烧写从0x5000或者0x8000开始的地址,而这个地址现在放的是脱机烧写器代码,所以需要向后移动到0x10000,并将目标文件大小存放在0x1F800地址上。脱机烧写器由于将目标文件存放在K20芯片内部,所以受到K20内部flash大小的限制,只能烧写目标文件小于60K。        4. 添加编程算法工程,由于目标芯片内部的flash需要不同的驱动,所以可以将他们生产的算法代码先放到K20内部0x1FC00的地址上,烧写器开始工作时,先将编程算法通过SWD下载到目标文件的RAM中,并修改目标芯片的SP PC指针,让其运行。编程算法与烧写器的运行程序通过RAM进行交互。 参考代码下载地址: hudieka/OpenSourceOfflineProgrammerTools · GitHub 具体使用方法可以参考附件:
查看全文
This is an example for the Kinetis KE02Z devices, showing how to program the EEPROM with initial values when the flash is programmed.  The example works on the FRDM-KE02Z40M board, and was written with Kinetis Design Studio (KDS) v3.0.0.  The example also uses Processor Expert (PEx) to configure the UART and erase/program the EEPROM.  The EEPROM programming works with the P&E Micro Multilink Universal debugger, as well as the P&E Micro OpenSDA debugger app for the FRDM-KE02Z40M board. To program the EEPROM with initial values, the application declares constants for the EEPROM locations, and initializes these in the source code in eeprom.c. Compiler pragmas/attributes are used to force the linker to place these constants in EEPROM, using the m_eeprom memory section defined in the linker command file \Project_Settings\Linker_Files\ProcessorExpert.ld.  The P&E Micro flash programming algorithms initialize the EEPROM in 4Byte words. Therefore, any initialized EEPROM locations should be in aligned 4Byte words. This example initializes the first 4Bytes in the EEPROM as 0, 64, 128, 192. The example uses a terminal program to display EEPROM information.  It connects to the OpenSDA COM port on the FRDM-KE02Z40M board using UART1 from the KE02Z. The terminal settings are:   Baud Rate: 38,400   Data: 8bit   Parity: None   Stop: 1bit   Flow Control: None The example prints 5 bytes of EEPROM to the terminal after reset: the 4 initialized bytes, plus the following EEPROM byte which was not initialized. Then the example increments the first byte, and decrements the second byte, and writes the new values back to EEPROM.  The other 3 bytes are not changed. Then the application prints the new EEPROM values of all 5 bytes.  Everytime the MCU is reset, it will print the existing EEPROM data and then the changed data.  Below is the example output from the terminal after initially programming the KE02Z, and then doing a single reset: Terminal output:   KE02Z EEPROM example   EEPROM values after reset = 0 64 128 192 255   EEPROM values after updating = 1 63 128 192 255   KE02Z EEPROM example   EEPROM values after reset = 1 63 128 192 255   EEPROM values after updating = 2 62 128 192 255
查看全文
The AOI and Crossbar modules are inregrated in DSC, Kinetics KV and i.mxrt families, user can use them to generate complicated trigger signal for the on-chip peripherals. The DOC discusses the AOI function, crossbar fuction based on KV58. It gives the example, the example demos how to implement AND operation of two signals via crossbar switch A and B and AOI modules. The two logic signals are connected to the pads of KV58, and routed to AOI inputs via Crossbar switch B, the AOI sub-module0 implements the AND operation of the two signals, and output the AND output signal Event0  to pad of KV58 via crossbar switch A. Connect input pads and output pad of KV58 to oscilloscope, from the waveform of the three signals on scope, we can see that the AND logic  is implemented.
查看全文
This application demonstrates the use of the FRDM-KL25 as a HID HOST. In this project the HID Device is a Numeric Keyboard and the HOST Device (FRDM-KL25) is handling the data and printing them in a 16x2 LCD used in 8 bits mode .
查看全文
Download Kinetis M bare-metal drivers and software examples installation file. Changes in 4.1.6 : Modified FreeRTOS kernel to disable all interrupts prior entry to critical section and enable all interrupts upon exiting from critical section. This kernel behavior is compatible with standard FreeRTOS port to the ARM Cortex-M0 core. All freertos_cfg header files updated to reflect kernel change. Updated PLL_Disable macro and Quad Timer driver. Added UART_SetBaudRate macro. Removed RCM_ClrResetFlags macro. Fixed issue of generating callback events after conversion for these ADC channels with interrupt disabled.
查看全文
Some of our customers encountered clock stretching issue when using the I2C. Actually the first should been in mind is the clock stretching is usually done by the slave, not the master.  In the case for the Kinetis as master to connect with I2C device, the clock stretching should been done by the slave device. In this case the slave device should hold the clock signal low until it has data available. There isn’t anything that needs to be done to enable clock stretching on the master side. So how the code do with the clock stretching? The slave should toggling read_start high first and reading the data register to actually start the transfer. Be remember that the read from the data register is what actually triggers the transfer. Customer always missed this point.
查看全文
Many customers reported that their ADC function works on FRDM-KL27Z board but meet issue on their own board. We need to pay attention to the difference between the ADC reference voltages of different packages (on board MKL27Z64VLH4 is 64LQFP package). This tip introduce the ADC Reference Options on KL17/KL27 32/36pin package Part number involved: 32-pins 36-pins MKL17Z32VFM4 MKL17Z32VDA4 MKL17Z64VFM4 MKL17Z64VDA4 MKL27Z32VFM4 MKL27Z32VDA4 MKL27Z64VFM4 MKL27Z64VDA4 PTE30/VREF_OUT- connected as the primary reference option on 36-pin and below packages VDDA/VSSA - connected as the VALT reference option   ADCx_SC2[REFSEL] selects the voltage reference source used for conversions.   About the primary reference option: When on-chip 1.2V VREF is enabled, PTE30 pin must be used as VREF_OUT and has to be configured as an analog input, such as ADC0_SE23 (PORTE_PCR30[MUX] = 000). Notice: this pin needs to connect a capacitor to ground.   PTE30 can also be used as an external reference voltage input as long as PTE30 is configured as analog input and VREF module is disabled. It means you can connect external reference voltage to PTE30 pin and use it as ADC reference voltage. (For example 3.3V) KL17P64M48SF2RM     Kinetis KL17: 48MHz Cortex-M0+ 32-64KB Flash (32-64pin) (REV 4.1) KL27P64M48SF2RM     Kinetis KL27: 48MHz Cortex-M0+ 32-64KB Flash (32-64pin) (REV 4.1)
查看全文
The following file contains example code for usage of ADC, UART, DAC, GPIO, I2C, interrupts, MCG and timers for the k53 platform. Regards.
查看全文
Hi,All Our team have developed the K60's peripheral derives lib which is open source and open source firmware library. the The open source lib have these feature just as follow: 1\The setup code based on the CMSIS Standard; 2\The lib include most of peripherals of K60 such as ADC,DAC,DMA,CAN,FTM,LPTMR, ENET,FLASH,FLexBUS,GPIO,IIC,MCG,PDB,SPI,USB,TSI,UART,WDOG,SDHC,PIT,etc. 3\All of the peripheral initiate function are based on the a structure variable Struct format. 4\Add parts of Freescale USB Stack into the lib such as USB CDC and USB HID mouse. 5\We also develop relative example projects to demonstrate how to use the library for the peripheral. All of the project are created by the IAR for ARM Ver.6.4. The attach is the code. We divide the code into two parts. One part is driver lib, and another part is project. PS 1:All of the code comments are Chinese, please forgive. PS 2:All of drivers is on the \lib\LPLD\HW.      The K60 project need Unzip into the \porject\. PS 3:The code has many place that need update and improve. if you have any doubt and opinions,please contact us.support[AT]lpld.cn Best Regards Wang
查看全文
  MCU Bootloader2.0.0 enables quick and easy programming of Kinetis MCUs through the entire product life cycle, including application development, final product manufacturing, and beyond. It supports many kinds of peripherals, include UART, I2C, SPI, USB, CAN and so on. Among these peripherals, UART is most common used. In reference manual, it only says that feature can be turned on or off by using #define statement in bootloader_config.h. In fact, you can use UART0 by default. But if you want to use other UART port, change TERM_PORT_NUM to other value is useless. If you traced this value, you’ll find it is not used at all, nor the TERMINAL_BAUD. Here we use FRDM-KV31F512 as the example. We want to download image by UART2. First, we should modify peripherals_pinmux.h. #define BL_ENABLE_PINMUX_UART2 (BL_CONFIG_SCUART)     //line 38   //! UART pinmux configurations #define UART2_RX_PORT_BASE PORTE #define UART2_RX_GPIO_BASE PTE #define UART2_RX_GPIO_PIN_NUM 17               // PIN 16 in the PTB group #define UART2_RX_FUNC_ALT_MODE kPORT_MuxAlt3   // ALT mode for UART0 RX #define UART2_RX_GPIO_ALT_MODE kPORT_MuxAsGpio // ALT mode for GPIO functionality #define UART2_RX_GPIO_IRQn PORTE_IRQn #define UART2_RX_GPIO_IRQHandler PORTE_IRQHandler #define UART2_TX_PORT_BASE PORTE #define UART2_TX_GPIO_PIN_NUM 16             // PIN 17 in the PTB group #define UART2_TX_FUNC_ALT_MODE kPORT_MuxAlt3 // ALT mode for UART0 TX   The original define is UART0, here we change it to UART2. It is strongly recommended to do so. Otherwise you’ll find that UART can’t work at all. Another comment here is PTE16 and PTE17 is conflict with SPI. You must disable SPI or change SPI function to other pins.   Next we must modify peripherals_KV31F512.h. const peripheral_descriptor_t g_peripherals[] = { #if BL_CONFIG_SCUART    // UART0    {.typeMask = kPeripheralType_UART,      .instance = 2, // change this value from 0 to 2      .pinmuxConfig = uart_pinmux_config,      .controlInterface = &g_scuartControlInterface,      .byteInterface = &g_scuartByteInterface,      .packetInterface = &g_framingPacketInterface },   Although there is a baud rate definition TERMINAL_BAUD, but it is never used too. MCU bootloader2.0.0 use auto baud rate detection. When power on, bootloader will go to autobaud detection mode. KinetisFlashTool sends ‘0x ’ every second. Bootloader check this byte and calculate baud rate.   After getting this value, bootloader will change to normal communication mode. Baud rate will not change until reset. If blhost is used, subsequent blhost invocations must specify the same baud rate as was used for the initial invocation unless the bootloader is reset. If the baud rate is not specified using the -p COMx, <baudrate> option, the UART baud rate will be set to 57600. Since Kinetis MCU UART module don’t have auto frequency detect function, the bootloader detects frequcny by software. It uses GPIO interrupt and timer to measure frequency. But in bootloader, there is only code for UART0, there isn’t code for other UART port. We must add the code. In hardware_init_KV31F512.c, modify the function get_uart_clock()   uint32_t get_uart_clock(uint32_t instance) {    switch (instance)    {        case 0:        case 1:            // UART0 and UART1 always use the system clock            return SystemCoreClock;        case 2:            return get_bus_clock();        default:            return 0;    } }   KV31 has 4 UART, include three UART modules and one low-power UART. They have different clock source. UART0 and UART1 use System clock while UART2 and LPUART0 use Bus clock. Thus, we finished the work. UART2 can work as the download port now.
查看全文
This document introduces basic usage of NVIC based on Freescale Kinetis. please see the attached document for details.
查看全文
The SAI of Kinetis supports 4 modes:normal mode, network mode, I2S mode, AC97 mode, the documentation give the brief introduction about the 4 modes, give the waveform of the 4 modes.
查看全文
The documentation points out that the Figure 32-1. Multipurpose Clock Generator (MCG) block diagram in KV5xP144M240RM.pdf is incorrect, the  /2 divider is NOT included in the feedback loop. It gives the formula to compute the VCO and MCGPLLCLK clock frequency and corresponding code.
查看全文
MAPS-KS22 Board Introduction: MAPS boards are localization evaluation boards for Chinese customers. The MAPS boards are suitable for NXP MCU product, with low coat, more flexibility and easy-copy features, which matching with local customer requirements and better for learning and product evaluation. MAPS board includes four parts board, which are MCU Board, Peripheral Board, Application Board & Socket Board. The naming of MAPS are using the four-part board initial letter. MCU board is NXP Kinetis MCU based evaluation main board with chip related special module interface/device, such as graphic LCD/ENET interface and etc. The MCU board fan out all MCU pins as test points for measuring. The MCU board also provide two 32-pin socket to connect external peripheral board or application board. Peripheral Board collects more general device into one board and using two 32-pin socket connects with MCU board. The MAPS-Dock is the first peripheral board, which with below configuration: Micor-SD card slot; six touch pads; USB FS interface; IrDA transceiver; one SPI Interface (SPI-Flash); two UART interface; four buttons; one I2S interface (audio codec); one CAN interface; two potentionmeter; one DAC output interface; 128x64 monochrome LCD; one 5-way button. It also with SWD debugger on board and USB CDC virtual COM. Application Board designed for special applications, such as motor control, IOT, Smart Home, Wireless Charger and etc. Socket Board provides interface for FreeDOM boards/Arduino boards/Customer defined boards. MAPS-KS22 board MCU board for KS22 chip evaluation. KS22 MCU is based on the ARM® Cortex®-M4 core with 120MHz MCUs with FPU, offering full-speed USB 2.0 OTG, in addition to other features like USB crystal-less functionality. MAPS-KS22 oobe demo porting process MAPS-KS22 oobe demo is based KSDK V1.0, which will show Freescale LOGO on the SPI color LCD and meanwhile use FlexIO I2S to play an audio on microphone. Step1: visit Kinetis Expert website (http://kex.nxp.com/en/welcome) to download MAPS-KS22 KSDK V2.0 software: Step2: download [Kinetis SDK Project Generator Tool] from below link and generate oobe demo project based on MAPS-KS22 SDK V2.0 software: https://www.nxp.com/webapp/sps/download/license.jsp?colCode=KSDK-PROJECT-GENERATOR-TOOL&appType=file1&location=null&DOWNLOAD_ID=null Step 3: After that, open the oobe project, which located at default path: C:\Freescale\SDK_2.0_MAPS-KS22\boards\mapsks22\user_apps\oobe\iar The default project is based on <hello-world> demo, it need to add LED control code. Those part of code could be found at <main.c> file and related pin muxing code at <pin_mux.c> file. Step 4: Modify ili9341 related driver: For the oobe project with two major functions, the first one is to display Freescale LOGO at LCD. The MAPS-KS22 board graphic LCD is using ili9341 TFT LCD driver with SPI interface with KS22 chip. The previous oobe project is using GPIO pins emulate SPI communication, we will make the similar application with KSDK V2.0 driver. Most modification based on the GPIO pins control. Please check below code at <ili9341.h> file, which call KSDK V2.0 GPIO driver: #define ILI9341_CS_HIGH()       GPIO_SetPinsOutput(BOARD_LCD_CS_GPIO, 1U << BOARD_LCD_CS_PIN) #define ILI9341_CS_LOW()        GPIO_ClearPinsOutput(BOARD_LCD_CS_GPIO, 1U << BOARD_LCD_CS_PIN) #define ILI9341_CLK_HIGH()      GPIO_SetPinsOutput(BOARD_LCD_CLK_GPIO, 1U << BOARD_LCD_CLK_PIN)  #define ILI9341_CLK_LOW()       GPIO_ClearPinsOutput(BOARD_LCD_CLK_GPIO, 1U << BOARD_LCD_CLK_PIN) #define ILI9341_MOSI_HIGH()     GPIO_SetPinsOutput(BOARD_LCD_MOSI_GPIO, 1U << BOARD_LCD_MOSI_PIN) #define ILI9341_MOSI_LOW()      GPIO_ClearPinsOutput(BOARD_LCD_MOSI_GPIO, 1U << BOARD_LCD_MOSI_PIN)      #define ILI9341_MISO_HIGH()     GPIO_SetPinsOutput(BOARD_LCD_MISO_GPIO, 1U << BOARD_LCD_MISO_PIN) #define ILI9341_MISO_LOW()      GPIO_ClearPinsOutput(BOARD_LCD_MISO_GPIO, 1U << BOARD_LCD_MISO_PIN) And it also need to add ili9341 control pin muxing initialization code at <pin_mux.c> file. Step 5: We could modify the Freescale logo with new NXP logo, which could using [Embedded GUI Conversion Utility3.0] tool. This tool could be downloaded from below link:  http://tinyurl.com/eGUI-Convert  The conversion result of the graphic data is 16-bit array, which need be transfer to 8-bit array. After that, compile and download the image to the board, it with below result: Step 6: The oobe demo provide another function to play music with MAPS-DOCK board WM8960 codec chip, then using headphone will hear the sound. For the KS22 with FlexIO module, the demo will use FlexIO emulating I2S bus to transfer data to WM8960 codec chip. About I2S bus MCLK clock source, the MAPS-KS22 provide two selection, one is using TPM1_CH1 pin, the other one is using I2S0_MCLK pin with JP5 jumper selection. In oobe demo, we use TPM1_CH1 pin to generate 12MHz MCLK clock with TPM module output compare mode. Related code, please refer below tpm_init_output_compare() function at <main.c> file: //enable clock gating of tpm1 CLOCK_EnableClock(kCLOCK_Tpm1); //set TMP output compare mode TPM_SetupOutputCompare(BOARD_TPM_BASEADDR, BOARD_TPM_CHANNEL, kTPM_ToggleOnMatch, 1U); BOARD_TPM_BASEADDR->MOD = 0x1; TPM_StartTimer(BOARD_TPM_BASEADDR, kTPM_SystemClock);   //TPM counter increments on every TPM counter clock Step 7: WM8960 is a stereo CODEC chip provide I2C port for chip configuration. There need to initialization the WM8960 chip before using it with related driver <wm8960.c> & <wm8960.h> files. The MAPS-KS22 board using LPI2C0 module connects with WM8960 chip, so there need to port using LPI2C driver of KSDK V2.0 and modify the WM8960 driver related. The LPI2C module initialization code located at <main.c> with lpi2c_master_init() function. The WM8960 driver major modification with WOLFSON_WriteReg() function at <wm8960.c> file, calling the LPI2C driver of KSDK V2.0 with below code:  wolfson_status_t WOLFSON_WriteReg(uint8_t reg, uint16_t val) {       uint8_t cmd,buff;        status_t ret;        cmd = (reg << 1) | ((val >> 😎 & 0x0001);    // register address        buff = val & 0xFF;     //data        reg_cache[reg] = val;      // copy data to cache         uint8_t data[2];         data[0] = cmd;         data[1] = buff;         //start lpi2c tx operation                   ret = LPI2C_MasterStart(LPI2C0, WM8960_I2C_ADDR, kLPI2C_Write);           // send two data with register address and related value          ret = LPI2C_MasterSend(LPI2C0, data, 2);                //stop lpi2c tx operation                  ret = LPI2C_MasterStop(LPI2C0);               if(ret != kStatus_Success)          {  return kStatus_WOLFSON_I2CFail;  }          return kStatus_WOLFSON_Success; } After WM8960 chip driver modification, there could call related driver to initialize WM8960 chip and configure the communication interface with I2S bus. Following steps focus on how to transfer data to WM8960 codec with I2S bus. Step 8:  The FlexIO modul will simulate I2S bus call FlexIO_I2S_MasterInit() function in <main.c> file to initialize FlexIO module as I2S master. There using FXIO0_D4 pin as I2S bit clock pin, using FXIO0_D5 pin as I2S Transmit pin and using FXIO0_D6 pin as I2S Transmit Frame Sync pin. KSDK V2.0 provide FlexIO for I2S driver located at <fsl_flexio_i2s.h> file. Step 9: There will call eDMA with FlexIO module to reduce the core work load during the I2S data transfer. It will initialize the eDMA & DMAMUX modules for FlexIO. Related code located at <main.c> file with ConfigDMAforFlexIOI2STX() function: void ConfigDMAforFlexIOI2STX(void) { EDMA_GetDefaultConfig(&dmaConfig); EDMA_Init(EXAMPLE_DMA, &dmaConfig); EDMA_CreateHandle(&dmaHandle, EXAMPLE_DMA, EXAMPLE_CHANNEL); DMAMUX_Init(DMAMUX0); DMAMUX_SetSource(DMAMUX0, EXAMPLE_CHANNEL, EXAMPLE_DMA_SOURCE); DMAMUX_EnableChannel(DMAMUX0, EXAMPLE_CHANNEL); }    Step 10: KSDK V2.0 software provides FlexIO I2S eDMA driver located at <fsl_flexio_i2s_edma.c> file, with below codes to initialize FlexIO I2S master DMA handler and to configure the sample rate & audio data format to be transferred: FLEXIO_I2S_TransferTxCreateHandleEDMA(&base, &txHandle, callback, NULL, &dmaHandle); FLEXIO_I2S_TransferSetFormatEDMA(&base, &txHandle, &format, 48000000); Step 11: After above preparation, following action will start to transfer music data to WM8960 codec with below code. When the music data transfer finished, the callback function will be called to start next round data transferred. Then we could hear the sound with endless loop. static void callback(FLEXIO_I2S_Type *i2sBase, flexio_i2s_edma_handle_t *handle, status_t status, void *userData) {   // Initiate FlexIO I2S transfer again after previous transfer finished  FLEXIO_I2S_TransferSendEDMA(&base, &txHandle, &xfer); } About more detailed oobe demo software info, please check attached file. The default oobe demo located path is: C:\Freescale\SDK_2.0_MAPS-KS22\boards\mapsks22\user_apps\oobe
查看全文