11 years, 1 month ago.

RTOS breaks USBDevice on LPC11U24

I can't seem to get the USBDevice library to work alongside RTOS library on an LPC11U24. I'm trying to combine the USBHID demo with the basic RTOS demo, but as soon as I add the USBHID hid(8, 8); line, everything grinds to a halt. No flashing LEDs, nothing. And yet I can run the same code on a KL25Z just fine. Do the RTOS and USBDevice libraries use so much RAM that they can't coexist on an LPC11U24?

#include "mbed.h"
#include "rtos.h"
#include "USBHID.h"

//LED objects
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);

//USB objects
USBHID hid(8, 8);
HID_REPORT send_report;
HID_REPORT recv_report;

void led1_thread(void const *args)
{
    while (true) {
        led1 = !led1;
        Thread::wait(500);
    }
}

void led2_thread(void const *args)
{
    while (true) {
        led2 = !led2;
        Thread::wait(1000);
    }
}

int main()
{
    send_report.length = 8;

    Thread thread1(led1_thread);
    Thread thread2(led2_thread);

    while (true) {
        //Fill the report
        for (int i = 0; i < send_report.length; i++)
            send_report.data[i] = rand() & 0xff;

        //Send the report
        hid.send(&send_report);

        //try to read a msg
        if(hid.readNB(&recv_report)) {
            led3 = !led3;
            for(int i = 0; i < recv_report.length; i++) {
                printf("%d ", recv_report.data[i]);
            }
            printf("\r\n");
        }

        Thread::wait(100);
    }
}

Question relating to:

Ok, fixed the first problem. Apparently USBHID hangs the system until a USB cable is connected. However, the moment I write to it with SimpleHIDWrite it crashes. Any ideas would be appreciated.

posted by Neil Thiessen 08 Nov 2013

Can you elaborate on what you did to get the above example working? I'm running it (except for changing the LED pins) and it is behaving as you describe.

Thanks,

don

posted by Don Elwell 25 Jul 2014

Hi Don, I resolved this several months ago. If I recall right, there was a bug in mbed-rtos that caused it to only use a fraction of the RAM on the LPC11U24.

posted by Neil Thiessen 25 Jul 2014

Hi Neil, Thanks for the comment. Still no joy. I found the issue you posted about the initial stack pointer being incorrect and verified it is correct in the RTOS source code. I discovered I have the 301 variant which has less memory. I tried changing INITIAL_SP down to 0x10001800 and cutting the number of threads down to 1 but that still didn't work. I've ordered a few of the 401 devices on the off chance that this is the issue. Very strange.

posted by Don Elwell 31 Jul 2014

1 Answer

10 years, 2 months ago.

Any update on this? I think I have the same issue on a lpc1768

Yea, I am actually having similar problems as well. I am using the lpc1768 and as soon as I add the mbed-rtos library. It all breaks.

posted by John Kading 29 Sep 2014

I posted an issue for this problem on github: https://github.com/mbedmicro/mbed/issues/470 But not much response at the minute, can't find the problem myself because I know nothing about USB

posted by Jannes De Brabandere 30 Sep 2014

I figured out the issue for myself. There was a printf in the the USBDevice code that I think was screwing up the timing. So at the end of the day, I think it was my own error.

posted by John Kading 30 Sep 2014

Was this printf in the standard usbdevice library? I'm trying with the normal usbmidi example and thread example, when put together it halts at the usbmidi initialization.

posted by Jannes De Brabandere 01 Oct 2014