USB host and device not working at the same time

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

USB host and device not working at the same time

1,914 Views
biafra
Senior Contributor I

Hi everyone,

 

I have a custom board based on RT1064, usigned MCUXpresso 11.5.0 and SDK 2.11.0. The device executes the main program from SDRAM (32 MB) and it uses FreeRTOS, with the heap located on SDRAM.

On USB1 the RT1064 acts as a dual CDC device. Reading other posts, to make it work, I needed to define DATA_SECTION_IS_CACHEABLE=1 and to allocate usb device data structures on internal DTC memory (not cacheable) using USB_DMA_NONINIT_DATA_ALIGN( USB_DATA_ALIGN_SIZE ). The usb device is working properly.

On USB2 the device acts as a host connected on the board to a usb modem. If I run a simple test program (executing from internal flash memory and using FreeRTOS, with the heap located on internal DTC ram), is working properly: the modem is correctly enumerated and I can communicate with it, so the hardware connections are ok.

But when the main program is executed I'm not able to enumerate the modem: I receive the kUSB_HostEventEnumerationFail error. I think the reason is related with the heap location: the same test program but with heap located on SDRAM can't even enumerate the modem.

Reading other posts I tried to define USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE=1: this way the modem is enumerated on USB2 host, but the dual CDC device on USB1 can't be enumerated on a PC.

 

How can I make both USB1 device and USB2 host work, using the heap located on SDRAM (and the USB data structures on internal DTC ram of course)?

 

Another question. When I compile with USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE=1, I receive the warning message "USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE is not supported.": why is there this message and the modem is enumerated and without USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE=1 the modem is not enumerated?

 

Many thanks

Biafra

3 Replies

1,889 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @biafra ,

There is a USB host+device demo in SDK. You can find it in usb_examples/usb_keyboard2mouse. Please refer to it.

As the USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE, I advice you not to use it. It use malloc() to allocate buffer. The malloc function split memory form heap. So, the heap should also be noncacheable. Put all USB buffer and heap into noncacheable area directly. I'd like to put heap into DTCM.

 

Regards,

Jing

1,866 Views
biafra
Senior Contributor I

Hi @jingpan,

 

Many thanks for your answer.

I've found the cause of the failure in enumerating the modem with the FreeRTOS heap located in SDRAM: when USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE=1 some data are located in m_usb_dma_noninit_data and m_usb_dma_init_data sections that wasn't defined in the Managed Linker Script settings, so the linker located them in default memory region (SDRAM). With these two sections defined as DTC ram in the Managed Linker Script settings, the modem is correctly enumerated and the usb dual CDC device is working properly.

Regarding the USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE, depending on its definition or not, in some part of the code the functions SDK_Free (that calls malloc) or OSA_MemoryFree (that calls pvPortMalloc) are called. pvPortMalloc allocs memory from FreeRTOS heap (SDRAM) and malloc from system heap (even SDRAM, from map file). I think that it's not important where these dynamic data are allocated: the difference is that when USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE=1 the cache is cleaned (calling the DCACHE_CleanByRange and DCACHE_CleanInvalidateByRange functions) in the USB_HostSend, USB_HostSendSetup and USB_HostRecv functions.

 

Is there another method other than using USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE that I can use?

 

Many thanks

Biafra

1,836 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @biafra ,

The key is "don't use cache function for USB/ENET/SD/..." DMA buffer. Assign these buffer and heap to noncacheable area. But it seems there isn't a single definition word can control all there things.

FreeRTOS has several heap policy. Heap_4.c allocate a big array first. Then allocate task heap from this array. Heap_3.c use malloc() to assign task heap from system heap directly.  You can change heap policy according to your application. 

Some of SDK examples use heap_3 and some use heap_4.

 

Regards,

Jing