Hello,
Tricky one to post and get a diagnosis but I thought I'd try
1) Using Rowley CrossWorks because MCUExpresso is... well I never really worked out how it worked. It's also not our in house preferred tool.
2) Using the LPC libraries (i'm not sure what version, I inherited this project and the files were a bit mangled in the end, however my present code calls are now the same as 1.0.3).
I am using the NXP USB driver as a mass storage host. Overall things are working - I can detect a USB stick, get the data from it telling me it's made by SanDisk and so forth (this is all just the initialisation from the example code - nothing I've written).
However, when I come to try read data from the disk, in the first case, Sector 0 to get the partition table, I use the MS_BulkRecv function but get a hard fault during the USB transaction. The Host_ProcessTD() function is the sticking point. This is already called three times during the initialisation process (where it reports the brand etc). The curiosity is that if I single step through the code, the read works fine and I get something resembling a FAT32 MBR!
Regarding the library code, this is refactored to a better coding standard but is unchanged. My present feeling is around memory locations. Behind the scenes the USB has two types of memory, the fast AHB memory where all the end points live; it also has standard memory. I wonder if my receive buffers all need to be in the AHB memory block and going through the debugger slowly gets rid of the race condition. Beyond that I haven't much idea.
Has anyone got any thoughts on the Gotchas involved in this part of the code and USB or any ideas of a place we can look first? As I wrote this I wasn't sure what to attach since my code is largely the USB library!
Thanks
While I have very little experience with USB, I had been using Crossworks for years.
Though this problem seems not directly related to the toolchain.
I would start with backtracking from the Hardfault handler routine, and check the SCB register values - that should be possible in the debugger. These values should tell you something about the fault reason and location.
I always recommend the Keil document in this regard : https://www.keil.com/appnotes/files/apnt209.pdf
Hello @synth_bouffant
Sorry I haven't used Rowley CrossWorks tool.
About USB mass storage host, how about refer to the demo "lpcusblib_MassStorageHost" under LPCopen? It integrated into MCUXpresso IDE, also can download from:
There is a detail description about this demo:
https://community.nxp.com/t5/LPCware-Archive-Content/Mass-Storage-Host-example/ta-p/1125544
BR
Alice
Thanks for the response @Alice_Yang. I've tried several times to do this but the instructions aren't especially clear and Eclipse was never the most intuitive IDE. I've never managed to successfully find the projects listed in the guide when loading up the folder of projects. It's like they're not even similar, not a single one listed.
Either way, motivated by your post, I tried again and still can't get it going. Are there any more instructions which would make the projects needed more explicit. For instance, nxpUSBlib, and Example_MassStorageHost are simply not present in the project archive.
That said, I have extracted files which I have reverse engineered from our older projects and your examples in the archive 1.0.3 and have code which executes in the same order. Infact, the software setup I have in CrossWorks does do a bulk receive as part of the set up of the peripheral and initial detection of the device. It's only when I try to read Sector 0 that it crashes.
Hello @synth_bouffant
Attachment just a simple video about how to use MCUXpresso IDE open example "lpcusblib_MassStorageHost" .
BR
Alice
I thought I would respond to this as the video enabled me to get a system up and running (ages ago, but the forum wouldn't allow me to log in and reply for a long time). This gave me access to the numbers I needed to get my code going (for interest, it turns out the stack has to be massive for the USB code!).
Having then back tracked through older versions of the libraries, the instructions don't work for other archives; they are specific to one version. At the expense of consistency, perhaps it's worth linking/mentioning which version of the libraries the instructions work with.
However, thanks for your help. It's what I needed.