How to mount the program into external flash using Keil

Source: Internet
Author: User
Tags jlink


In actual projects, the Internal flash space of the chip is often insufficient, which requires the program to be installed into the external flash.

In order to avoid detours, I would like to share some of my problems and lessons with you.

For your reference only. If you have any errors, please correct them. Thank you in advance!


Reprinted please indicate the source: blog.csdn.net/waitig1992


  • Introduction to hardware environment
The chip is lpc1788, and the External Flash is sst39vf1601 (norflash ).
This norflash does not have a burning Algorithm in my Keil (v4.0) version. You need to manually write the burning algorithm. I will write the specific steps later.
  • Add a burning Algorithm
Open the Options menu of the project, select the utilities tab in it, and select the first item in configure, which means "Use the target driver for the flash Project ", the following item means "using external tools for flash Projects". In general, we use jlink for debugging. Keil has a built-in driver, so select this item.
Click settings. For example:

Then the menu about the algorithm is displayed:


Click Add under this menu to add the flash burning algorithm;

  • Select a burning Algorithm

You can select the desired burning algorithm in the window shown in:



If you have the desired algorithm, select it and click Add. If not, you must manually compile the algorithm.

I will introduce the steps for writing algorithms later. I will not explain them too much here. After your algorithm is compiled, it will be displayed in this menu and you can select it directly.


  • Modify the start address and size
After successful addition, modify the start address and size on the page shown in.


The starting address is determined based on the hardware connection and chip configuration, and the size is determined based on the actual size of the external flash. After the configuration is complete, click OK.
  • Compile the jlink configuration file
After configuring the burning algorithm, you need to compile the jlink configuration file to be used by jlink when downloading the program. It mainly initializes the pin and configures the read latency. The configuration file of my project is as follows for your reference:
FUNC void PinSel(int p1, int n1, int f1){    _WDWORD(0x4002C000 + (p1 * 32 + n1) * 4, 0x8 | f1);}FUNC void InitNORFlash(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 < 32; i++)        PinSel(3,i,1);            for(i = 0; i < 21; i++)        PinSel(4,i,1);    PinSel(4,24,1);    PinSel(4,25,1);    PinSel(4,30,1);    PinSel(4,31,1);        /* PCONP |= 1 << 11 */    _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    /* STATICCONFIG1 */    _WDWORD(0x2009C220, 0x00000081);    // 16bit data width                                        // Disable asynchronous page mode                                        // Read when active bits are low                                        // No extend wait    /* STATICWAITWEN1 */    _WDWORD(0x2009C224, 0x00000002);    // WaitWEn        /* STATICWAITOEN1 */    _WDWORD(0x2009C228, 0x00000002);    // WaitOEn    /* STATICWAITRD1 */    _WDWORD(0x2009C22C, 0x0000001F);    // WaitRd    /* STATICWAITPAGE1 */    _WDWORD(0x2009C230, 0x0000001F);    // WaitPage    /* STATICWAITWR1 */    _WDWORD(0x2009C234, 0x0000001F);    // WaitWr    /* STATICWAITTURN1 */    _WDWORD(0x2009C238, 0x0000000F);    // WaitTurn    _sleep_(100);}

This is the function used. The configuration file is as follows:
INCLUDE SST39VF1601.iniInitNORFlash();                                 // Initialize memory

Select the configuration file from the init file option on the tab shown in, and you can add the configuration file;

  • Configure distributed file loading
After the above steps, external flash can work like Internal flash. Modify and load files separately, and divide the code into parts for external flash.
Do not put the code that initializes the external flash into the external flash, which will lead to read errors, and put the initialization code of the external flash to the front of the Code that stores the external flash. (It's a bit difficult, but it's hard to learn Chinese ...)
However, when the chip reads the External Flash, there will be a certain latency, so the operation will be relatively slow. We recommend that you try to put unimportant code outside.
  • Possible Problems and Solutions
After the configuration is completed, some friends may encounter the following problems:


Then, the following message is displayed: "Because the burning algorithm also requires space, but there are too few allocated Ram resources, the loading of the burning algorithm fails. Solution: Increase the ram space.

  • After the above steps, we can basically succeed. If there are any errors, I hope you can correct them. Thank you in advance! If you have other questions, you can discuss them and make progress together! (The above is for reference only)

Reprinted please indicate the source: blog.csdn.net/waitig1992

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.