lpcware

USB Hard Fault during ISR if task is not running

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by ldchub on Wed Dec 09 02:25:33 MST 2015
Hello everybody,

I have a problem with USB on LPC1766 processor.

Setup)
Toolchain & Editor: LPCXpresso v7.9.2
uC: LPC1766

Problem description)
I'm modified the usbd_lib_cdc example from LPCopen to integrate the USB functionality into Freertos-based application firmware.

I followed the indications from here:
http://www.freertos.org/FreeRTOS-Plus/BSP_Solutions/NXP/combining_lpcopen_example.html
The final result is OK with the USB task being the only task in the system (apart from the idle one).

Later on, I added tasks for my application, and now I'm getting an Hard Fault when the USB_IRQHandler() is called. This does not happens always, but only when the running task is not the USB one. Instead, the call to
USBD_API->hw->ISR(g_hUsb)
does not produces any error if the running task is the USB one.

What I did)
I tried to modify the task' stack up to 1024 bytes, but the error persisted.

I also checked the priority value of USB interrupt to comply with FreeRTOS requirements (logic priority less or equal to configMAX_SYSCALL_INTERRUPT_PRIORITY. But the problem persisted.

Further, the problem arises both if I use FreeRTOS api in USB ISR (...FromISR suffix) or I don't use any synchronization at all.

Could you help me?

Some information:

List of tasks launched, with priorities and dimensions:

xTaskCreate( usb_entry_point, ( signed char * ) "USB", 1024, ( void * ) NULL, tskIDLE_PRIORITY+4, &xUsbTaskHandle );

    xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );
   
    xQueue_myQueue = xQueueCreate( 4, ( unsigned portBASE_TYPE ) 40 );
       
    xTaskCreate( vSIM_Task, ( signed char * ) "SIM", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY + 1, ( xTaskHandle * ) NULL );



Register dump during Hard Fault:
r0volatile uint32_t0x2007c010 (Hex)
r1volatile uint32_t0x1000025c (Hex)
r2volatile uint32_t0x800005ff (Hex)
r3volatile uint32_t0xd24d (Hex)
r12volatile uint32_t0xa5a5a5a5 (Hex)
lrvolatile uint32_t0xc189 (Hex)
pcvolatile uint32_t0xd25a (Hex)
psrvolatile uint32_t0x1000028 (Hex)

The program counter points to the flash sector, indeed I'm using usbd ROM stack. So I think NXP should take the floor here.

In attachment you can find the linker file and the file containing the USB ISR and task.

Thanks for your support







Original Attachment has been moved to: cdc_if.c.zip

Original Attachment has been moved to: linker_file.zip

Outcomes