RT1020-EVK: FreeRTOS + USB + SDRAM = HardFault

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

RT1020-EVK: FreeRTOS + USB + SDRAM = HardFault

2,077 Views
edv1111
Contributor I

Hello,

I am trying to setup a MIMXRT1020-EVK project using MCUXpresso and SDK-2.6.1. I want to use SDRAM since my project will use large amounts of memory. The RAM usage is already quite high when I add LWIP and USB stacks to the project.

The only working example with SDRAM I found is 'lwip_httpscli_mbedTLS_freertos' which seems to include the correct implementation of SDRAM, however I had to modify the .scp connect script to include memory initialization routines for it to start debugging at all (POKE32 & PEEK32 commands, to correspond to what is done in this SDRAM driver (Edit: Correction: from dcd_data in evkmimxrt1020_sdram_ini_dcd.c) or else it goes to Hard Fault upon debug.

With USB stack, the situation gets more problematic. I tried to accommodate USB to no avail. There was a similar issue in early 2019 with RT1050 and the older SDK 2.5.x that was discussed here https://community.nxp.com/thread/497440
Preprocessor defines added as per the recommendations in the last post:


SKIP_SYSCLK_INIT
XIP_BOOT_HEADER_DCD_ENABLE=1

Also,

BOARD_SDRAM and BOARD_SDRAM_NONCACHEABLE are listed first and split 30MB : 2MB as described in that thread.

FreeRTOSConfig.h is also the same as in the 'lwip_httpscli_mbedTLS_freertos' example.

I get HardFaults whenever I try to use USB stack in the project that has the SDRAM setup. It does not seem to enter the main loop; at times it is stuck in SystemInit() on SystemInitHook(), and sometimes goes to 0x0 with INVSTATE Hard Fault.

What else do I need for RT1020 + FreeRTOS + USB to work with SDRAM? This use case seems to be quite obscure, as there are user manuals for each of these separately, but I found none that would mention these concepts together.

Labels (1)
1 Reply

1,658 Views
edv1111
Contributor I

I reviewed all the preprocessor defines from the 'lwip_httpscli_mbedTLS_freertos' example again. I am currently able to debug using this set, and change memory at SDRAM (addresses over 0x80000000). It seems that those in bold are mandatory. I do not have to use a custom .scp script anymore.

USB_STACK_FREERTOS
SKIP_SYSCLK_INIT
LWIP_DNS=1
XIP_BOOT_HEADER_ENABLE=1
USB_STACK_FREERTOS_HEAP_SIZE=32768
FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE
LWIP_DHCP=1
XIP_BOOT_HEADER_DCD_ENABLE=1
USE_RTOS
__REDLIB__
CPU_MIMXRT1021DAG5A
CPU_MIMXRT1021DAG5A_cm7
SDK_DEBUGCONSOLE=0
CR_INTEGER_PRINTF
PRINTF_FLOAT_ENABLE=0
XIP_EXTERNAL_FLASH=1
FSL_RTOS_FREE_RTOS
SDK_OS_FREE_RTOS
__MCUXPRESSO
__USE_CMSIS
DEBUG

In this thread, a similar issue with SKIP_SYSCLK_INIT is discussed:

iMXRT1050-EVKB runtime difficulties with project based on EVKB SDK v2.3.1 

My memory details are quite standard:

pastedImage_7.png

Linker script settings have the BOARD_SDRAM_NONCACHEABLE extra section.

pastedImage_8.png