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:
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:
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
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
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
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
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
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:
2. Compile settings
3. Save bin file
4. Write the application, store the bin file in the SD card, and run the IAP upgrade program.
Previous article:STM32F105 USB pin Vbus processing
Next article:LPC11U14 implements SD card USB disk
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Practical sharing: The harm of Miller effect to MOSFET switching process
- Last day! Free review of Beetle ESP32-C3, hurry up and get it
- SVPWM principle, implementation, simulation analysis
- Why is the waveform of LM324 distorted?
- Answer the questions to win prizes | TDK special reports are waiting for you
- Today, People's Daily pushes information from the Ministry of Industry and Information Technology
- RK3399 development board Android image burning Windows system image burning
- TouchGFX Design Whack-a-Mole
- [Fudan Micro FM33LC046N Review] + Learning UART0 DMA Transmission and Reception
- What are the abbreviations of h and f in the small signal current amplification factor hfe?