LPC1100 Processor SD Card Upgrade Application

Publisher:温暖微笑Latest update time:2016-07-14 Source: eefocusKeywords:LPC1100 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
With the development of processors, IAP upgrade is becoming more and more popular. There are many ways to upgrade IAP, such as: upgrade via serial port, GPRS remote upgrade, SD card upgrade, etc. Here is a detailed introduction on how to use SD card to upgrade the application.

The following is an introduction to the basics of LPC1100 processor IAP:

 1. LPC1100 processor (LPC1114) Flash allocation: LPC1114 has a total of 32K Flash, divided into 8 sectors, each sector size is 4K, as follows:

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

 

 

2. NXP's IAP commands are the same, there are 9 in total:

 

 

3. The IAP command passes parameters through registers R0 and R1. R0 passes parameters and R1 passes return values:

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

IAP function application:

 

1. Define the entry address of the IAP program

 

 

Code:

 

#define IAP_ENTER_ADR 0x1FFF1FF1 /* IAP entry address definition */

 

 

 

2. Define parameters

 

 

Code:

 

uint32 ParamIn[8]; /* IAP entry parameter buffer */
uint32 ParamOut[8]; /* IAP exit parameter buffer */

 

 

 

3. Define function type pointer

 

 

Code:

 

void (*IAP_Entry)(uint32 *param_tab, uint32 *result_tab) =

(void(*)())IAP_ENTER_ADR; // define function pointer

 

 

 

4. Notes:

 

①Call the IAP function according to the above function type, but pay attention to the function parameters.

② Since the on-chip Flash memory is not accessible during the erase/write operation, the IAP code cannot use or disable interrupts.

③Flash programming commands use the top 32 bytes of on-chip RAM, and user programs cannot use this space.

IAP command application (code from Zhou Gong):

 

1. Prepare sectors for write operations

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

 

 

 

Code:

 

/********************************************************************************
** Function name: SectorPrepare
** Descriptions: IAP operation sector selection, command code 50
** input parameters: sec1: start sector
** sec2: end sector
** output parameters: ParamOut[0]: IAP operation status code, IAP return value     
** Returned value: ParamOut[0]: IAP operation status code, IAP return value                     
*********************************************************************************/
uint32 SectorPrepare(uint8 sec1, uint8 sec2)
{  
    ParamIn[0] = IAP_Prepare; /* Set command word */
    ParamIn[1] = sec1; /* Set parameters */
    ParamIn[2] = sec2;                            
    (*IAP_Entry)(ParamIn, ParamOut); /* Call IAP service program */
   
    return (ParamOut[0]); /* Return status code */
}

 

 

 

2. Copy RAM contents to Flash

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

 

 

 

Code:

 

 

/*******************************************************************************
** Function name: RamToFlash
** Descriptions: Copy RAM data to FLASH, command code 51
** Input parameters: dst: Destination address, i.e. FLASH start address. 512 bytes as the boundary
** src: Source address, i.e. RAM address. The address must be word aligned
** no: the number of bytes copied is 512/1024/4096/8192
** output parameters: ParamOut[0]: IAP operation status code, IAP return value     
** Returned value: ParamOut[0]: IAP operation status code, IAP return value                     
******************************************************************************/
uint32 RamToFlash(uint32 dst, uint32 src, uint32 no)
{  
    ParamIn[0] = IAP_RAMTOFLASH; /* Set command word */
    ParamIn[1] = dst; /* Set parameters */
    ParamIn[2] = src;
    ParamIn[3] = no;
    ParamIn[4] = IAP_FCCLK;
    (*IAP_Entry)(ParamIn, ParamOut); /* Call IAP service routine */
    
    return (ParamOut[0]); /* Return status code */
}

 

 

 

3. Erase sectors

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

 

 

 

Code:

 

/*******************************************************************************
** Function name: SectorErase
** Descriptions: Sector erase, command code 52
** input parameters: sec1 start sector
** sec2 end sector 92
** output parameters: ParamOut[0]: IAP operation status code, IAP return value
** Returned value: ParamOut[0]: IAP operation status code, IAP return value                     
**********************************************************************************/
uint32 SectorErase(uint8 sec1, uint8 sec2)
{  
    ParamIn[0] = IAP_ERASESECTOR; /* Set command word */
    ParamIn[1] = sec1; /* Set parameters */
    ParamIn[2] = sec2;
    ParamIn[3] = IAP_FCCLK;
    (*IAP_Entry)(ParamIn, ParamOut); /* Call IAP service program */
   
    return (ParamOut[0]); /* Return status code */
}

 

 

 

4. Check the empty sectors

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

Code:

 

