4 years, 2 months ago.

MBED OS 5 and LPC1768 RawSerial interrupt crash

Hi,

I'm trying to get the serial port with mbed OS 5, RTOS and interrupts to work on a LPC1768.

So far I found the following post (https://developer.mbed.org/questions/76113/Error-attaching-interrupt-to-UART-on-LPC/). However the proposed solution doesn't work for me.

So far I tested the following code with mbed OS 2 and 5.

#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);

RawSerial pc(USBTX, USBRX);

void callback() {
    // Note: you need to actually read from the serial to clear the RX interrupt
    printf("%c\n", pc.getc());
    led2 = !led2;
}

int main() {
    pc.attach(&callback);

    while (1) {
        led1 = !led1;
        wait(0.5);
    }
}

For mbed OS 2 the code is here

Import programLPC_echo

LPC1768 with mbed (2) and RawSerial test

and for mbed OS 5 the code is here

Import programLPC5_echo

LPC1768 with mbed OS (5) and RawSerial test

On mbed OS 2 everything seems to be running fine (without RTOS at the moment) but on mbed OS 5 LED1 stops blinking as soon as a single character arrives.

Since mbed OS 5 kept failing I also tried to debug it offline by using the keil demo and the CMSIS-DAP connection provided by the LP1768. However this resulted in the following messages:

Load "C:\\Keil_v5\\Code\\rtos_basic_uvision5_lpc1768\\rtos_basic\\build\\uvision5\\rtos_basic.axf" 
PDSC: Cannot recover from reset
Error: Flash Download failed  -  Target DLL has been cancelled

Finally since I also have a NRF51 board on my desk I decided to try the same code with mbed OS 5 as well. In this case the test works without problems. The code is here:

Import programNRF51_Echo

NRF51 with mbed OS (5) and RawSerial test

However since I also need a USB host interface in the destination project this isn't a viable solution.

Any toughts on how to fix this?

Thanks in advance.

2 Answers

3 years, 10 months ago.

Hi everybody,

I have read your post because i have the same problem with a mtdot 868. I have replace Serial pc by RawSerial and my système doesn't work.

I have download the exemple "LPC5_echo" but it's doesn't work with my equipment.

Do you have an idée to resolve the problem ?

Thanks you

3 years, 10 months ago.

Hi everyone,

In general, you should not print from interrupt context. It takes a long time to do this and interrupt code should return as quickly as possible.

It's best to defer the print to the main loop using flags or the event loop.