Q&A


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:

Advertisements

719 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,
    Brynn

    Like

  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.
    Brynn

    Like

    • 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.
      Erich

      Like

      • 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.

        Brynn

        Like

  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.
    Thanks
    Eli

    Like

    • 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.

      Like

  4. Hi Erich
    I am wondering if you have noticed this:
    I created an application where I added the following components:
    -WAIT
    -ConsolIO
    -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.

    Like

  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.

    Like

  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??

    Brynn

    Like

    • 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,
      Erich

      Like

      • 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).

        Thanks,
        Brynn

        Like

  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?

    Brynn

    Like

    • 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?
      Erich

      Like

      • 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:
        Rx1_Get()…
        CDC1_RecvChar() …
        CDC1_StdIOReadChar() …
        CLS1_ReadLine()…
        CLS1_ReadAndParseWithCommandTable()…

        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?

        Brynn

        Like

      • 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().

        Like

      • 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

        Brynn

        Like

      • 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?

        Like

  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.

    Brynn

    Like

    • 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.

      Like

      • 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?
        Brynn

        Like

  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.

    Brynn

    Like

  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?

    Like

    • 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!

      Like

      • 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.

        Like

      • 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.

        Like

  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 */
    0xFFU,
    /* NV_BACKKEY2: KEY=0xFF */

    etc

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

    /* NV_FPROT3: PROT=0xFF */
    0xFFU,
    /* NV_FPROT2: PROT=0xFF */
    0xFFU,
    /* NV_FPROT1: PROT=0xFF */
    0xFFU,
    /* 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
    dave

    Like

  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?

    Thanks.
    Alex

    Like

  13. FRDM-KL24Z + IRDA

    Erich,
    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.

    Like

  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.

    Brynn

    Like

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