/**********************************************************************************
** Function name: BlankChk
** Descriptions: Sector check, command code 53
** input parameters: sec1: start sector
** sec2: end sector 92
** output parameters: ParamOut[0]: IAP operation status code, IAP return value
** Returned value: ParamOut[0]: IAP operation status code, IAP return value                     
************************************************************************************/
uint32 BlankChk(uint8 sec1, uint8 sec2)
{  
    ParamIn[0] = IAP_BLANKCHK; /* Set command word */
    ParamIn[1] = sec1; /* Set parameters */
    ParamIn[2] = sec2;
    (*IAP_Entry)(ParamIn, ParamOut); /* Call IAP service program */

    return (ParamOut[0]); /* Return status code */
}

 

 

 

5. Compare

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

 

 

 

Code:

 

/*******************************************************************************
** Function name: DataCompare
** Descriptions: Verify data, command code 56
** Input parameters: dst: Destination address, i.e. RAM/FLASH start address. The address must be word aligned
** src: Source address, i.e. FLASH/RAM address. The address must be word aligned
** no: The number of bytes to be copied must be divisible by 4
** output parameters: ParamOut[0]: IAP operation status code, IAP return value
** Returned value: ParamOut[0]: IAP operation status code, IAP return value                     
****************************************************************************/
uint32 DataCompare(uint32 dst, uint32 src, uint32 no)
{  
    ParamIn[0] = IAP_COMPARE; /* Set command word */
    ParamIn[1] = dst; /* Set parameters */
    ParamIn[2] = src;
    ParamIn[3] = no;
    (*IAP_Entry)(ParamIn, ParamOut); /* Call IAP service program */

    return (ParamOut[0]); /* Return status code */
}

After having the above functions, you can write the SD card upgrade function as needed:

 

1. Define the user program address

 

 

Code:

 

#define APP_CODE_START_ADDR 0x00006000 // User program start address

 

 

2. Read and write bin files from SD card to update and upgrade

 

Upgrading the program from the SD card is very simple. Open the upgrade file from the SD card, read 512 bits each time, and then write to the Flash until the writing is completed.

 

 

Code:

 

 

/**********************************************************************************
* FunctionName : UCSDCardProgram()
* Description : Program from SD card
* EntryParameter : fileName - name of application in SD card, buf - buffer
* ReturnValue : None
*************************************************************************************/
uint8 UCSDCardProgram(uint8 *fileName, uint8 *buf)
{
    uint32 addr = 0;
    FATFS fs; /*Work area (file system object) for logical drive*/
    FIL file; /*file objects*/
    UINT br; /*File R/W count*/
    FRESULT res;

 

    DisableIRQ(); // Disable interrupts
    SectorPrepare(6, 6); // Select sectors     
    SectorErase(6, 6); // Erase sectors          
    EnableIRQ(); // Enable interrupts

 

    /*Register a work area for logical drive 0*/
    f_mount(0, &fs);

    /*Create file*/
    res = f_open(&file, (const TCHAR *)fileName, FA_OPEN_EXISTING|FA_READ);

    if(res != FR_OK)
    {
         return res;
    }
    else
   {
        while (1)
        {
             res = f_read(&file, buf, 512, &br);     // 读取数据

             DisableIRQ();
             SectorPrepare(6, 6);
             RamToFlash(APP_CODE_START_ADDR + addr, (uint32)buf, 512); // Write data to FLASH
             EnableIRQ();
             addr += 512;

             if ((res != FR_OK) || (br < 512))
             {
                  break;
             }
         }
    }

    /*Close all files*/
    f_close(&file); // Close the file, must appear in pair with f_open function

    /*Unregister a work area before discard it*/
    f_mount(0, 0);

    return FR_OK;
}

 

 

 

3. Main function:

 

The main function implements key scanning. If a key is pressed, the SD card is upgraded. If no key is pressed, it jumps directly to the application program.

 

 

Code:

 

/**********************************************************************************
* FunctionName : main()
* Description : Main function
* EntryParameter : None
* ReturnValue : None
*********************************************************************************/
int main(void) 

    void (*userProgram)() = (void (*)())OSInit; // Function pointer 

    OSInit(); // Initialize the system

    while (1)
    {
         if (KeyGetValue())
         {
             UCSDCardProgram(\"LPC1114.bin\", SDBuf);
         }

         userProgram = (void (*)())(APP_CODE_START_ADDR + 1);
         (*userProgram)(); // Start the program  
    } 
}

 

 

 

The IAP program is now completed. The next step is to write the application.   .

Application Writing:

 

There is nothing special about application programming, but you need to pay attention to the settings in a few places

 

1. Set the compilation address:

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

 

 

 

2. Compile settings

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

 

 

3. Save bin file

 

LPC1100 processor SD card upgrade application (original) - My Heart Will Go On - ARM-Practitioner

 

 

4. Write the application, store the bin file in the SD card, and run the IAP upgrade program.


Keywords:LPC1100 Reference address:LPC1100 Processor SD Card Upgrade Application

Previous article:STM32F105 USB pin Vbus processing
Next article:LPC11U14 implements SD card USB disk

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号