Summary of Issues Keil program debugging in external RAM (Personal experience Summary)

Source: Internet
Author: User
Tags jlink

Keil program in the basic steps of internal RAM debugging online has been very much, I will not repeat, we can search the Internet very much.


But sometimes the internal ram is not enough, this need to load the program into the external Ram debugging, and in this process may have a variety of problems, here I will have some of the problems I have encountered and the need to pay attention to the place to summarize, I hope to be helpful to everyone.


The wrong place also hope that the gods can teach, in advance to express their thanks ...


Reprint Please specify source: Waitig's Blog


First introduce my project using hardware, Chip is LPC1788, external ram is mt48lc4m32b2, size 16M (128Mb X32 SDRAM), before using mt48lc2m32b2, size 8M, later found things too much, 8M is not enough, So it's replaced by 16M.

There have been some problems with swapping RAM, which is described in the next article.


    • In the external RAM debugging program, the program must not have the operation of external RAM code!


Debug in external RAM, do not have code to operate external RAM in the program, and do not initialize or include operations on RAM-related pins.

The initialization of RAM and the initialization of the pins should be put into the download configuration file of Jlink, which is mainly related to the configuration of the LPC registers, do not forget the reading algorithm configuration in RAM.

Put my configuration file for everyone to participate in the test.

