Hello,
I've just gotten a chance to try this out myself.
Quote:
The Problem is that Serial IRQ Flag isn't cleared in ISR. It gets cleared by reading the RX buffer i guess. Is it a bug or a feature?!
Yes, most hardware will keep the interrupt pending until it is cleared. Some boards do not have a way to clear the IRQ unless you read from the register, so it must be consumed.
Another problem with your program... printf will generate serial events, and for each of those events, you'll print more, so you're stuck in an infinite loop even if you consumed the data in your callback.
So, here is a program that will do what I think you want:
#include "events/mbed_events.h"
#include "mbed.h"
mbed::Serial *pc;
EventQueue eventQueue(32 * EVENTS_EVENT_SIZE);
Thread t(osPriorityNormal);
void post_to_queue();
void printtext(){
pc->printf("text received %c\n\r", pc->getc());
pc->attach(post_to_queue, Serial::RxIrq);
}
void post_to_queue(){
pc->attach(NULL, Serial::RxIrq);
eventQueue.call(printtext);
}
int main(){
t.start(callback(&eventQueue, &EventQueue::dispatch_forever));
pc = new Serial(USBTX, USBRX);
pc->attach(post_to_queue, Serial::RxIrq);
}
Hello there,
When i'm trying to attach an EventQueue event to the Serial RX ISR it produces an assert:
mbed assertation failed: id, file: /src/mbed-os/events/Event.h, line 149
With other ISRs it is working. I don't understand what the assert means. Any suggestions?
EXAMPLE CODE