Page 1 of 1

LPC1343 w/ USB support

Posted: Tue Jan 11, 2011 8:14 pm
by linux718
I really enjoy the ChibiOS! However, I would really like to be able to use the ROM-based USB-HID stack that resides on the LPC1343 as well as Chibi. To do this, you have to muck with the loader file and include the USB header file and call a couple init functions before allowing the main application to start (Chibi). I keep running into problems. Has anyone done this successfully?

Re: LPC1343 w/ USB support

Posted: Tue Jan 11, 2011 8:42 pm
by Giovanni
Hi,

I never did it but it should be possible, reading the UM, there are only several things to take care of:
  • Setup the USB PLL, if I remember well this is not done in the ChibiOS/RT HAL yet. You should not use the USB initialization function because it would change all the other clock settings and cause problems to the OS. Note that this function is classified as optional in the UM.
  • Initialize the I/O pins and the USB PHY. The whole procedure is described in the UM in section 10.3.1.
  • Modify the linker script (ch.ld) in order to reserve the RAM range 0x10000050 to 0x10000180 to the USB driver.
  • Link the ChibiOS/RT interrupt table to the ROM USB routines.

What I can do is to add the USB PLL support to the HAL in one of the next versions.

Giovanni

Re: LPC1343 w/ USB support

Posted: Thu Jan 13, 2011 5:42 pm
by linux718
Giovanni:
You skimmed over the hardest part:
"Modify the linker script (ch.ld) in order to reserve the RAM range 0x10000050 to 0x10000180 to the USB driver."

I think this is the root of my problem. The Code Red IDE has a great example of using the ROM-based USB stack in a program. There is almost nothing to do. Call the ROM's init routines and that's pretty much it. But you have to have the ch.ld file set up properly for those calls to go to the right places. So, can anyone hold my hand through this?

Re: LPC1343 w/ USB support

Posted: Thu Jan 13, 2011 6:54 pm
by Giovanni
Sure,

Change this line:

Code: Select all

    ram : org = 0x10000000, len = 8k


This way:

Code: Select all

    ram : org = 0x10000150, len = 8k - 0x150


This will reserve the ram from 0x10000000 to 0x1000014F. After compiling the application you may examine the map file for confirmation.

Giovanni

Re: LPC1343 w/ USB support

Posted: Tue Jan 17, 2012 4:46 pm
by tobiasquinn
Hi,
Has anyone managed to get the LPC1343 USB HID ROM drivers to work reliably with chibios, I've taken the steps mentioned above - setting the ram size, enabling clocks, integrating the IRQ and it works to a point (enumerates) but crashes (timeout on host) after multiple USB writes to the device... The crash is seen as a hard lock ie. the UART driver shell does not respond and the host sees a USB timeout.

To integrate the ROM ISR I've used the following code:

Code: Select all

CH_IRQ_HANDLER(VectorFC)
{
    CH_IRQ_PROLOGUE();
    chSysLockFromIsr();
    (*rom)->pUSBD->isr();
    chSysUnlockFromIsr();
    CH_IRQ_EPILOGUE();
}


-Tobias

Re: LPC1343 w/ USB support

Posted: Tue Jan 17, 2012 5:01 pm
by Giovanni
Hi,

It could be an IRQ stack overflow, try incrementing __main_stack_size__ in the linker script.

You could also enable the debug options in chcore.h and inspect the halt message if the OS halts.

I also recommend to not call chSysLockFromIsr() before invoking the ROM code, there is no need because the ROM code does not invoke any OS code.

Giovanni