7 years, 10 months ago.

Serial Interups and mbed-rtos

Hi,

I have a problem that if i include the rtos library on the 1768 as soon as my serial rx interrupt is triggered it seems to stall. see this repo for an example https://developer.mbed.org/users/chrissnow/code/serialinterrupttest/

what's really odd is that removing the rtos library doesn't fix it, only creating a new program and never adding the rtos seems to work.

1 Answer

7 years, 10 months ago.

Compile -> compile all should also fix it.

You need to use RawSerial, regular Serial can't be read during interrupts, and you need to read to use the RX interrupt. Just replace 'Serial' with 'RawSerial'.

Accepted Answer

Thanks for the info. Is this the best approach when using the rtos with serial? Happy to do something different if there is.

posted by Chris Snow 10 Jun 2016

Yes that is the best approach.

Bit of summary: Regular Serial uses C stdio library as in-between layer for also things like printf. C stdio library wants to take exclusive control of the Serial in RTOS. However this is done with a mutex, and they are not allowed in interrupt context, locking up your device.

RawSerial does not use the C stdio layer. Popular ones like printf are implemented 'manually', but you don't have all the C stdio functions when using RawSerial. However your basic Serial is there, and functions properly also in interrupts.

posted by Erik - 10 Jun 2016

It is worth noting that if you are pulling data in an interrupt then you probably won't be using the printf/scanf functionality anyway so it is no loss to use rawserial instead of serial.

posted by Oliver Broad 11 Jun 2016