10 years, 3 months ago.

Help with Serial interface. Hangs mbed completly.

Hi,

I am trying to manage a serial connection using interrupts. It is part of a wider library.

Essentially, a thread is launched by the main function ( and it happens to be a static function member of a class and it works).

This thread is in charge of just listening to serial and capture read data into a storage. The way it works is, it attaches a second worker (worker2) to the serial interface that does the heavy work while the thread seats waiting.

Worker2 never runs ( or so it seems). As soon as something is typed in the console, the whole mbed just stops.

Any hints ??

Thanks.

Julian.

stub

Serial pc(USBTX,USBRX);
VarStore Store(&pc);

main(){

Thread thread(VarStore::Worker,&Store,osPriorityNormal,DEFAULT_STACK_SIZE,NULL);

}

Class VarStore{

friend    void Worker2();

public:
static    void Worker(void const *args);
}

void VarStore::Worker(void const *args)
{
VarStore::MyThis->pc->attach(&Worker2);
}

void Worker2()
{}....................never runs and mbed hangs.

1 Answer

10 years, 3 months ago.

When using RTOS interrupts are not allowed to access functions which use shared resources which can be blocked by other functions, which include stdio functions such as getc (which I assume is in your interrupt handler).

Solution: Replace Serial with RawSerial. This doesn't use those stdio functions.

Accepted Answer

Thanks !! this works.

just crashing with malloc....I guess no malloc neither ? alternatives ??

posted by julian C 25 Aug 2014