Actually no.
1) I stated in my repro that:
1.a) keyboard2mouse from full blown SDK 2.4.1 zip (Where all the examples like "hello world" are located) always goes into hard fault.
2.b) keyboard2mouse from standalone SDK 2.4.1 zip (which only contains keyboard2mouse and nothing else) never goes into hard fault.
So this tells us that something is wrong with the firmware. And a firmware that can not recover gracefully upon resuming from BP has a bug; regardless of the protocols in use on target.
We do not believe in magic, so something is wrong.
2) What changed ?
2.a)The source files between the two zips (although located in different sub folder) are exactly the same.
2.b)The compile order of the sub component DOES change, which leads to a different memory map for USB static SRAM
keyboard2mouse standalone (works):
m_usb_global 0x40100000 Section 208 usb_osa_bm.o(m_usb_global)
s_UsbBmSemStruct 0x40100000 Data 8 usb_osa_bm.o(m_usb_global)
s_UsbBmEventStruct 0x40100008 Data 48 usb_osa_bm.o(m_usb_global)
s_UsbBmMsgqStruct 0x40100038 Data 152 usb_osa_bm.o(m_usb_global)
m_usb_global 0x40100100 Section 40 usb_device_hid.o(m_usb_global)
s_UsbDeviceHidHandle 0x40100100 Data 40 usb_device_hid.o(m_usb_global)
m_usb_global 0x40100140 Section 128 usb_device_class.o(m_usb_global)
s_UsbDeviceCommonClassStruct 0x40100140 Data 16 usb_device_class.o(m_usb_global)
s_UsbDeviceSetupBuffer 0x40100180 Data 64 usb_device_class.o(m_usb_global)
m_usb_global 0x40100200 Section 5472 usb_device_lpcip3511.o(m_usb_global)
s_EpReservedBuffer 0x40100200 Data 5120 usb_device_lpcip3511.o(m_usb_global)
s_ControlTransferData 0x40101600 Data 64 usb_device_lpcip3511.o(m_usb_global)
s_SetupData 0x40101640 Data 64 usb_device_lpcip3511.o(m_usb_global)
s_ZeroTransactionData 0x40101680 Data 64 usb_device_lpcip3511.o(m_usb_global)
s_EpCommandStatusList1 0x40101700 Data 96 usb_device_lpcip3511.o(m_usb_global)
m_usb_global 0x40101760 Section 112 usb_device_dci.o(m_usb_global)
s_UsbDevice 0x40101760 Data 112 usb_device_dci.o(m_usb_global)
m_usb_global 0x40101800 Section 1376 usb_host_ohci.o(m_usb_global)
s_UsbHostOhciHcca 0x40101800 Data 256 usb_host_ohci.o(m_usb_global)
s_UsbHostOhciTd 0x40101900 Data 1120 usb_host_ohci.o(m_usb_global)
keyboard2mouse full blown (Hard fault prone):
m_usb_global 0x40100000 Section 1376 usb_host_ohci.o(m_usb_global)
s_UsbHostOhciHcca 0x40100000 Data 256 usb_host_ohci.o(m_usb_global)
s_UsbHostOhciTd 0x40100100 Data 1120 usb_host_ohci.o(m_usb_global)
m_usb_global 0x40100560 Section 208 usb_osa_bm.o(m_usb_global)
s_UsbBmSemStruct 0x40100560 Data 8 usb_osa_bm.o(m_usb_global)
s_UsbBmEventStruct 0x40100568 Data 48 usb_osa_bm.o(m_usb_global)
s_UsbBmMsgqStruct 0x40100598 Data 152 usb_osa_bm.o(m_usb_global)
m_usb_global 0x40100700 Section 5472 usb_device_lpcip3511.o(m_usb_global)
s_EpReservedBuffer 0x40100700 Data 5120 usb_device_lpcip3511.o(m_usb_global)
s_ControlTransferData 0x40101b00 Data 64 usb_device_lpcip3511.o(m_usb_global)
s_SetupData 0x40101b40 Data 64 usb_device_lpcip3511.o(m_usb_global)
s_ZeroTransactionData 0x40101b80 Data 64 usb_device_lpcip3511.o(m_usb_global)
s_EpCommandStatusList1 0x40101c00 Data 96 usb_device_lpcip3511.o(m_usb_global)
m_usb_global 0x40101c60 Section 112 usb_device_dci.o(m_usb_global)
s_UsbDevice 0x40101c60 Data 112 usb_device_dci.o(m_usb_global)
m_usb_global 0x40101d00 Section 128 usb_device_class.o(m_usb_global)
s_UsbDeviceCommonClassStruct 0x40101d00 Data 16 usb_device_class.o(m_usb_global)
s_UsbDeviceSetupBuffer 0x40101d40 Data 64 usb_device_class.o(m_usb_global)
m_usb_global 0x40101d80 Section 40 usb_device_hid.o(m_usb_global)
s_UsbDeviceHidHandle 0x40101d80 Data 40 usb_device_hid.o(m_usb_global)
3)what's going on.
The memory location that triggers the hard fault (usb_host_ohci.c::USB_HostOhciAddToPeriodicList()::line #769) is being sourced from data structure "s_UsbHostOhciHcca" at 0x40100000. At the time of the hard fault the memory is corrupted and contains pointers outside of the valid memory range.
The first 8 bytes starting from 0x40100000 is the actual setup packet from the USB get device descriptor request (mouse from USB1).
Coincidence ? no. The USB device controller (USB1) is actually corrupting this memory.
This is a race condition in usb_device_lpcip3511.c. The code is actually violating the contract with HW:
-It erases the SETUP entry of the endpoint command/status list (see offset 0x04 in section 39.7.1 from the spec) while DEVCMDSTAT->DEV_EN is enabled.
-DATABUFSTART->DA_BUF is 0x40100000.
so, If the SETUP packet comes in before the controller had a chance to initialize SETUP entry to a valid offset then the hardware (USB1 device block) store the 8 bytes at 0x40100000 (s_UsbHostOhciHcca) belonging to USB0 device block.
You can actually reproduce the hard fault w/o any breakpoint. Unplug/replug J2 (USB1) a couple of time and you eventually hit the race condition window.
The standalone version always worked because it is corrupting memory in OSA section not in use in bm. So the corruption is hidden from main view.
See attached file for my fix (see #ifdef _HSDEVICE_SIGSEGV_FIX_).