I am following the evkbmimxrt1060_host_msd_fatfs_bm sample and trying to get USB host working with Zephyr. I managed to create a non-cacheable region in SDRAM and place the symbols inside, see output of readelf:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] rom_start PROGBITS 60000000 0000f4 0022c0 00 WAX 0 0 4
[ 2] text PROGBITS 600022c0 0023b4 01f88c 00 AX 0 0 4
[ 3] .ARM.exidx ARM_EXIDX 60021b4c 021c40 000008 00 AL 2 0 4
[ 4] initlevel PROGBITS 60021b54 021c48 000098 00 A 0 0 4
[ 5] device_area PROGBITS 60021bec 021ce0 0000dc 00 A 0 0 4
[ 6] log_const_area PROGBITS 60021cc8 021dbc 000048 00 A 0 0 4
[ 7] log_backend_area PROGBITS 60021d10 021e04 000010 00 A 0 0 4
[ 8] tbss NOBITS 60021d20 021e14 000004 00 WAT 0 0 4
[ 9] rodata PROGBITS 60021d20 021e14 005b80 00 A 0 0 4
[10] nocache NOBITS 80000000 028000 004000 00 WA 0 0 4096
[11] .ramfunc PROGBITS 80004000 027fbc 000000 00 W 0 0 1
[12] datas PROGBITS 80004000 027994 00009c 00 WA 0 0 4
[13] sw_isr_table PROGBITS 8000409c 027a30 000500 00 WA 0 0 4
Relevant lines from linker map file:
NonCacheable 0x0000000080000000 0x2b80 app/libapp.a(usb_host_ehci.c.obj)
NonCacheable 0x0000000080002b80 0x200 app/libapp.a(host_msd_fatfs.c.obj)
NonCacheable 0x0000000080002d80 0x100 app/libapp.a(usb_host_hci.c.obj)
NonCacheable 0x0000000080002e80 0x200 app/libapp.a(fsl_usb_disk_bm.c.obj)
In summary, a region in the beginning of SDRAM is marked as non-cacheable, and the USB host code symbols are placed in that region. I've checked the binaries geenrated by MCUXpresso and they're fairly similar.
The code compiles but USB fails to enumerate. Where should I look for the problem?
Thanks
Hi @tbonkers
Thanks for your question!
"USB fails to enumerate after you managed to create a non-cacheable region in SDRAM....".
I tried to understand what's the key point for this issue. Please correct me if something wrong.
It seems that the USB host-related code is correctly placed in the non-cacheable memory region in SDRAM. The relevant sections in the `readelf` and linker map outputs look fine. However, USB enumeration issues can be tricky and might arise from several other aspects.
Here are some further steps you can take to troubleshoot the problem:
1. Verify Non-cacheable Memory Configuration:
Ensure that the memory marked as non-cacheable is correctly set up in both your linker script and your startup code. Verify that your linker script correctly defines the non-cacheable region. This appears to be correct in your setup, but double-check it aligns with your memory map.
MEMORY
{
/* Other memory regions */
NON_CACHEABLE (rw) : ORIGIN = 0x80000000, LENGTH = 16K
}
SECTIONS
{
.nocache (NOLOAD) :
{
*(.nocache)
} > NON_CACHEABLE
}
2. Check Cache Configuration:
Double-check that the non-cacheable region is indeed being treated as such by the CPU. Ensure the memory attributes for this region are configured properly to avoid caching issues.
3. Ensure Proper USB Host Initialization:
Verify that all steps for USB host initialization are correctly followed and that no steps are missing. This includes setting up clocks, initializing hardware, and enabling interrupts.
4. Debugging Output and Logs:
Enable and review any debugging logs from the USB stack. These logs can provide insights into where the enumeration process is failing.
Debugging Output:
Enable debug logs to trace the enumeration process
By following these steps, you should be able to narrow down the cause of the USB enumeration issue and correct it. If the problem persists, consider checking for errata related to the microcontroller or the USB controller in use.
Have a nice day!
Sam
The problem was that the OSAL was dynamically allocating memory from a cacheable region. It was resolved by creating a non-cacheable heap.