Piziheng embedded: using memtester program to test SDRAM on i.mxrt1060-evk

Time:2021-4-24

Hello everyone, I’m a ruffian Heng. I’m a serious technical ruffian. Today, ruffian Heng introduces to youUsing memtester program to test SDRAM on i.mxrt1060-evk

We know that NXP i.mxrt1xxx series is the representative of high-performance MCU. For this monster with ultra-high dominant frequency (> = 500MHz), it’s a waste of its ability not to do some high-level applications in human-computer interaction graphic display or run point algorithm. High level applications often need large capacity buffer (RAM). The maximum internal ram of i.mxrt1xxx series is 1-2mb, not particularly abundant, Therefore, when we design at the board level, we often use an external RAM for i.mxrt1xxx. There are many kinds of external RAM to choose from. You can hang hyperram / PSRAM through flexspi peripherals or SDRAM / SRAM through SEMC peripherals. SDRAM is the most common choice, and SDRAM is also selected by default on the official evk.

Although the external SDRAM solves the system cache capacity crisis, it may also introduce potential system stability problems. After all, SDRAM is an external device, which is vulnerable to interference (such as PCB wiring or ambient temperature). If the read-write access of SDRAM is not reliable, then the system will have unpredictable strange problems, Therefore, we need to do a pressure test on SDRAM when the board leaves the factory (not only testing the SDRAM chip and PCB design, but also testing the corresponding SEMC peripheral configuration). Today, piziheng chooses memtester program to give SDRAM the last strength.

About the basic knowledge of memtester program, PI Ziheng wrote an article beforeMemory read write correctness stress test program (memtester)This article is a practice based on the basic knowledge of memtester. Come on, let’s get started.

1、 Preparation

1.1 hardware platform NXP i.MX rt1060 evk

To start the stress test for SDRAM, you need to have a development board. The i.mxrt1060 evaluation board is on the official website of NXP. The model of on-board SDRAM chip is MgO’s mt48lc16m16a2. We will test it today.

1.2 integrated development environment IAR EWARM

There are many integrated development environments for arm Cortex-M microcontroller, among which IAR EWARM is favored by the majority of engineers with its excellent characteristics. Today, piziheng chooses IAR as the software environment, and the specific version is IAR EWARM v8.50.6.

1.3 official software development package NXP MCU express SDK

Before we begin to transplant memtester program to i.mxrt1062, we need to have a basic Hello World routine of i.mxrt1062. Of course, we can write one from scratch in the data manual, but here PI Ziheng recommends using the official software development kit.

Register and log on to the official website of NXP toMCUXpresso SDK BuilderPage, select evk-mimxrt1060 in “select development board”, click build MCU express SDK to jump to the next page, and click download SDK to get SDK_ 2.9.1_ Evk-mimxrt1060.zip, the following is the specific version information of the development package downloaded by piziheng:

2、 Start measurement

2.1 run through Hello World

Power the i.mxrt1060 evk board (the J2 port is connected to the 5V output power supply), and use the USB cable to connect the computer with the J41 USB port of the board. At this time, you should be able to see the USB virtual serial port in the device manager (the lpc-link2 debugger on the evk board contains the function of USB to serial port. If you can’t see the serial port, please install the lpc-link2 driver yourself).

Open the SDK in the development package downloaded in the previous step_ 2.9.1_ EVK-MIMXRT1060\boards\evkimxrt1060\demo_ apps\hello_ world\iar\hello_ world.eww Confirm that the linker file in the project option is mimxrt1062xxxx_ ram.icf Then the J21 JTAG port is connected with JLINK plus to download the project directly into the ram of the main chip to run.

If the project runs normally, you should see the “Hello world.” printout in the serial port debugging assistant (115200, 8n1).

2.2 porting memtester program

Hello_ Based on the world project, unzip the memtester-4.5.0.tar package downloaded from the official website, and copy all the following source files (. C or. H) under the path of \

\memtester-4.5.0

Add all the above memtester source files to hello_ World project and rename the project memtester, and then add the original main function entry file hello to the project_ World. C is renamed as main. C, and the basic memtester project is completed. But note that the project cannot be compiled at this time, because the memtester source file needs to be further modified.

2.2.1 adapt to embedded platform

The source code of memtester we downloaded is used to run on UNIX like system, so there are some codes in the source code that are only suitable for running on UNIX like system, which need to be deleted to be suitable for running on embedded platform.

For the reference part of header file, you need to delete some inapplicable # include statements in memtester. C and tests. C files and use the standard header in SDK instead:

//The following UNIX system headers need to be deleted
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include //The following SDK standard headers need to be added

In fact, the most important (only) change of the whole memtester source code is the original main() function in memtester. C. the original main function is to accept the user options from the console to complete the parsing, obtain the necessary parameters (memory start address, test length, number of stress test cycles), and then run various algorithm subroutines in tests. C. What we need to do is to delete all kinds of code in the main function, remove all the code that is not suitable for running on MCU, and change the main function prototype as follows:

