hw->Init and hw->GetMemSize return seemingly incorrect values

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by giedrius on Thu Jul 25 05:28:57 MST 2013
Hello, my question/problem is more or less the same as stated in part 1 of this comment http://www.lpcware.com/content/forum/usb-rom-resource-usage#comment-1120292 However as it was not answered I will repeat it again from my point of view.

So I have this piece of code

usb_param.mem_base = 0x10001000;
usb_param.mem_size = 0x1000;


uint32_t usbMemSize = pUsbApi->hw->GetMemSize(&usb_param);
ret = pUsbApi->hw->Init(&hUsb, &desc, &usb_param);

GetMemSize returns 0x400 (1024)
and after calling hw->Init usb_param.mem_base changes from 0x10001000 to 0x10001b00 (difference of 0xb00 or 2816 bytes) and usb_param.mem_size changes from 0x1000 to 0x900 (difference of 0x700 or 1792 bytes).
Right from this point I have 3 different values that assumingly should be equal. What can be noticed though is that usbMemSize + mem_size difference = mem_base difference.
From another point of view I am telling that USB can use memory from 0x10001000 to 0x10002000 (just added 0x1000 mem_size), but after the call adding the values together yields that hw->Init decided that from this point an address region from 0x10001b000 to 0x10002400 can the used by another application (let's say I'm implementing HID or CDC afterwards), which not only extends past my given memory region, but also past the physical RAM region (I'm using LPC11U37).

So I have few questions:
1) Which value should I trust?
2) Does hw->Init allocate some region for some instance X, update mem_base, update mem_size, then allocate USB device stack of size usbMemSize, update mem_base, but forget to update mem_size?
3) Should I manually decrement mem_size by usbMemSize after calling hw->Init?
4 statement) According to GetMemSize I could fit USB device stack into USB RAM (2kB), however hw->Init reports that it takes more than 2kB of space, which combined with the fact that mem_base must be 4096 byte aligned can be put only at 0x10001000 renders half of RAM useless unless I think of something that could dynamically use that remaining ~1kB of space (0x10002000-0x10001b00).
4 question) Or is this just some kind of bug which in reality use only GetMemSize amount of memory and USB stack can perfectly be put into USB RAM without any consideration of possible crash?
5) Why does NXP support seem to turn quiet when there are questions about this seemingly flawed and/or poorly documented USBD ROM Stack problems?