USB MSC stop working when code is compiled to 0x00000000 instead of 0x1A000000

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB MSC stop working when code is compiled to 0x00000000 instead of 0x1A000000

675 Views
ondrahnilicka
Contributor I

Hello all.

I'm implementing bootloader for my LPC4337 based system (maybe it could be related also to LPC18xx). My code contains USB MSC stack from LPCOpen example (LPCOpen 3.02_43xx - usbd_rom_msc_sdmmc) connected to SD card containing FAT filesystem. Everything worked good until I implemented bootloader which copies new firmware from SD card to one of flash banks (0x1A000000 or 0x1B000000). Because of this I have to link my code to 0x00000000 flash address instead of 0x1A000000. LPC on startup remaps one of the flash banks (the one with the correct signature) to the address 0x00000000. It works properly. I tested firmware reload many times. The problem is that after changing the linking address from 0x1A..... to 0x00... USB MSC does not work. When I connect USB to PC, PC throws "Device not recognized", but the code runs further (no fault handler). Maybe it gets a bad decriptor, I don't know. So it seems to be some bad address or bad jump (or incorrect read of descriptor form an address). I have checked NVIC vector table, It seems to be OK. All vectors addresses was changed from 0x1A... to 0x00..... so the code cannot jump to 0x1A... based absolute address. I also checked the .map file (using Keil uVision) and it seems to be also good - there is no code at addresses 0x1A.... or 0x1B... everything (except RAM) is now located in 0x00...address space. I checked also the alignment of USB descriptors (must be aligned to DWord address)...it is OK in .map file. I went through the USB MSC code to find some absolute address jump or whatever suspicious, but found nothing. When I link to 0x1A or 0x00 the final .map file is the same except of 0x1A prefix of flash mem addresses, but rest bytes of addresses are the same (just shifted to 0x00...). When I compile/link to 0x1A... USB MSC works, when I recompile to 0x00 it doesn't. The rest of code works good on both addresses.

Now I have no idea what can be the problem. It seems that USB MSC code (from that example) must be placed at the 0x1A or 0x1B flash bank address (it uses the ROM code that is invisible from my side).

Using USB0 as MSC device on M4 core (M0 core is not used). Map file is in attachment.

Does anybody have some idea, what could cause such a behavior? Any ideas will be appreciated. Is there something more than M4MEMMAP what I have to take care of?

Thank you.

Ondrej

Labels (3)
0 Kudos
2 Replies

540 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Ondrej Hnilicka,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
I'm afraid it's impossible to execute the code in the 0x0000_0000~0x1000_0000 area, as this area is not the flash memory.

pastedImage_1.png
Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

540 Views
ondrahnilicka
Contributor I

I have found a workaround. I realocated all USB Msc functions code from FLASH to RAM and now it works. I tried to find which function caused this, but my code is unfortunately C++ and I cannot move only one function from the class to a different address space, I tried but Keil throws error. It seems that some of the USB MSC code from LPCOpen 3.02_43xx doesn't like m4memmap remapping. The USB MSC code takes cca 2kB in RAM so I'll keep it there likely because I don't have a time for further investigation.

Ondrej

0 Kudos