/*******************************************************************************
* Input parameters:
* ---- phystestbase : memory base address
* ---- wantraw      : memory size
* ---- memsuffix    : memory unit, B,K,M,G for B, KB, MB, GB
* ---- loop         : memory test code loop times
* ---- pagesize     : memory pase size (Bytes)
*/
int memtester_main(ul phystestbase, ul wantraw, char *memsuffix, ul loops, ul pagesize) 
{}

Finally, memtester_ When running the specific algorithm subroutine in tests. C in main, if it fails, the default is to continue to execute the next algorithm subroutine. We can add a fail_ Stop control variable, which decides whether to end the whole test or continue to run in case of failure.

2.2.2 board level initialization

In the previous section, the main() function in memtester. C has been changed to memtester_ Main (), so we’ll go directly to the original hello_ Add memtester to the main function in main. C instead of world. C_ Call main(), pay attention to set test parameters on demand (the setting in the following code is an example, test 0x8000)_ The 64KB memory starting from address 0000 can be recycled once). In addition, whether cache is enabled or not has a great impact on the test. It is recommended to turn off DCache test.

typedef struct _semc_test_config {
  uint32_t baseAddr;
  uint32_t testSize;
  uint32_t loopNum;
  uint32_t dramFreq;
  uint32_t enableCache;
} semc_test_config_t;

int fail_stop = 1;

int main(void)
{
    char memsuffix = 'B';
    /* Init board hardware. */
    BOARD_InitHardware();

    /* --------------- stress test --------------- */
    semc_test_config_t testConfig;
    testConfig.baseAddr = 0x80000000;
    testConfig.testSize = 64 * 1024;
    testConfig.loopNum = 1;
    testConfig.dramFreq = CLOCK_GetFreq(kCLOCK_SemcClk);
    testConfig.enableCache = 0;
    
    if (!testConfig.enableCache) {
        /* Disable D cache */
        SCB_DisableDCache();
    }

    PRINTF("\r\n########## Print out from target board ##########\r\n");
    PRINTF("\r\nSDRAM r/w test settings:\r\n");
    PRINTF("      Base Addr: 0x%x;\r\n", testConfig.baseAddr);
    PRINTF("      Test Size: %d Bytes;\r\n", testConfig.testSize);
    PRINTF("      Test Loop: %d;\r\n", testConfig.loopNum);    
    PRINTF("      SDRAM Freq: %d Hz;\r\n",testConfig.dramFreq);
    PRINTF("      Enable Cache: %d;\r\n\r\n", testConfig.enableCache);

    /* Run memory stress test: 64KByte, loop=1, page_size = 1kbyte */
    memtester_main(testConfig.baseAddr, testConfig.testSize, &memsuffix, testConfig.loopNum, (1*1024));

    while (1)
    {
    }
}
2.2.3 serial port printing function

The change of serial port printing function is relatively simple. You can directly replace fprintf() in the original memtester. C and tests. C files with printf(), which has been implemented in the original Hello world project.

2.3 parameter configuration of memtester

In the introduction to the basic knowledge of memtester program, PI Ziheng said that memtester has almost no parameter configuration, that is, it needs to add the following two macros in the sizes. H file:

#define ULONG_MAX  (4294967295UL)
#define TEST_NARROW_WRITES

2.4 output memtester results

At this point, the migration of memtester is complete. At this time, the memtester project (code and variables are linked in TCM) should be able to compile normally. You may wonder, where is the initialization code of SEMC peripherals? Don’t worry. There are two kinds of SDRAM initialization scripts in the project options debugger settings. We can choose either one:

In addition, it should be noted that skip needs to be added to the project precompile options_ SYSCLK_ Init macro, because the Project Clock initialization function board_ Bootlockrun() will decide whether to reconfigure SEMC according to this macro. We already have SDRAM initialization script, so we don’t need to configure SEMC clock in the project.

What are you waiting for now? Download the memtester project into the chip and open the serial debugging assistant to see the results of memtester. In order to get the result as soon as possible, PI Ziheng only tested 64KB of space. It should have tested all 32MB of space, but the test time is very long. If the loop num is greater than 1, the waiting time will be longer. If the test fails, in addition to checking the board level hardware, you can also adjust the configuration in the SDRAM initialization script to test again until you pass the stress test.

If you want to be lazy, just go to GitHubhttps://github.com/JayHeng/cortex-m-appsTo download the transplanted project, the project is in the_ Imxrt1062.

At this point, the pressure test of SDRAM with memtester program on i.mxrt1060-evk is over. Where is the applause~~~

Welcome to subscribe

The article will be published to me at the same timeBlog Garden Home PageCSDN home pageZhihu HomepageWeChat official accountOn the platform.

Wechat search“Ruffian scale embedded“Or scan the following QR code, you can see it on your mobile phone for the first time.