5 years, 2 months ago.

CANNucleo and mbed-rtos


Has anyone tried to used the mbed-rtos lib with CANNucleo? The following program is a simple test to listen for CAN messages. It works as expected.

#include "mbed.h"
#include "CAN.h"
//#include "rtos.h"

CAN can(PA_11, PA_12);
CANMessage rxMsg;
volatile bool msgAvailable = false;
RawSerial pc(USBTX, USBRX);

void onMsgReceived() 
    msgAvailable = true;

int main() 
    pc.printf("CANNucleo Test\n\r");
    can.attach(&onMsgReceived, CAN::RxIrq);
    while (true) 
        if (msgAvailable) 
            msgAvailable = false;
            pc.printf("CAN message received:\r\n");
            pc.printf("  ID     = %#x\r\n", rxMsg.id);
            pc.printf("  Type   = %d\r\n", rxMsg.type);
            pc.printf("  Format = %d\r\n", rxMsg.format);
            pc.printf("  Length = %d\r\n", rxMsg.len);
            pc.printf("  Data   =");            
            for (int i = 0; i < rxMsg.len; i++)
                pc.printf(" %x", rxMsg.data[i]);

However, when I include the mbed-rtos lib with the project, the project locks (I see no received CAN messages). I am using the latest mbed, CANNucleo, and mbed-rtos libs. Also, I am running the project on a NUCLEO-F446RE.



My bad. It appears the problem is related to the serial driver and rtos. The program works with the mbed-rtos lib if I remove the serial related statements (pc.baud & pc.printf) and just blink an LED when a CAN message is received. This problem does not exist as tested on the EA LPC4088 QSB platform.

posted by Tom Doyle 14 May 2016
Be the first to answer this question.