Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 1 month ago.
SerialDriver on a KLZ25/KL46 freezes my application
Hello,
The following code can reproduce my issue
#include "SerialDriver.h" DigitalOut lb(LED1); //SerialDriver pc(USBTX, USBRX);// Uncommenting this line makes the application hang int main() { lb=false; Timer elapsed; elapsed.start(); for(;;) { if(elapsed.read_ms() > 500) { elapsed.reset(); lb=!lb; } } }
I'm having this issue both on a KL25Z and a KL46Z. When I uncomment the line, the led stays lit on both board, the application is frozen. When I comment it blinks as expected.
Any idea what is going on ?
Question relating to:
2 Answers
9 years, 1 month ago.
Quick check shows it has the TX interrupt always enabled. On the LPC series for example, the TX interrupt generates an interrupt when a character was sent, so by definition there is now space in the tx buffer available again.
The KL series fires an interrupt when there is space in the TX buffer: There is always space in the TX buffer, so it keeps firing the interrupt, locking your program.
So it could be a solution to attach the TX interrupt when the outgoing software ring buffer gets some data and detach if this buffer gets empty? Or at least, enable/disable the isr.
posted by 23 Oct 20159 years, 1 month ago.
Hi! I do not own KLZ25 or KL46 so I can not debug this for you, we need to work together. First make sure, that every library in use is up to date.
What happens, if you comment out your Timer? My SerialDriver library is using the official mbed RTOS library, there might be an issue with RTOS and the Timer class. mbed RTOS provides a separate class for this: RtosTimer.
Please test: 1.) SerialDriver without (conventional) Timer 2.) SerialDriver with RtosTimer
Hi BlazeX
I tested 2) with the following code:
#include "SerialDriver.h" #include "rtos.h" DigitalOut lb(LED1); void blink(void const * args) { lb=!lb; } int main() { RtosTimer timer(blink, osTimerPeriodic); SerialDriver pc(USBTX, USBRX); lb=false; timer.start(500); Thread::wait(osWaitForever); }
I've obtained the same results.
I did not run test 1 because the conventional Timer is not entirely the same thing as the RTOS one. You cannot measure random time intervals with rtosTimer. If SerialDriver was not compatible with conventionnal timer then I would have to switch over to another lib
Did you have a look at Erik's answer ? I believe he's highlighting the true problem
Anyway, thank you for your support
posted by 23 Oct 2015I published an updated version, I've testet on LPC1768. It should fix your problem. Please give it a try and report, if it works or not.
posted by 25 Oct 2015Problem is fixed, thanks
I used the following code to validate the behavior, even checked that serial flow is well received computer side.
#include "SerialDriver.h" #include "rtos.h" DigitalOut lb(LED1); void blink(void const * args) { lb=!lb; SerialDriver* d = (SerialDriver*)(args); lb == true ? d->putc('A') : d->putc('B'); } int main() { lb=false; SerialDriver pc(USBTX, USBRX); RtosTimer timer(blink, osTimerPeriodic, (void *)&pc); timer.start(500); Thread::wait(osWaitForever); }
Assigned to
9 years ago.This means that the question has been accepted and is being worked on.
Fixed it. Thanks for the hint.
posted by BlazeX . 27 Oct 2015