Kinetis Microcontrollers Knowledge Base

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kinetis Microcontrollers Knowledge Base

Discussions

Sort by:
Hi All, This Kinetis Design Tips and Tricks document is used for those needing to have a checklist or troubleshooting document for their Kinetis hardware designs.  This will be a living document that is updated as needed. Enjoy all! Please give any and all feedback on this forum. Mike Steffen
View full article
To do: Implement a program that lets the 4 LEDs on the Tower toggle all together using the PIT Interrupt. This time, let the program run in the Flash. * toggle period 0.5 s * extract vector table and service routines in 'vector.c' * Change the linker command file 'ldscript_flash' * Take care of the 16 Byte security settings from $400-$410 in the Flash. Do not overwrite!!! Hint: Use the 'arm_cm4.c and 'arm_cm4.h' from the freescale kinetis homepage, which include access functions for the NVIC. For ease of use, these routines are included in the result file. Result: TWR_K60_PIT0_Flash.zip
View full article
To do: Implement a program that lets the 4 LEDs on the Tower toggle all together using the PIT Interrupt. For easy debugging, let the program run in the RAM. * toggle period 0.5 s, * extract vector table and service routines in 'vector.c. Hint: Use the 'arm_cm4.c and 'arm_cm4.h' from the freescale kinetis homepage, which include access functions for the NVIC. For ease of use, these routines are included in the result file. Result: TWR_K60_PIT0.zip
View full article
To do: Implement a program that lets the 4 LEDs on the Tower walk like this: * a single LED from left to right, * then the two left ones, the two right ones, * the two outside and at least the two LEDs in the middle. For easy observing write a wait routine, called 'delay (unsigned int ms)', of about 1 second without using any library functions. The processor will start with the standard frequency of 20...25 MHz. Estimate the time, that a loop needs to realize the time. Hint: Do not forget to stop the Watchdog Module at the beginning. Result:TWR_K60_Lauflicht.zip  including a readme with the compiler options
View full article
The KL TSI Library provides the following benefits: • Reduces time to market and development costs. Already available turn-key TSI Library for IH cooker, remote controller applications, etc. • KL TSI is a hardware touch sensing solution, without any additional peripherals, e.g. Timers, GPIO, CPU execution, as a result reduces overall system cost and size. • Enhances reliability by enabling environment adaptive algorithm, eliminating water droplet and stream influence, and filtering electromagnetic interference. • Easy to use, simplifies user interface design. Flexible TSI software library enabling customers to develop an application • FreeMaster1.4 visualizes TSI signal on screen, thus customer can debug and tune touch software simply.
View full article
I need to connect multi phy device with a single cpu. I want realize a follow hardware (see picture MultiPhys.jpg ). My dubt is if this schematic is correct. I need to send frame either PHY1 or PHY2. My application is like a gateway, it sends messages to network in selective way ( and it receives from every PHYs device ). Is it possible connect many PHY device with one RMII bus? what is the correct way to connect many PHY device on RMII bus? Anyone knowns documents that describe multi Phy configurations ?
View full article
中文版本:     在KL25的官方Demo 源代码中只有I2C驱动的PE代码而没有I2C驱动的baremental代码,对于不习惯用PE生成代码的用户直接上手有难度,于是考虑将K60的 I2C baremental 驱动代码中移植到KL25上,以供大家参考。但在移植过程中遇到了两个比较典型的问题,所以这里分享出来,希望能帮助遇到同样问题的用户迅速定位并解决问题。 测试硬件:TWR-K60D100M开发板  K60+MMA8451(MMA8451为三轴加速传感器,与K60通过I2C总线连接。K60作为master,MMA8451作为slave)                 FRDM-KL25Z开发板       KL25+MMA8451 开发环境:IAR 6.6 1.问题描述: 配置I2Cx_F寄存器MULT位不为0时,Repeat start信号无法产生 问题提出: K60示例代码(如附件1)中I2C demo的功能是通过I2C接口读取板载的加速度传感器MMA8451的数据,并且I2C数据控制采用查询ACK标志位的方式,在TWR-K60D100M开发板上运行该Demo一切正常。使用几乎相同的I2C驱动代码,在FRDM-KL25Z开发板上执行发现:程序总是停在如下Function 1的红色字体行i2c_wait(I2C0_B),进入这个函数内部,它实际上是停在while((p->S & I2C_S_IICIF_MASK)==0),一直等待传输完成的中断标志IICIF置位。 Function 1. u8 hal_dev_mma8451_read_reg(u8 addr) {     u8 result;     i2c_start(I2C0_B);     i2c_write_byte(I2C0_B, I2C_ADDR_MMA8451 | I2C_WRITE);     i2c_wait(I2C0_B);     i2c_get_ack(I2C0_B);     i2c_write_byte(I2C0_B, addr);     i2c_wait(I2C0_B);     i2c_get_ack(I2C0_B);     i2c_repeated_start(I2C0_B);     i2c_write_byte(I2C0_B, I2C_ADDR_MMA8451 | I2C_READ);     i2c_wait(I2C0_B);     i2c_get_ack(I2C0_B);     i2c_set_rx_mode(I2C0_B);     i2c_give_nack(I2C0_B);     result = i2c_read_byte(I2C0_B);     i2c_wait(I2C0_B);     i2c_stop(I2C0_B);     result = i2c_read_byte(I2C0_B);     pause();     return result; } Function 2. void i2c_wait(I2C_MemMapPtr p) {     while((p->S & I2C_S_IICIF_MASK)==0)  ; // wait flag     p->S |= I2C_S_IICIF_MASK;    // clear flag } 原因分析:      初步判断可能是上一步数据的传输 i2c_write_byte()没有完成,导致IICIF未能被置位。于是通过示波器去捕捉这个过程,发现在执行 i2c_repeated_start(I2C0_B)时,KL25并没有产生一个 Repeat start信号。经过一番谷哥和度娘,终于在Kinetis L的Errata中找到了答案:Repeat start cannot be generated if the I2Cx_F[MULT] field is set to a non-zero value. 这也就意味着,当 I2Cx_F[MULT]位被设置为非0值时,I2C Master不能产生一个Repeat start信号。而在应用程序的I2C初始化I2C_init()代码中, 我恰好设置I2Cx_F[MULT]=01,这正好是符合了Errata描述的错误产生的条件。 解决方案:      I2C的C1寄存器中MULT位是I2C SCL时钟的倍乘因子,用于控制I2C的波特率。为解决上面的问题,FSL官方提供了两种workaround的办法: 1)如果repeat start必须产生时,配置 I2Cx_F[MULT]为0; 2)在置位 I2Cx_F register (I2Cx_C1[RSTA]=1)的Repeat START产生位之前临时设置 I2Cx_F [MULT],然后再在repeated start信号产生后恢复I2Cx_F [MULT]位的设置。 按照第一种方法,我修改程序中I2Cx_F[MULT]的设置从01到00,然后程序在FRDM-KL25Z 开发板上运行正常,能正常读取板载的加速度传感器MMA8451的数据。 2.问题描述: I2C单字节读取时序问题 问题提出: 在上面的Function 1中, KL25读取MMA8451的基本过程是:发送要访问的从机地址及对从机的写命令->发送要访问的从机的寄存器地址->发送Repeat Start信号到从机->发送要访问的从机地址及读命令->读取从机返回的数据,如下Figure1 MMA8451的单周期读时序图所示,其过程和上面代码的描述一致。但是有一点值得注意的是Figure 1中红色方框部分,按照Figure 1的表述,Master是在从Slave从机读取DATA[7:0]之后返回NAK信号的,用于指示本数据是Master要接收的最后一个DATA,最后发送stop signal终止数据的传送。按照这个思路得到的KL25的程序代码如下Section 2,它首先去读取从机返回的数据 i2c_read_byte(I2C0_B),然后发送NACK信号到从机i2c_give_nack(I2C0_B)。然而从KL25实际的物理时序的角度看,这个顺序是错误的,正确的应该是如下Section 1,应该在读取从机返回的数据 i2c_read_byte(I2C0_B)之前,首先发送NACK信号到从机i2c_give_nack(I2C0_B)。 Section 1.   i2c_set_rx_mode(I2C0_B);   i2c_give_nack(I2C0_B);----line1   result = i2c_read_byte(I2C0_B);----line2   i2c_wait(I2C0_B);----line3   i2c_stop(I2C0_B);----line4   result = i2c_read_byte(I2C0_B);----line5 Section 2.   i2c_set_rx_mode(I2C0_B);   result = i2c_read_byte(I2C0_B);-   i2c_wait(I2C0_B);   i2c_give_nack(I2C0_B);-   i2c_stop(I2C0_B); 原因: 主机发送的NACK信号只有在下一个数据接收之后才会被push到总线上,KL25的RM手册中的描述为the No acknowledge signal is sent to the bus after the following receiving data byte (if FACK is cleared)。 具体分析: 按照两个时序分别做了一个测试,并用示波器捕捉了相应的波形:执行Section 1的代码得到的波形如下Figure 2所示,NACK(1)信号刚好在第9个pluse脉冲上升沿被push总线上,然后在Stop信号后总线处于idle状态(SCL和SDA均为高)。执行Section 2的代码得到的波形如下Figure 3所示,ACK(0)信号在第9个pluse脉冲上升沿被push总线上,说明后面还有数据要传输,一直处于等待MMA8451数据的再次传送中,这明显违背了读取单字节数据的原本意图。总之,KL的I2C应用中Section 1的代码操作顺序是正确的,实际的物理时序和 Figure 1的示意图时序是不一样的,这点需要特别注意。 Figure 1. MMA8451's 单周期读时序示意图 Figuire 2. Section 1 代码对应的时序 Figure 3. Section 2 代码对应的时序 为方便大家验证这些问题,我这里在附件中一并上传了K60的I2C的示例代码,KL25的示例代码,以及Kinetis L关于I2C的Errata。 —————————————————————————————————————————————————————————————————————— English Version:      Recently, I migrate the K60’s I2C demo code to the KL25, but found it can't works when the same demo code runs on FRDM-KL25Z board while it runs well on the K60 board. After a painful struggling, I finally get the cause, so here I make a record, wish it could be helpful when other users happen to meet same problem. Repeat start can't be generated when configure I2Cx_F[MULT] to non-zero      The K60’s demo( the attached 1) is to communicate with the onboard accelerometer MMA8451 by I2C, and in the demo it finish a data transmission by quering I2C’s flag bit. With almost same code, it always stops at below Function 1's red line i2c_wait(I2C0_B), also this function's defination is shown as below Function 2, it stops at while((p->S & I2C_S_IICIF_MASK)==0) to wait IICIF flag. Function 1. u8 hal_dev_mma8451_read_reg(u8 addr) {     u8 result;     i2c_start(I2C0_B);     i2c_write_byte(I2C0_B, I2C_ADDR_MMA8451 | I2C_WRITE);     i2c_wait(I2C0_B);     i2c_get_ack(I2C0_B);     i2c_write_byte(I2C0_B, addr);    i2c_wait(I2C0_B);     i2c_get_ack(I2C0_B);     i2c_repeated_start(I2C0_B);     i2c_write_byte(I2C0_B, I2C_ADDR_MMA8451 | I2C_READ);     i2c_wait(I2C0_B);     i2c_get_ack(I2C0_B);     i2c_set_rx_mode(I2C0_B);     i2c_give_nack(I2C0_B);     result = i2c_read_byte(I2C0_B);     i2c_wait(I2C0_B);     i2c_stop(I2C0_B);     result = i2c_read_byte(I2C0_B);     pause();     return result; } Function 2. void i2c_wait(I2C_MemMapPtr p) {     while((p->S & I2C_S_IICIF_MASK)==0)  ; // wait flag     p->S |= I2C_S_IICIF_MASK;    // clear flag }      Then what's the matter? when I capture the I2C's wave form, found it didn't generate a Repeat start signal when excute i2c_repeated_start(I2C0_B);  After a struggle, In the Kinetis L's Errata do I find the answer: Repeat start cannot be generated if the I2Cx_F[MULT] field is set to a non-zero value. That means there is a bug in KL's design, if the I2Cx_F[MULT] field is set to a non-zero value, the I2C master can't generate a Repeat start signal. Coincidentally, in the I2C_init function I happen to set theI2Cx_F[MULT]=01, so it just meets the I2C's Errata.      Considering the MULT bits define the multiplier factor mul. and  used along with the SCL divider to generate the I2C baud rate. In the Errata, FSL gives two possible workarounds: 1) Configure I2Cx_F[MULT] to zero if a repeat start has to be generated. 2) Temporarily set I2Cx_F [MULT] to zero immediately before setting the Repeat START bit in the I2C C1 register (I2Cx_C1[RSTA]=1) and restore the I2Cx_F [MULT] field to the original value after the repeated start has occurred. To verify it easily, I revise the I2Cx_F[MULT] from 01 to 00. After that the same code runs well on FRDM-KL25Z board.    2. The Timing Sequence Of I2C's single byte Reading      In the above Function 1, there are a MMA8451 data read section like below after  Write Device Address->Write Register Address->Repeat Start->Write Device Address, and these steps is same as MMA8451's single byte read Timing Sequence requirment which is shown as below Figure 1. But referring to Figure 1, it looks like Section2 we should first excute below line2 to read the data, and then line1 give a nack  to suggest it's the last data, at last excute line4 to send a I2C stop signal. But unfortunately the idea is wrong, because in the phasical timing sequence the No acknowledge signal is sent to the bus after the following receiving data byte (if FACK is cleared) ,which means we need to give NACK signal before a read. And the captured wave form is like below Figure 2, you can find the NACK in the Ninth pluse, while the captured wave form is like below Figure 3 if excute Section 2 code instesd of Section 1 code, you can find the ACK in the Ninth pluse. it means the master will read another data, but the original intention is to read only one byte, so the I2C bus blocks. In a word, the section 1 code is right, the physical timing is different from the Figure 1's sketch map. Section 1.     i2c_set_rx_mode(I2C0_B);     i2c_give_nack(I2C0_B);----line1     result = i2c_read_byte(I2C0_B);----line2     i2c_wait(I2C0_B);----line3     i2c_stop(I2C0_B);----line4     result = i2c_read_byte(I2C0_B);----line5 Section 2.    i2c_set_rx_mode(I2C0_B);    result = i2c_read_byte(I2C0_B);-    i2c_wait(I2C0_B);    i2c_give_nack(I2C0_B);-    i2c_stop(I2C0_B); Figure 1. MMA8451's single byte read Timing sketch map Figuire 2. Section 1 code's Timing Figure 3. Section 2 code's Timing
View full article
浙江地区去年下半年开始到现在,在一些电机控制客户中推广KE02,主要是低功率风机,BLDC,交流异步电机等。 总结了一些KE02在做电机控制方面的不足。 增加一点: (1) KE02 FTM PWM输出与NMI Pin 复用,上电容易烧管子
View full article
The TWR-KW2x board's OpenSDA is programmed with MSD (Mass Storage Device) application, that's why you see it listed as a disk drive. With that firmware, you can drag/drop .bin and .srec files to the board and that would flash it, but you won't be able to debug. For the boards to support download/debug features, the firmware for the OpenSDA had to be the Debug App ("DEBUG-APP_Pemicro_v108.SDA"). But PEMicro released a new firmware which supports BOTH functionality in the same firmware. You can also find it latest OpenSDA firmware at https://www.pemicro.com/opensda/ For example: Firmware that supports Debug and MSD functionality for TWR-KW24D512: "MSD-DEBUG-TWR-MKW24D512_Pemicro_v114.SDA". You can find attached the document with the instructions to modify the OpenSDA firmware on the TWR boards, basically you have to: 1. Unplug the board 2. Insert a Jumper in J30 to put the device in Bootloader mode 3. Plug in the board (Mini-USB) 4. Device will be enumerated as a "Drive Disk" But now with a "Bootloader" label 5. Drag and Drop the .SDA firmware to the drive (MSD-DEBUG-TWR-MKW24D512_Pemicro_v114.SDA) 6. Unplug the board 7. Remove Jumper 8. Plug in the board (Mini-USB) Now you should see the board being enumerated as "OpenSDA - CDC Serial Port" (allowing you to download/debug) and also listed as a disk drive(allowing you to drag/drop images to the board). Note1: If the "OpenSDA - CDC Serial Port" driver is not recognized, you can locate the driver within the TWR's Disk Drive (MSD) Note2: Jumper has to be in place in J29 for debugging Hope this info is helpful. You can find additional information on www.freescale.com/TWR-KW2x  --> Downloads -> Board Support Package  AND BeeKit Wireless Connectivity Toolkit
View full article
This is a copy of the currently posted KL26 reference manual to be used to enter community comments.  Please feel free to add inline comments in this reference manual. You can point out where more information is needed or where existing information is incorrect.  You can also enter information in your comment that expands on existing information in the document, based on your experience with the device.  If you are pointing out that more information is needed in a paragraph or a section, please be very specific, not “needs more information”.  Your comments in this manual may help other members and will drive improvements in this and future documentation. Note: The doc viewer does not support going directly to a specified page.  Instead of manually paging through one page at a time, you can do a search on a string on a page such as "types of resets", or you can go to chapter links listed in the inline comments.  To do this, page down to the comments below the doc view, select "Inline Comments", sort the comments by "page", and then select the chapter you want to view.
View full article
DFU_PC_demo_source_code.zip
View full article
Kinetis Programming using PE multilink Connect All the VDD to +3.3V and all VSS to GND. Connect 10K pullup resistor to RESET_b pin of the controller. If the controller have the option of JTAG/SWD/EZport make sure to connect 10K pullup resistor to NMI_b or EZP_CS_b pin. NMI_b pins selects the interrupt to highest priority so the controller won't enter into programming mode and EZP_CS_b pin is used for selecting Ezport programming method.   At factory reset condition, all the controller is in the continuous watchdog enabled mode and constantly resetting and the voltage level on the reset pin will be approx 1.64V after adding the pullup resistor as mentioned in point 2. Do not add any filter capacitor on the reset pin while programming the controller for the first time. As it will not let the logic level go low while programming. Which is essential. On probing the reset pin to the oscilloscope the following will be the pattern Before programming we need to mass erase the controller otherwise it will be in continuous reset mode. And to do that we need to configure SWD/JTAG mode. The following configurations for K20P48 LQFP in SWD mode. For mass erase following steps we need to follow. Search for thunderbolt icon in code warrior ie flash programmer and click on the drop-down menu on the icon.     Click on edit then      After configuring the above settings then click on the erase whole device option shown on step 9. If the microcontroller have JTAG/SWD and EZPORT then connect the microcontroller to JTAG port using PORT B of multilink with 20 pin headder. Try avoiding jumpers instead connect the 20 pin cable provided with PE multilink programmer. As all GND pins need to be connected on board's GND.   If the problem still persist then refer to this link Freescale community programmer
View full article
我们知道Kinetis L系列的中断向量表中只支持两个外部中断向量(vector_46 and vector_47),而FSL早期推出的的KL系列(包括KL25\KL24、KL15\KL14)只有PORTA和PORTD两个IO口支持中断,不过最新推出的KLx6系列(KL26、KL16和KL46)可以支持PORTA、PORTC和PORTD三个IO口的外部中断,其中PORTC和PORTD这两个IO端口共享同一个中断向量,另外,KL0x系列(包括KL02、KL04和L05)由于外部引脚只有PORTA和PORTB两个IO端口,所以它所支持的外部中断只有PORTA和PORTB。 下图分别为KLx5\KLx4系列(不包括KL05\KL04)、KLx6系列和KL05\KL04\KL02的外部中断向量分配表: KLx5\KLx4: KLx6: KL0x: KLx6的头文件注释: 最后需要注意的是,目前所有官方的demo例程(KLxx_SC)的中断向量表vector.h和MKLxxxx.h文件中关于中断向量的注释仍然是PORTA和PORTD,甚至有一部分例程中中断向量表的注释仍然是M4的注释直接移过来的,容易误导客户编程,这点需要在设计PCB板的时候有所考虑。
View full article
        在我们嵌入式工程应用中,中断作为最常用的异步手段是必不可少的,而且在一个应用程序中,一个中断往往是不够用的,多个中断混合使用甚至多级中断嵌套也经常会使用到,而这样就涉及到一个中断优先级的问题。         以我们最熟悉的Cortex-M系列为例,我们知道ARM从Cortex-M系列开始引入了NVIC的概念(Nested Vectors Interrupts Controller),即嵌套向量中断控制器,以它为核心通过一张中断向量表来控制系统中断功能,NVIC可以提供以下几个功能: 1)可嵌套中断支持; 2)向量中断支持; 3)动态优先级调整支持; 4)中断可屏蔽。         抛开其他不谈,这里我们只说说中断优先级的问题。我们知道NVIC的核心工作原理即是对一张中断向量表的维护上,其中M4最多支持240+16个中断向量,M0+则最多支持32+16个中断向量,而这些中断向量默认的优先级则是向量号越小的优先级越高,即从小到大,优先级是递减的。但是我们肯定不会满足于默认的状态(人往往不满足于约束,换句俗话说就是不喜欢按套路出牌,呵呵),而NVIC则恰恰提供了这种灵活性,即支持动态优先级调整,无论是M0+还是M4除了3个中断向量之外(复位、NMI和HardFault,他们的中断优先级为负数,它们3个的优先级是最高的且不可更改),其他中断向量都是可以动态调整的。         不过需要注意的是,中断向量表的前16个为内核级中断,之后的为外部中断,而内核级中断和外部中断的优先级则是由两套不同的寄存器组来控制的,其中内核级中断由SCB_SHPRx寄存器来控制(M0+为SCB_SHPR[2:3],M4为SCB_SHPR[1:3]),外部中断则由NVIC_IPRx来控制(M0+为NVIC_IPR[0:7],M4为NVIC_IPR[0:59]),如下图所示: M0+中断优先级寄存器: M4中断优先级寄存器:         其中M4所支持的动态优先级范围为0~15(8位中只有高四位[7:4]才有效),而M0+所支持的动态优先级范围则为0~3(8位中只有高两位[7:6]才有效),而且秉承着号越小优先级越高的原则(0最高,15或3为最小),同时也间接解释了为什么复位(-3)、NMI(-2)和HardFault(-1)优先级最高的原因,很简单,人家都是负的了,谁还能比他们高,呵呵,而且这三位中复位优先级最高,NMI其次,HardFault最低(这个最低仅限于这三者)。 下面给出个ARM CMSIS库中关于M0+和M4中断优先级设置的API函数NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)实现供大家来参考: M0+: NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) {   if(IRQn < 0) {     SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |         (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }  /* set Priority for Cortex-M  System Interrupts */   else {     NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |         (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }   /* set Priority for device specific Interrupts  */ } M4: void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) {   if(IRQn < 0) {     SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M  System Interrupts */   else {     NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff);    }        /* set Priority for device specific Interrupts  */ }
View full article
    不得不说Keil貌似是国内用户使用最多的IDE了,其被ARM收购之后,ARM嵌入了ARMCC等编译器推出了Keil MDK开发环境更是受到了广大ARM开发工程师的欢迎,庞大的用户群(很多是从当年的51等8位机直接转过来的)、简洁的管理窗口和友好的UI界面等优势都让其风靡一时,而且毕竟现在成了ARM的“亲儿子”了,其对ARM内核的产品支持还是灰常不错的。     而GCC更是大名鼎鼎,这个至今仍然在维护的GNU项目下的产物,在N多大牛的维护下不断得到优化,其强大的编译效率和跨平台能力也是广为大家所认可(Codewarrior10.x之后,针对ARM的编译器就是集成了GCC)。     而本文的目的是针对那些想从GCC平台迁移到Keil MDK平台的开发者(并不是代表ARMCC比GCC好,这里不拿这两者做对比),可能用习惯了GCC的话移植到ARMCC下会有些差别需要注意,如匿名的联合体union在ARMCC下是不支持的,要想再ARMCC下使用需要在前面添加“#pragma anon_unions”,而这种格式在GCC却是直接支持的。     而如果开发者想将原来在GCC下的工程整体迁移到Kei MDK下,如果工程里存在大量的这种定义,那人为的一条条修改绝对是一件让人抓破头皮的事,呵呵,那有没有简单的一蹴而就的方法呢?咳咳,我都这样说了那肯定就有啦,有点卖关子了,呵呵,其实很简单,我们进入到Project->Options…,设置如下图所示,即添加“--gnu”即可实现在Keil工程下使用GNU工具链GCC来编译工程C文件了,是不是有点太简单了,呵呵。     当然最后我需要提一句,这个“--gnu”是添加在C/C++这个选项卡下的,如果你最开始使用Keil重新新建的一个工程并添加了Keil自动生成的启动代码的话(startup_xxx.s)请慎用在ASM选项卡下添加“--gnu”,因为ARMCC下的汇编格式是与GCC完全不一样的,所以用GCC来编译Keil下生成的汇编是不行的,这点需要注意。
View full article
There is new amazing feature in FreeMaster ver 1.4 ( www.freescale.com/freemaster ) - you can do the debugging and visualization of your application in FreeMASTER without adding any code in there (you do not need a serial driver of any kind to achieve the connection), just using the communication plug-in to OSDA embedded in new version of Freemaster connected instead of the debugger from IDE. The driverless use of Freemaster use is easy to use, just open the FreeMaster, assuming you have your own application, without any Freemaster driver in it. Load the application into flash memory of the KL device and close debugging session from IDE. Open FreeMaster and  go to Project/Options/Comm, use setup from picture below Choose Plug-in - use the FreeMASTER BDM Communication Plug-in, hit configure and take P&E Kinetis. you can test the connection there too. The next step is to go to Options/MAP files, navigate to *.ELF file of your project and set file format to ELF/DWARF (I have chosen .elf from some usb demo project just to show the way how to do so) well, the connection is established, now there is need to choose variables for display and visualization. Go to project/Variables and choose variables you want to follow (hit Generate.. to do so, list of variables available in your project will appear and you can choose the desired one and hit generate - it will check and generate the variable connection, you can do it for single variable, array or more variables - it is intuitive ) When desired variables are generated, close the dialog. You can make a scope or add variables to watch. To add variable to variable watch window click by right mouse button in watch area go to watch properties, Watch tab and hit Add---->> to add it between watched wariables and hit OK and value appears in the Variable Watch window. To create scope, go to project tree window and use right mouse button on NewProject, choose Create Scope... In scope properties chose the name for this scope and go to  Setup tab. You can add your variable to the scope here by choosing in drop down menu Hit OK and start the session (Ctrl+K) or hitting Stop icon in the menu, the variable is displayed in the window. The value in my case stays 0 however displays correctly... Pavel
View full article
本文分享自China-FAE Team,谢谢同事的sharing! MQX如何自适应10/100Mbps网络          Kinetis K60 媒体接入控制器MAC(Media Access Layer)实现了数据链路层,同时支持10Mbps和100Mbps两种速率。MAC通过MII/RMII接口与PHY芯片连接。         现有的MQX4.0 RTCS协议栈在K60  Tower System Board无法支持与10Mbps交换机等网络设备通信。问题的原因是MQX4.0 BSP初始化代码macnet_init.c默认将MAC配置为100Mbps/Full Duplex模式。     MQX4.0 BSP针对TWR-SER所使用的PHY芯片(KSZ8041NL)的初始化代码没有考虑用户指定链路速率的情况,仅由PHY做默认设置。为了能够自适应链路速率,不仅需要设置KSZ8041NL的控制寄存器(0.13 Speed Select、0.8 Duplex Mode),还要设置K60的ENET_RCR/ENET_TCR寄存器。 解决办法: 修改MQX4.0 BSP代码,使能PHY芯片与网络设备端进行链路速率自动协商,然后读取PHY协议好的链路速率,通过这个链路速率设置MAC的相关寄存器ENET_RCR/ENET_TCR。MQX4.0的 PHY的接口函数已经提供了speed和duplex函数,可供MAC初始化调用,可以保证系统代码的可移植性。 测试结果: 修改后的MQX4.0 BSP代码能够自适应10/100Mbps网络,网络通信正常。
View full article
分享自China-FAE team同事,在此谢过! 有客户需要bootloader功能,于是从网上下到最新版本的AN2295,发现里面添加了很多的内容,包括支持了很多新的器件,比如KM系列,但是真正把它在板子上跑起来,却花了2天时间,为了减少大家工作量,不在重蹈覆辙,我在这里share给大家,目前该代码在FRDM_KL25以及TWR-K60D100M上跑起来了。遇到的问题主要有如下几点: 问题1: 在工程中使用除法命令: a =a /100; 会报错: Error[Li005]: no definition for "__aeabi_uidiv" [referenced from D:\Customer\XinRuiYang\an2295sw_Kl25\src\Kinetis\IAR_6_4\Kinetis L Debug\Obj\bootloader.o] 原因是: 这里Lib选择的是None,说明没有使用任何库,所以不能使用除法。 打开库后,可能会占用比较大的空间,所以不推荐使用。 问题2: FRDM_KL25使用默认代码频率,波特率有问题,发送data = 0但是实际发送值为0x80,通过更改主频为48M,然后分频解决。附件有参考代码。TWR-K60100DM没有此问题。 问题3: FRDM_KL25板子,如果不使能BOOTLOADER_AUTO_TRIMMING这个宏,即不调用SlaveFrequencyCalibration();函数时, 代码上电不能直接运行,而使能该函数后,会一直进行校准频率,上位机无法通讯,查找代码发现: 上版代码为         #if BOOTLOADER_AUTO_TRIMMING == 1                       if(UART_GetChar() != BOOT_CMD_ACK)              {                SlaveFrequencyCalibration();              }                                        #endif 本版代码为:         #if BOOTLOADER_AUTO_TRIMMING == 1                         SlaveFrequencyCalibration();                     #endif 修改为上版代码,可以正常运行并跑起来。 但是不使能BOOTLOADER_AUTO_TRIMMING这个宏,代码依旧跑不起来,现象就是仿真时没有问题,可以正常跑起来,但是如果是上电直接运行,就不能正常通讯: 这个问题出在了USB插拔瞬间,KL25会收到一个数据,该数据并不是上位机下发的FC码,如果不使能BOOTLOADER_AUTO_TRIMMING这个宏,代码会误认为自己进入 等待上位机下发数据的状态机,导致通讯错误。在SlaveFrequencyCalibration(); 函数中,有软件复位功能,会让插拔稳定后KL25不在接收到异常数据,以此保证状态机的正确。 问题4: 仿真时全速跑起来时,指针经常回到__main,说明波特率有问题,代码进入SlaveFrequencyCalibration中,复位了。 AN2295引导MQX Keil工程 AN2295的文档已经说明如何修改CW IAR的工程以便让Bootlaoder引导,但是没有Keil工程的说明,这个就只能自己动手啦。 首先肯定会想到修改scf文件: #define USERFLASH_BASE_ADDR    0x00060000 #define INTFLASH_BASE_ADDR     0x00000000 #define INTFLASH_SIZE          (USERFLASH_BASE_ADDR - INTFLASH_BASE_ADDR) #define MY_ALIGN(address, alignment) ((address + (alignment-1)) AND ~(alignment-1)) LOAD_REGION_INTFLASH INTFLASH_BASE_ADDR INTFLASH_SIZE {     VECTORS INTFLASH_BASE_ADDR     {         vectors.o (.vectors_rom,+FIRST)         vectors.o (.cfmconfig)     }     CODE +0     {         * (InRoot$$Sections)      ; All library sections for example, __main.o,                                   ; __scatter*.o, __dc*.o, and * Region$$Table         * (KERNEL)         * (TEXT)         * (+RO)     }     RAM_VECTORS 0x1FFF0000 ; For ram vector table. Used when  MQX_ROM_VECTORS is set to zero.     {         vectors.o (.vectors_ram)     }     NOUSER +0     {         * (.nouser)     }     ROUSER MY_ALIGN(ImageLimit(NOUSER), 32)     {         * (.rouser)     }     RWUSER MY_ALIGN(ImageLimit(ROUSER), 32)     {         * (.rwuser)     }     DATA MY_ALIGN(ImageLimit(RWUSER), 32)     {         * (+RW)         * (+ZI)     }     USB_BDT MY_ALIGN(ImageLimit(DATA), 512)     {         * (.usb_bdt)     }     KERNEL_DATA_START MY_ALIGN(ImageLimit(USB_BDT), 0x10)     {         * (KERNEL_DATA_START)     ; start of kernel data     }     KERNEL_DATA_END 0x2000FFF0      ; RAM_END     {         * (KERNEL_DATA_END)     ; end of kernel data     }     ; mem_init writes a storeblock_struct at the end of kernel data,     ; max size 32 bytes, so use 0x100 offset     BOOT_STACK_ADDR 0x2000FEF0     {         * (BOOT_STACK)     } } 都是按偏移算的,应该只改INTFLASH_BASE_ADDR     0x00004000就O了,找了个最简单的工程:mqx\examples\hello,编译生成S19文件,通过bootloader下载进片子, 按reset后看屏幕,始终木有出现hello world,没办法,只能上debug了。 打开AN2295工程,加载调试环境,然后在JumpToUserApplication函数上下断点,中断后,单步执行到在__asm("mov pc, r1"); 函数,继续在汇编窗口点单步执行,之后就完全跟crack有点类似,一直点,直到芯片复位,说明之前点那一下是key point,然后对照map文件,于是找到了复位点: init_hardware->_bsp_initialize_hardware->_bsp_watchdog_disable();执行后会复位 不管啦,直接把它屏蔽掉,反正之前就已经关闭看门狗了。 重新编译,继续上。 还是没看到期待已久的hello world,肿么办? 重复上面的方法,发现又一个key point: _sched_start_internal 查看代码发现,这是一个系统call,应该是从vector 11调用的,查看下寄存器: SCB_VTOR 肿么变成0了,bootloader中已经改成0x4000了,什么时候变成0了....... 代码太多了,不知道从哪儿看起,内存断点是个好东西哈,IAR中没找见在哪儿下,算了,换Keil吧。 用Keil打开AN2295工程,加载调试,然后在0xE000ED08(SCB_VTOR )下写断点,直接run,等待中断吧: _time_set_timer_vector函数修改了SCB_VTOR, 大概路径是_bsp_enable_card->BSP_INTERRUPT_VECTOR_TABLE->BSP_TIMER_INTERRUPT_VECTOR 哈哈,找代码看看: __VECTOR_TABLE_ROM_START 是这个宏搞的鬼。 仔细对比代码,发现__VECTOR_TABLE_ROM_START 这个宏是通过条件编译区分开的,IAR是通过icf文件定义的 而Keil是通过#define 来实现的。好了,修改对应的值为0x4000,重新编译,下载,搞定,可以看到hello world喽。 总结一下,使用AN2295引导MQX Keil工程需要做以下3点修改: 1.scf文件INTFLASH_BASE_ADDR     0x00000000改为0x00004000 2.屏蔽_bsp_watchdog_disable()该函数 3.修改__VECTOR_TABLE_ROM_START为0x00004000.
View full article
最近有客户问到如何移植PE生成的TSI代码到IAR中,按照常规的方法在把头文件和库文件意义一一包含进来,非常繁琐,于是研究了一下相关的操作。在早期的IAR版本中,需要用户自己手动添加芯片名称,链接文件和包含的路径信息,特别是在PE增加或者删除组件后,需要用户去增减相应的文件,更增加了难度。而在最新版本的 IAR 6.7中集成了对PE工程的链接机制,它可以方便的读取PE工程的XML文件,从而实现移植PE生成的代码到 IAR Embedded Workbench中,相对于早期的IAR版本,主要完成以下几个工作: 自动检测使用的芯片类型; 自动添加PE的LCF连接配置文件; 自动更新包含的头文件路径; PE增加或者删除Component组件后,IAR工程会自动Add 或Delete 相应的组件代码; 尽管IAR完成了一些繁琐的工作,但网上没有太多的资源可以参考,对于首次使用的用户来说还是需要一些探索,为节省大家的时间,下面以一个具体的示例Step By Step的介绍如何在IAR中集成PE的工程。 1. 打开Processor Expert software 新建一个PE的工程并保存生成代码,这个过程比较简单,此处不再赘述,重点讲述一下在IAR中的使用步骤; 2. 在IAR Workbench中"Creat New Project"新建一个空的工程。 3. 保存新建的工程文件到PE工程的文件夹中,需要注意的是此处也可以选择其他路径,但为简便和易维护性上还是建议直接存放到PE工程中。 4. 打开Tools->Options->Project选项,勾选“Enable project connects”,这个选项的目的在于使能 IAR 能够读取Freescale Processor Expert和Infineon DAVE等第三方工具生成.XML文件。 5. 添加PE工程的XML文件,选择Project->Add Project Connection,会弹出链接选择对话框,选择使用Freescale Processor Expert,默认是IAR Project Connection; 6. 点击OK后,选择建立PE工程时生成的工程描述符文件Projectinfo.xml; 7. 完成上面步骤后,在IAR中自动完成以下三方面工作:自动加载PE生成的文件到IAR中,自动安装LCF链接配置文件,自动包含头文件路径。这几个步骤在之前版本的IAR中需要自己手动添加,并且当在PE中重新生成Code时需要重新添加对应的文件; 8. 完成上面步骤之后,需要根据实际情况配置采用的下载/调试器,Project->Options->Debugger->Setup 选择下载Driver,实验中使用的是KL25的FRDM板,所以在PE Macro中选择OpenSDA,点击OK,完成设置; 9. 编译工程,下载Debug; 总结下来,主要完成两个工作:(1)配置使能 Project connection,并导入PE生成的XML文件; (2)配置调试的下载器仿真器;
View full article
¡ FELICIDADES AL GANADOR! El sábado 7 de diciembre se realizó la final del Kinetis L MCU Challenge México en las instalaciones del Centro de Congresos, Tecnológico de Monterrey Campus Guadalajara; donde se eligió al ganador a través de las redes sociales y la herramienta RankTab. La emoción se sintió entre los participantes durante la votación; al finalizar el conteo de votos y calificaciones en Ranktab ¡obtuvimos un ganador! Nos complace presentar a: Andrés Gafford con el proyecto Tablet Braille para Invidentes como el ganador del Kinetis L MCU Challenge México 2013. Quién se irá de viaje con todos los gastos pagados al Freescale Technology Forum (FTF) en Dallas, Texas del 8 al 11 de abril del 2014. Agradecemos a los finalistas por su esfuerzo y participación en el evento;  también agradecemos a todas las personas que nos ayudaron con su calificación y voto a elegir el mejor de los proyectos. Esperamos que esta competencia haya sido un semillero de grandes ideas que se conviertan en las innovaciones del mañana.
View full article