Hi Bernhard,
Thanks for your reply. I had figured out most of those details and I also found the USBD source (including the original ROM USBD source) in https://www.nxp.com/docs/en/application-note/TN00041.zip
This is indeed the USBD code for the LPC18xx/43xx MCU.
I managed to piece all that together and rework my code to use that stack and got it up and running.
The version identifier (from mw_usbd_rom_api.c) of the the code in TN00041.zip is 0x02233405. Much later than the version of the ROM stack it appears.
It does indeed have the changes for 64 bit byte offset value in the control structure but I don't think anyone ever tested this code by writing more than 4G of data to a device. Mainly because it fails with the file system being corrupted.
There is a bug in this version as well and as soon as you reach the 4G boundary the offset wraps back to zero destroying the FAT first followed by critical structures at the beginning of the cluster heap. This destroys the filesystem (exfat in my case) and the partition cannot be mounted after that. The parameter high_offset is always passed in as zero.
After spending a few hours wandering through code with a little bit of wiresharking and debugging I found the issue and fixed it. While the offset in the USB control structure is a uint64_t, the variable that is used to extract the LBA value from the USB packet is a uint32_t which causes 32 bit arithmetic to be used erroneously.
The function mwMSC_RWSetup in mw_usbd_mscuser.c contains the following line that converts the LBA address to the 64 bit offset:
pMscCtrl->Offset = n * pMscCtrl->BlockSize;
This line needs a cast to make sure that 64 bit arithmetic is used and should read:
pMscCtrl->Offset = (uint64_t)n * pMscCtrl->BlockSize;
With that fix in place I was able to write multiple 7GB files to the sd card with out any problem.
Hopefully this post helps 2^32+1 people.
Best regards,
Mike