FUNC void Pinsel (int p1, int n1, int F1) {_wdword (0x4002c000 + (P1 * + n1) * 4, 0x8 | f1);}        FUNC void Initsdram (void) {int i;    Pinsel (2,16,1);    Pinsel (2,17,1);    Pinsel (2,18,1);    Pinsel (2,20,1);    Pinsel (2,24,1);    Pinsel (2,28,1);    Pinsel (2,29,1);    Pinsel (2,30,1);    Pinsel (2,31,1);            for (i = 0; i <; i++) Pinsel (3,i,1);    for (i = 0; i < i++) Pinsel (4,i,1);    Pinsel (4,24,1);    Pinsel (4,25,1);    Pinsel (4,30,1);        Pinsel (4,31,1);    /* PCONP |= 1 << */_wdword (0X400FC0C4, 0x04288fde);    Power on EMC/* Emccontrol |= 1 */_wdword (0x2009c000, 0x00000001);    Enable EMC/* emcdlyctl */_wdword (0X400FC1DC, 0x00081818);    Config Data Read Delay/* Emcconfig */_wdword (0x2009c008, 0x00000000);    Little endian Mode/* DynamicControl */_wdword (0x2009c020, 0x00000003);  Set Normal self refresh mode, normal power mode//CE always HI                                      Enable clock out//clock does not stop Duri    NG Idle/* Dynamicrefresh */_wdword (0x2009c024, 0x0000001F);    Refresh Timing/* Dynamicreadconfig */_wdword (0x2009c028, 0x00000001);    Read Timing/* DYNAMICRP */_wdword (0x2009c030, 0x00000002);    TRP/* Dynamicras */_wdword (0x2009c034, 0x00000003);    TRAS/* Dynamicsrex */_wdword (0x2009c038, 0x00000005);    Tsrex/* DYNAMICAPR */_wdword (0x2009c03c, 0x00000001);    TAPR/* Dynamicdal */_wdword (0x2009c040, 0x00000005);    Tdal/* DYNAMICWR */_wdword (0x2009c044, 0x00000003);    TWR/* DYNAMICRC */_wdword (0x2009c048, 0x00000004);    TRC/* DYNAMICRFC */_wdword (0x2009c04c, 0x00000004);    TRFC/* DYNAMICXSR */_wdword (0x2009c050, 0x00000005);    TXSR/* DYNAMICRRD */_wdword (0x2009c054, 0x00000001); TRRD/* DYNAMICMRD */_wdword (0x2009c058, 0x00000003);    TMRD/* DYNAMICCASRAS0 */_wdword (0x2009c104, 0x00000303);    Ras/cas Latency/* DYNAMICCONFIG0 */_wdword (0x2009c100, 0x00004500);                       Config device type as SDRAM//config address mapping _sleep_ (100);    Wait MS/* DynamicControl */_wdword (0x2009c020, 0x00000183);                       NOP command _sleep_ (100);    Wait MS/* DynamicControl */_wdword (0x2009c020, 0x00000103);    Pre-charge command//* Dynamicrefresh *///_wdword (0x2009c024, 0x00000002);                       Refresh Timing _SLEEP_ (100);    Wait MS/* Dynamicrefresh */_wdword (0x2009c024, 0x0000001F);    Refresh Timing/* DynamicControl */_wdword (0x2009c020, 0x00000083); Mode command _rdword (0xa0000000 |        (0x32 << (2 + 2 + 8));                       _SLEEP_ (100); Wait MS/* DynamicControl */_wdword (0x2009c020, 0x00000003);    Noamal Command/* DYNAMICCONFIG0 */_wdword (0x2009c100, 0x00084500);                       Enable buffer _sleep_ (100); Wait-MS}

The above is the initialization part of the external RAM, do not forget the RAM itself in the register, in this case the address is 0xa0000000, the function of the various bits in the Register for example:


(since MT48LC4M32B2 's datasheet)

The data to be configured correctly, RAM ability to work correctly. The next step is the configuration of the Memory Protection Unit (MPU), the combination of which is Jlink initialization and configuration of RAM.


Ram_debug.ini files such as the following are seen:

INCLUDE Mt48lc4m32lfb5.iniinitsdram ();                                Initialize Memoryload. \SDRAM_OBJ\UC1788.AXF INCREMENTAL    //Download program/* RNR */_wdword (0xe000ed98, 0x00000000);            Use no.0 mpu/* RBAR */_wdword (0xe000ed9c, 0xa0000000);            Set MPU Base addr/* RASR */_wdword (0xe000eda0, 0x03000031);            Set MPU size and permission/* SHCSR *///_wdword (0xe000ed24, 0x00000100);            Enable memory Managemeng fault/* mpu_control */_wdword (0xe000ed94, 0x00000005);            Enable mpu/* vtor */_wdword (0xe000ed08, 0x10000000);            Set vector Table offsetsp = _rdword (0x10000000);                   Set Stack pointerpc = _rdword (0x10000004);                   Set Program counter

This can be debugged in RAM just like debugging in Flash.

However, do not appear in the program no matter what operating RAM code! Be sure to remember!


    • An error occurred in the program loading the start address in RAM


The so-called start address, that is, the program just loaded into RAM, has not executed the PC address.
Normally, this address is the address of the Systemiinit () function that points to the chip's boot code, but sometimes the address goes wrong and runs to a place where you don't know what the address is.


For example, as seen in:



I analyze this phenomenon because of the problem with the configuration of RAM in the Jlink, that is, the RAM is not configured successfully, causing the program to not be successfully stored in RAM, or the storage is successful, but the read failed, or storage read there is a problem.


The solution is to look at the data in memory to see if it is correct. Or the device power up again, the Jlink reset after debugging again.


This problem occasionally occurs to me, but again the debugging will disappear, so I do not know the reason for this problem at the moment.


    • program runs into Hardfault_handler

Hardfault_handler refers to an instruction error interrupt, usually due to an incorrect instruction in the assembly code that is translated into the program code.

The solution is usually to find the address of the wrong instruction, assuming that the address is at the very beginning of the currently allocated code snippet (for example, I put the code between 0xa0001000-0xa0002000 in the scatter load, and then the error command is now 0xa0001010 this position);

Or at the end of the last code snippet (for example, I put this code at the 0xa0001000 position, the previous code ends in 0xa0000900, and the error command is in the 0xa0000920 position);

In general, it is caused by insufficient memory, and the statement that makes the error is usually the statement that assigns a value to the global variable. Because the memory is not enough, but jlink in the RAM to write data when the memory is not enough, resulting in the subsequent overflow of the data back to the beginning of the code snippet, the contents of the past caused by overwriting. (Memory overwrite)


The solution to this problem is to change a large ram.


Another possibility is that there is code to manipulate the RAM in the program, which can also cause the contents in RAM to be changed and the wrong instructions to appear.


    • The program runs in the middle


The problem in the previous article may also cause the program to run Midway, and another possibility is a pointer problem.

The pointer is not initialized correctly, an uninitialized pointer is used, or the pointer is not properly recycled, causing the wild pointer to appear, which is the most common and easiest cause of the program to run. This factor should be considered first in the event of a failure.


After the above factors have been excluded, it is possible to find out the detailed reasons by looking at the values of the LR registers, such as the default ones, and finding the failed statements.


    • Issues to be aware of when replacing new external ram


Before replacing the new RAM, look at the RAM manual and the chip's manual, see clearly using the chip support does not support the new RAM, I did not see clearly the manual led to buy the chip does not support the RAM, both expensive and laborious ....

The chip user Manul generally has a table, which is the type of all the ram it supports. For example, with:



Find out before you buy chips, bloody lessons ...


Different RAM read and write rules some will be different, configuration is not the same, so in the replacement of new RAM should be carefully read the RAM datasheet, it is clearly mastered.

The main parameters that need to be configured are the following: page size, external bus address mapping (row, column, bank), space size, number of bits, read and write algorithms (configured in RAM's own registers);

The external bus address mapping is appropriate for the chip, and then the value of the configuration register is determined by the table above. (Program debug in RAM to change jlink INI file)



    • Conclusion: The provisional thought of these, the above problems are I encountered in the actual project problems, and some experience introduced. Because I also do not have the skills, limited, so inevitably there is the wrong place, hope that the great God passing can help correct. statement at the same time, for reference only.


Reprint Please specify source: Waitig's Blog


Summary of Issues Keil program debugging in external RAM (Personal experience Summary)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.