Hi,
As per our previous discussion in
https://community.nxp.com/t5/i-MX-RT/iMXRT1170-USB-OTG-issue-OSA-WaitEvent-in-USB/m-p/1651745, we managed to make the USB demo work on our board however, as we started to enable some other external peripherals, the USB is not working again.
As I troubleshoot the root cause, I noticed that there might be a conflict between the external peripheral and the USB in terms of using the ucHeap. As I pointed out in the previous discussion, for USB mouse or keyboard to work, I will set the configAPPLICATION_ALLOCATION_HEAP to 1 and declare the ucHeap somewhere whereas the external peripheral will make use of the heap_4.c PRIVILEGE_DATA ucHeap.
I am still trying to understand this USB demo code and try to incorporate this code into our working code without any memory usage conflicts between the peripherals. Any idea?
Solved! Go to Solution.
Hi @Desmond_lim ,
Please see BOARD_ConfigMPU() in board.c. The code is hung at
assert(!(nonCacheStart % size));
This checking is due to MPU feature. The MPU region size should be 2^N, 5<=N<=32, region base should be multiples of size.
Regards,
Jing
Hi giraffe508,
Thank you for your quick response.
1. I will try on that to ensure it work. Most likely I will double the size and see if it works or not. Currently, the heap size I am setting is 0xc000. I will try to set 0x20000 just for the try out. Is there a limit to set for the heap for this case?
2. This is the current setting I am doing now. I am following the SDK examples for USB and I think this is the only option I have since my understanding from the last conversation that USB needs to run in nonCacheable area, am I right in that aspect?
Hence, I set the configAPPLICATION_ALLOCATED_HEAP = 1 and definition of ucHeap as per SDK. The snippet of the code is as follows:
#if defined(configAPPLICATION_ALLOCATED_HEAP) && (configAPPLICATION_ALLOCATED_HEAP)
USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) uint8_t ucHeap[configTOTAL_HEAP_SIZE];
#endif
3. I was thinking of doing that too, but was a bit worried if I will break something else. Are there any SDK example in using heap_5.c for this matter?
I have also configured different combination of setting like turning on/off the configAPPLICAITON_ALLOCATED_HEAP and compare the map files and observed the output.
Let me try out your first suggestion and see if that is the issues. If it is then, it is the best. Oh, by the way, is there a way to check if the heap size is enough or not? Any tools to use besides MCUExpresso?
As for the heap_5.c, to be honest, I am still confused by the concept compare to the heap_4.c. How to set it up and what needs to be changed? The concept is also very confusing like non-consecutive memory area. The one I did in my previous example where the heap is defined in 0x81500000 is it considered as consecutive or non-consecutive?
Hi @Desmond_lim ,
I can't open the link you gave and the zip file seems empty too. I guess you may meet SDRAM cache issue. You can refer to this post.
https://community.nxp.com/t5/i-MX-RT/USB-Host-enumeration-fails/m-p/1436138
Here is some other post for your reference.
https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/Using-NonCached-Memory-on-i-MXRT/ta-p/1183369
Regards,
Jing
Hi JingPan,
I just checked on the zip file, it is not empty. However, in the zip file, there is a file which does not have a file type. However, you can open the file using any text editor because it is a text file. This file is a scatter file or linker script and by default the file type should be scf.
I am not sure if you pc will automatically delete any suspicious file or not if it is not txt. Anyway, I will upload again by changing it to txt
Hi @Desmond_lim ,
Please see BOARD_ConfigMPU() in board.c. The code is hung at
assert(!(nonCacheStart % size));
This checking is due to MPU feature. The MPU region size should be 2^N, 5<=N<=32, region base should be multiples of size.
Regards,
Jing
Hi Jing,
Yes. I did a mistake in the size calculation. It is ok now. Thanks for your help.
Hello, It seems like you are facing a memory allocation conflict between the USB and the external peripherals. To resolve this issue, you can try the following steps:
Here's a code snippet to create separate heap regions using heap_5.c:
/* Define the heap regions. */ HeapRegion_t xHeapRegions[] = { { ( uint8_t * ) ucHeap1, configTOTAL_HEAP_SIZE1 }, { ( uint8_t * ) ucHeap2, configTOTAL_HEAP_SIZE2 }, { NULL, 0 } /* Terminates the array. */ };
/* Initialize the heap with multiple regions. */ void vApplicationDefineHeapRegions( HeapRegion_t * const pxHeapRegions ) { /* Pass the array into heap_5.c. */ vPortDefineHeapRegions( pxHeapRegions ); }
Make sure to adjust the configTOTAL_HEAP_SIZE1 and configTOTAL_HEAP_SIZE2 according to your memory requirements for USB and external peripherals.
I hope this helps you resolve the memory allocation conflict between the USB and external peripherals. If you have any further questions or need more assistance, please feel free to ask.