FRDM-KL25Z board and buffered serial

08 Jul 2013

I am wondering whether anyone has been successful in getting any of the buffered serial libraries working on the FRDM-KL25Z platform?

I have found a number of libraries available, including MODSERIAL, BufferedSerial and SerialBuffered.

I originally looked at MODSERIAL, but this seems to have been written previous to mbed support for the Freedom board being released. Most recently I have been looking at the BufferedSerial example, from Sam Grove.

Any thoughts/suggestions would be greatly appreciated.

Thanks, Cameron

10 Jul 2013

I am due to this topic currently looking at porting MODSERIAL to KL25Z, and completely seperating the code in device dependent and independent code. Since MODSERIAL was purely designed for LPC devices that is a bit of work :).

10 Jul 2013

Hello Erik,

I would very much be interested in putting MODSERIAL through its paces once you are done with the port.

Since my initial post I have had some success with the SerialBufferedDemo example, from Richard Sewell. This example lacks much of the functionality found in MODSERIAL, but I am hopeful that it can be made to work in the interim.

Regards, Cameron

11 Jul 2013

Small update: After it went a bit slower than expected, bit faster, than bit slower again, it already is starting to do something. It runs the example1 file on both LPC1768 and KL25Z :P (last one not completely correct).

Currently the issue is that MODSERIAL enables the Serial interrupt once, and then enables/disables it on a register level, I guess that is quite a bit faster than doing it via the serial class. On the LPCs that works fine, since there the serial interrupt handler reads a register that tells which interrupt fired, and of course that can only be the ones not disabled by MODSERIAL.

Now the KL25Z doesn't have this register, it only has flags. One of them is for example the 'Transmit buffer has space' flag, which is used for the TX interrupt. Then if MODSERIAL disables TX interrupts, that flag will still be set when an RX interrupt comes in. Mbed serial doesn't know MODSERIAL disabled the TX interrupt bit, it sees the flag is set, so will happily call the TX interrupt handler.

So need to figure out nicest way to solve that.

12 Jul 2013

Okay it looks like it works, at least the simple tests I have done (on KL25Z and LPC1768). Would be nice if you (and others also of course) can check if it works.

Something to take into account, when switching devices, always use Compile All (ctrl+shift+b). Otherwise you can get weird stuff.

Import libraryMODSERIAL

MODSERIAL with support for more devices

13 Jul 2013

My serial driver for the 1665-like UARTs in the LPC21xx - used the TX and RX FIFOs to the max. Loaded up the TX FIFO in one interrupt.

This reduces the interrupt rate dramatically

14 Jul 2013

Hi Erik,

Saw your post today, grabbed the updated library and as you say example1 seems to work fine.

Any idea why adding the mbed-rtos library to the MODSERIAL example1 app causes the application to stop working?

What I see is that the blue LED (LED1) is lit solid. I am using UART0 (pc) and UART2 (uart). I am seeing output on the UART2, but nothing on UART0.

I have seen this with a number of other buffered serial examples I have been working with lately. While I could eliminate the uses of the RTOS, in my app, I would prefer not to do this as I have a large portion of my app already written.

Thanks, Cameron

15 Jul 2013

MODSERIAL was never written with the intention to work with RTOS. Problem is probably the putc/getcs in IRQ context, that goes via stdio, which isn't allowed to be used in IRQs (for a reason tbh). It might work to replace them with _putc/_getc, since that skips the stdio calls and only directly writes registers.

Edit: tested it a bit, that doesn't work :P

15 Jul 2013

I was afraid that this was going to be the answer.

Sounds as if I need to re-write my application and strip out the RTOS. Certainly not the outcome I was hoping for.

Thanks for the feedback on this thread, as well as the porting effort on MODSERIAL.

Cameron

15 Jul 2013

I will have a look at it, but considering this week I am at my work again, and since this is a hobby for me, I cannot give any promises when that happens :)

15 Jul 2013

I totally understand your situation.

16 Jul 2013

Had a short look at it: getc of Modserial already works with RTOS + IRQs (at least I assume that was the issue, reading/writing from/to serial in an IRQ). Putc was the issue that prevents the example from working. I don't know why my initial attempt didn't work, because it seems it works fine now: I redefined the standard putc to directly send everything to _putc: The MODSERIAL putc, which has no mutexes and similar stuff.

I had hopes that it would mean printf/puts would also work directly, but no joy there. Puts was simple fix, simply manually add puts function that writes characters in a loop. Printf is a bit more of a problem for me, but should be doable if I spend some time on it :P.

It isn't really a finished situation currently, but from your post I get the idea you can really use it (if this was indeed the issue, writing from an IRQ), so for now I made a fork with these changes. If/when it is finished I will put it together with the other one:

Import libraryMODSERIAL-RTOS

MODSERIAL with support for KL25Z + RTOS (beta, putc + puts currently)

If you need printf before I got that added (no timeframe ;) ), use sprintf to write it to a buffer, and then puts to write that buffer. I only tested it on the LPC1768, but should work same on KL25Z. Example1 works with rtos included.

16 Jul 2013

Hi Erik,

I appreciate all of your effort on this matter.

I spent a good part of last evening re-writing my application, eliminating the RTOS. As I need to get a working demo out the door this afternoon, I am going to finish it using the non-RTOS version of MODSERIAL.

I am definitely going to complete the RTOS version of my application, however.

Cameron