AnsweredAssumed Answered

Issue with MIMXRT1050-EVK, FreeRTOS and SDRAM for data storage

Question asked by Ed Waldner on Feb 22, 2018
Latest reply on Mar 29, 2018 by Ed Waldner

I started out with an MCUXpresso SDK 2.3 sample project for using FreeRTOS and I customized it to create three tasks and an event queue for dispatching requests from two of the tasks into the third. (freertos_queue example) The initial SDK example project ran out of SRAM, so I converted the project to run out of hyperflash on the MIMXRT1050-EVK.

 

This step was performed using notes from Overview of using the MIMXRT1050-EVK(B) with MCUXpresso IDE to convert a RAM project to XIP from flash (doc v104, page 17).

 

At this point, the project builds and runs well, however the heap used by FreeRTOS along with all other data memory resources come from SRAM_DTC. This area maxes out at 128KB and the project that I am preparing for will use several hundred KB of heap space. For this reason I am attempting to use the MIMXRT1050-EVK SDRAM (32 MB) device. 

 

I changed the project config for memory details to include an SDRAM section and positioned it immediately below the hyperflash section. 

 

memory details

I then edited FreeRTOSConfig.h and increased my heap allocation:

 

/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE ((size_t)(500 * 1024))
#define configAPPLICATION_ALLOCATED_HEAP 0

 

The build completed error/warning free, but I get a hard fault thrown at runtime. 

 

 

By decreasing the heap size to 30 * 1024, I no longer get the hard fault, but rather my second of 3 tasks fails to create (pvPortMalloc call returns NULL). My queue and task that uses the queue create without problems.

 

I searched for similar issues posted to the community and found Jack King's thread:

Does debug init SDRAM for xip app on MIMXRT1052? 

 

as well as a thread describing similar hard fault issues with FreeRTOS for the LPC1778:

hard fault when FreeRTOS heap is in external SDRAM 

 

The takeaway from one of Jack King's comments:

2. When using xip to execute a project from flash, SDRAM is not needed, but *is* initialized (for some reason?) This is done by configuring the project to use xip: adding the xip sdk components, adjusting the linker, adding flash memory definition and setting the XIP_EXTERNAL_FLASH symbol.  The SDRAM configuration is performed by the flash bootloader using an array defined in fsl_flexspi_nor_boot.c

 

was that I didn't need anything else for SDRAM init other than the memory config I have above since I could see the dcd_sdram[] space initialized in my project via constant def in fsl_flexspi_nor_boot.c.

 

The hard fault thread mentioned a corrective action for EMCDLYCTL for that processor:

LPC_SC->EMCDLYCTL = 0x1410;
LPC_EMC->DynamicReadConfig = EMC_DynamicReadConfig_RD(1);

 

however I could not find references to these settings in my project. The closest thing was the config of fsl_semc driver, but I don't have a good understanding whether that is even needed for what I'm trying to do. 

 

I tried setting the heap to match the configuration that was running on the SRAM_DTC setup (10 x 1024) however that resulted in the same problem as the 30 x 1024 heap size. 

 

I looked in the project linker definition for heap and stack placement and redefined the region for both to SDRAM and size to a ridiculous value (0xF4240) for each heap and stack, just in case this affects FreeRTOS usage, but my problem persisted. 

 

I believe I'm dealing with a misconfiguration in this setup for dynamically allocating memory resources out of SDRAM, but I am not sure what to try next. Any hints are appreciated.

Outcomes