Everything you always wanted to know about Eclipse, Embedded Systems Programming, Software and Tools, or any topics of this blog, but where afraid to ask, then this page is for you.

Post a comment, and you might get an answer, either from myself or from the readers of this blog. Otherwise: the answer is always ‘42‘ 😉

For feature requests or bug reports on the McuOnEclipse project end Processor Expert components, you should use the GitHub issue tracking system:


726 thoughts on “Q&A

  1. Hi Erich,
    I need to implement a control loop to control pressure in a chamber. Also separate loop to just control the temperature of a heater.
    I thought that using your PID components would allow this, but I noticed the PID_integer wanted to add motor and quadrature stuff which isn’t needed.
    I tried the PID_float component, but I don’t really know how to use it, I could maybe make some good guesses, but is there an example somewhere? Or documentation?

    Many Thanks,


  2. Hi Erich,
    Another question – I have 5 I2C devices on one bus, and from time to time that bus can get locked up (SDA remains low). Is there a way to reset the bus to get it going again? I’ve had to power cycle my board sometimes to get rid of the lockup, other times just resetting the software works. Using the GI2C component wrapping the CI2C kenitis component (on my K22fn512 board)

    It was working really well for a while, when I noticed my SPI interrupt was not updating the SPI peripheral at 1000Hz. I fixed that, and now the I2C (which is much slower and I have seen the SPI transactions which share no pins come in the middle of the I2C transaction) is locking up much more often.


    • Hi Brynn,
      do you know who pulls the SDA low? If one of the devices does that, there is not much you can do about it.
      You can try to unlock it with a repeated sequence of data (see https://mcuoneclipse.com/2013/12/08/bit-banging-i2c-with-resetbus-functionality/), but I have this available only in the bit banging version of the driver.
      What I have done in the past to overcome such situations is to power down/up the I2C device(s) with a FET.


      • The earlier version of the board had FETs controlling the power of 3 of the 5 I2C devices (Because they all came at the same address), When any of those three were powered down they dragged both SDA and SCL low so I couldn’t use that to enable/disable them individually – so I removed the feature from the next board. Which is too bad because I cannot power cycle them with software anymore. Though it could well be one of the other two devices that are the culprits.



  3. Hi Erich
    I am trying to implement a USB CDC host on KL25Z and having lots of problems do it. I am trying to use MQX-Lite.

    case 1:
    I created a project, changed the clock, added consoleIO, and FSL_USB_CDC_Host. Generated the code and then compiled.
    I get errors in the generated code.

    case 2:
    Same as above except the I used the FSL_USB_Stack component and then selected a CDC host. When I compile it, I get errors in the MQXLITE directory.

    Any suggestions as to what is wrong.


    • Hi Eli,
      I have not used MQX (or MQXLite) for a very long time, so I cannot really help on that. I would use FreeRTOS instead. The FSL_USB_Stack is not compatible with MQX, and probably never will be.


  4. Hi Erich
    I am wondering if you have noticed this:
    I created an application where I added the following components:
    -FSL_USB_Stack – setup as a USB CDC device
    The only thing the application does is a printf to the console.
    This works fine.

    I than disabled the CDC device and enabled the CDC host.
    Now the printf does not work.

    I did notice that the CDC sub-component changed from CDC1 to CDC2.


  5. Hi Erich

    I am working with KDS 3.2.0 and the K64F board.
    Two items:
    1-When I add the RingBuffer component from the 2016-10-30 release everything is OK
    When I use the 2016-12-12 release there is a problem with CS1 component.
    Are you aware of this.
    2- I want to use UART1 to communicate with a RS232 printer. If I don’t use flow control I get some bad characters printed. When I enable flow control it does not work at all.
    Any suggestions.


  6. Hi Erich,
    On my I2C problems, I switched from the kinetis CI2C component to the genericSWI2C component and all My I2C problems went away. I don’t even have to use the ‘ResetBus’ function which was why I switched to the software solution in the first place!

    Today I just made a bunch of changes to my code, and now the KDS V3.2 is giving me phantom compile errors – the error message is telling me that there is an undefined reference to a variable that existed in a previous version of the code, but is no longer used and has been completely deleted. I double click on the error and it puts me on a line of code that is completely different than the error it claims. It is approximately where the old variable existed in the code.

    No amount of ‘clean’ or deleting the debug and generated code directories help.

    Any ideas how to fix this bug??



    • Hi Brynn,
      Well, my first thought would have been to do a ‘clean’ or delete the ‘debug’ folder. But as you already did this, not sure what else it could be. If it is a undefined reference, it means that the code is using that variable, but it is not defined somewhere. But what sometimes happens is that Eclipse ‘keeps’ the errors listed in the ‘Problems’ view. Check the console view output if the error report is real. You can delete/remove the errors from the ‘Problems’ view (context menu and delete them all or individually).
      I hope this helps,


      • Hi Erich,
        Apparently there were still instances of the not entirely deleted variables elsewhere in the file, and now that I deleted them it compiles again. (but it was still pointing to the wrong places when listed in the problem window).



  7. Hi Erich,
    New question – I am using the USB CDC as a debug port and am displaying lots of stuff.
    I changed my code over to using a text frame buffer that I update with values and colors, and then only send a big serial stream of the stuff that changed. (It uses ansi esc sequences to change the colors and position the cursor, and I have a ‘dirty’ bit in the frame buffer that gets set whenever I write new info to the frame buffer)

    It actually works real good – except two things – both having to do with the CLS shell component.
    The first I am sure I can fix so I won’t go into it…
    The second is that after I start typing a ‘command’ to the shell, the other tasks come nearly to a complete stop, and stay sloooow until I hit the ‘return’ to end the command.
    Any suggestions on how to best fix this?



    • Hi Brynn,
      I have not observed such a slow thing with the shell. Which terminal application are you using? What happens in the shell is that it checks if there are any incoming characters and appends it to a buffer. It uses a function to find out if there is anything available, then gets the character. Maybe something is wrong with this: with your changes it thinks that there is a character, but then when it tries to get it, it runs into a timeout?


      • I just started typing a command now and see that the other tasks have gone slow (like 50x slowdown) but not stopped.
        I hit the ‘pause’ to break where the code is now, and the call stack is:
        CDC1_RecvChar() …
        CDC1_StdIOReadChar() …

        CDC1_RecvChar() is
        while(Rx1_Get(Chr)!=ERR_OK) {}
        and that’s where it is spending 99% of the time

        Instead of that empty while loop I just tried adding a vTaskDelay(1); inside that loop, and it makes my code not slow perceptibly

        Except now that is in generated code and will get overwritten when PEX generates components.

        Did I fix this the right way?



      • Hi Brynn,
        interesting, I think I see now the problem you describe. Not sure why I have not observed this on my side. Indeed, it should not block that way. I have added timeouts and waiting for the sending, but not for receiving characters. Your fix is basically correct. I need to think this through, a better way would be not to block or to provide a flexible way dealing with this.
        My current thinking is that CDC1_StdIOReadChar() should call Rx1_Get() and not CDC1_RecvChar().


      • Instead of that empty while loop I just tried adding a vTaskDelay(1); inside that loop, and it makes my code not slow perceptibly

        Actually not true, it is slowed by a factor of 2 or 3, but that is way better than 50x



      • Hi Brynn,
        I looked closer at what you describe. And my finding is that it should not block like you describe? CLS1_ReadAndParseWithCommandTable() calls CLS1_ReadLine() which first calls io->keyPressed(). This calls CLS1_KeyPressed() which checks using USB1_GetCharsInRxBuf() if there are characters in the Rx buffer. If there are zero, it will not try to read from the Rx ring buffer.
        I don’t know what is happening on your end, as indeed it should not try to read if there is nothing in the buffer?
        That’s why I have not seen such a blocking issue on my side.
        I hope that makes sense, and I don’t know what I’m missing?


  8. Hi Erich,
    I also have the SeggerRTT component included, as I am using that to dump some logging data.
    I only want the shell responding to the USB commands.

    I do call
    (void)CLS1_ReadAndParseWithCommandTable(in_buffer, sizeof(in_buffer), &CDC1_stdio, CmdParserTable);

    with the CDC1_stdio struct ptr.



    • Hi Brynn,
      with (void)CLS1_ReadAndParseWithCommandTable(in_buffer, sizeof(in_buffer), &CDC1_stdio, CmdParserTable); it will use the USB CDC as input/output for the shell (UART) communication. You can have as many RTT channels on the side as you want.


      • Hi Erich,
        I’m still having problems with the CDC blocking. Again, everything is fine until I type the first character of a command. From then until I type a ‘return’, it loops on the code:
        CDC1_RecvChar() is
        while(Rx1_Get(Chr)!=ERR_OK) {}

        I tracked down that CLS1_KeyPressed() is a function that calls USB1_App_Task(…) which returns the number of chars that are in RX1 waiting to be read.

        This is driving me nuts, I think I need to write my own routine that gets my character input and then just calls CLS1_ParseWithCommandTable() to replace the ‘CLS1_ReadLine’ which is the root of what causes that while(Rx1_Get(Chr)!=ERR_OK) {} loop.

        Yes my ‘vTaskDelay’ that I added helps a bunch, but it is also in the generated code directory so it gets overwritten by PEX the next time I generate components – is there a way to change code that was generated by PEX and not have it get overwritten later?


  9. Hi Erich,
    A different dumb USB question – my code starts talking and sending screens to the USB as soon as the USB is plugged in. But it does that even before my terminal emulator is connected to the USB serial port.
    Is there a function that I can use to actually wait until there is a terminal emulator connection so I don’t send to a non-existent screen? This would also help out because right now my initial screen draws happen long before the terminal is hooked up, and I have to manually type a screen refresh command after it has been connected.

    I see a few likely function names (ApplicationStarted, TransactionsStarted) but I am not sure they or any other function will do what I want.



  10. Hello Erich,

    I have a bricked KL25Z Freedom Board which has the next versions:
    Board Name is: FRDM-KL25Z
    MicroBoot Kernel Version is: 1.01
    Bootloader Version is: 1.01
    Application Version is: 0.00

    I was watching your tutorial and trying to recover it.
    I know that you said it will not work on versions below V1.11: “only works if the bootloader of the board has been already updated to V111”. But i want to recover this little beast.

    Is there a way to recover this board?


    • First: it would make sense if you could post your question in that article (easier find for everyone else).
      About your problem: You will need a Windows 7 machine to update the bootloader first, see ‘Updating the bootloader’ in https://mcuoneclipse.com/2014/11/01/illustrated-step-by-step-instructions-updating-the-freescale-freedom-board-firmware/, there is no way around it. Check out the comments section for that article: Mark Butcher posted a hint (I was not able to try that one), but maybe with that one you can do it from a Windows 8.x machine too.
      Good luck!


      • Thank you Mr. Erich,

        I was able to fix my bricked board following your instructions.

        What i did: I just connected the board to a windows 7 PC and copied the last version of the SDA firmware for this board (MSD-DEBUG-FRDM-KL25Z_Pemicro_v118). After a reset, the board was up and running again.

        By the way, sorry about not commenting on the right post.


      • Hi Ivan,
        no worries about posting. In any case, I recommend that you update the bootloader too as outlined in the instructions, just in case. Having the new bootloader ensures that you can update the firmware from a Windows 8/10, Mac or Linux machine too.


  11. hi Eric, how do i toggle program flash protection on a mk22fn1m0vlh12

    i can see how to do it in PE or by using

    /* Flash configuration field */
    __attribute__ ((section (“.cfmconfig”))) const uint8_t _cfm[0x10] = {
    /* NV_BACKKEY3: KEY=0xFF */
    /* NV_BACKKEY2: KEY=0xFF */


    but how do i change the following field in my application:

    /* NV_FPROT3: PROT=0xFF */
    /* NV_FPROT2: PROT=0xFF */
    /* NV_FPROT1: PROT=0xFF */
    /* NV_FPROT0: PROT=0x7F */

    i tried
    NV_FPROT3 = 0xFF;
    NV_FPROT2 = 0xFF;
    NV_FPROT1 = 0xFF;
    NV_FPROT0 = 0x7F;

    but that causes hard fault. i can read from those however.

    thanks for help


  12. Hello, Erich!

    I have a sumo robot project in which I use two QTR-1RC digital sensors for detecting the border of the battle ring. I don’t know how to do the code for them. Can you please help me? I am using the FRDM-KL46z. Do I need a counter for using them?



  13. FRDM-KL24Z + IRDA

    Have you ever done any IRDA using the FlexIO of a KL2x processor.

    I have a FRDM-KL24Z board and can see a demo app for KSDK1.3.0 using a KL43Z.

    http://www.nxp.com/assets/documents/data/en/user-guides/KSDK13DEMOUG.pdf ( search for IRDA )

    I am unsuccessful getting the demo ported over to the FRDM board I have (24z), and have never done any FlexIO implementations yet.

    If you have had some experience in this or some suggestions, pointing me in the correct direction would be greatly appreciated.


  14. Hi Erich,
    I wrote my own character reading handler instead of calling CLS1_ReadandParseWithCommandTable. In it, I use the NON_Blocking function CDC1_GetChar() . Deep inside the CLS_R…. command above, it calls the blocking function CDC1_RecvChar(). This is what makes that command block. Now that I have my own nonblocking character handler, everything is great.



  15. Hi Erich,
    I am working a Virtual COM port with the USB port on MK20DX256, bare metal no RTOS.
    I have tried to use the USB CDC CLASS from PEx and USB stack from NXP. I have experienced the “not supported on selected processor” or the similar issue. I have tried KDS 3.2 and Eclipse V10.3. V10.6 with the PEx components from USB stack 4.1.1 , V4.03 and the FSL_USB_Stack from your website, but no luck at all. I also tried to port the example code from SDK 2.0 for MK20 but the debug is such a pain. I really hope that I can use the USB_CDC_CLASS with what ever version IDE from NXP. Any suggestions would be highly appreciated.

    Tony Wang


  16. Hi Erich,
    I have tried the 2nd link which is for KDS. After plug the USB onto computer with Windows 10, the computer installed the driver itself and the K20DX256VLL10 is shown as COM4. However, there is nothing shown on the terminal. The USB driver for this port is from Microsoft. I will take a further look tomorrow.
    If I plug the same USB at Windows XP or Vista, I will need to manually install the driver.Not sure what driver I should use.
    Thank you so much for the help. Also thanks for the new release of PEx component on March 12,2017. Without this new release, I don’t think I can make the progress so far.



  17. Hi Erich,
    Everything works well. I can get echoed text after send letter or string on the Virtual COM port.Thank you so much.


  18. Hello Erich,

    I am Rashed. I am presently struggling to get the camera (OV7670) work with OPen4X9I-C development board.

    I have been following the example code made by Mr. Jorge’s blog (http://embeddedprogrammer.blogspot.kr/2012/07/hacking-ov7670-camera-module-sccb-cheat.html)

    I have built and debugged the project on eclipse neon.2. But I am trapped in an infinite loop.

    The loop is ov7670 configuration. It is not able to read the camera. I changed and activated all the pheripherals, clock and arrangement. Checked them a lot of times.

    Can you please help me in this project? I am just trapped. I can also send you my project by email.

    Thank you so much for your time.



    • Hi Rashed,
      I don’t thinkn I have that camera around (I had a similar one), so hard to help you out here. What I suggest is to check the signal lines with a logic analyzer: do they make sense? Do you see the commands you send? Do you see the signals the camera is sending?


What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s