|
发表于 2012-8-1 22:04:02
|
显示全部楼层
本帖最后由 Gorgon_Meducer 于 2012-8-1 22:06 编辑
Gorgon_Meducer 发表于 2012-8-1 22:01 ![](static/image/common/back.gif)
我之前做过很多努力,无法通过绝对定位的方法将数据放到高64K。但是你可以通过修改HEX文件的方法将原本定 ...
这段经过检验的代码应该能给你启示,ICC下的
- #if BL_USE_PAGE_VERIFY == ENABLE
- /***********************************************************
- * 函数说明: 页面校验函数 *
- * 输入: 源页面缓冲区,目标地址 *
- * 输出: 校验是否成功 *
- * 调用函数: 无 *
- ***********************************************************/
- BOOL Bootloader_Flash_Page_Verify
- (
- BYTE *pchDataBuffer,
- #if BL_USE_EXTEND_ADDRESS_SPACE == ENABLE
- UINT32 dwAddress
- #else
- UINT16 wAddress
- #endif
- )
- {
- UINT16 wCounter = FLASH_PAGE_SIZE;
- UINT8 chDataA;
- UINT8 chDataB;
-
- #if BL_USE_EXTEND_ADDRESS_SPACE == ENABLE
- UINT8 TRAMPZ = RAMPZ;
- #endif
- if (pchDataBuffer == NULL)
- {
- //! have nothing to do with...
- return FALSE;
- }
- #if BL_USE_EXTEND_ADDRESS_SPACE == ENABLE
- RAMPZ = dwAddress >> 16;
- #endif
- //! load the address to z register
- asm("movw r30,r18");
- //! load the buffer address to x register
- asm("movw r26,r16");
- #if BL_USE_EXTEND_ADDRESS_SPACE == ENABLE
- if (RAMPZ)
- {
- while(wCounter--)
- {
- //! load a byte from flash (addressed by z register)
- asm("elpm r0,z+");
- //! employ a temporary variable chDataA
- asm("mov %chDataA,r0");
- //! load a byte from sram (addressed by x register)
- asm("ld r0,x+");
- //! employ a temporary variable chDataB
- asm("mov %chDataB,r0");
- //! checking...
- if (chDataA != chDataB)
- {
- RAMPZ = TRAMPZ;
- return FALSE;
- }
- WDR();
- }
- }
- else
- {
- while(wCounter--)
- {
- //! load a byte from flash (addressed by z register)
- asm("lpm r0,z+");
- //! employ a temporary variable chDataA
- asm("mov %chDataA,r0");
- //! load a byte from sram (addressed by x register)
- asm("ld r0,x+");
- //! employ a temporary variable chDataB
- asm("mov %chDataB,r0");
- //! checking...
- if (chDataA != chDataB)
- {
- RAMPZ = TRAMPZ;
- return FALSE;
- }
- WDR();
- }
- }
- RAMPZ = TRAMPZ;
- #else
- while(wCounter--)
- {
- //! load a byte from flash (addressed by z register)
- asm("lpm r0,z+");
- //! employ a temporary variable chDataA
- asm("mov %chDataA,r0");
- //! load a byte from sram (addressed by x register)
- asm("ld r0,x+");
- //! employ a temporary variable chDataB
- asm("mov %chDataB,r0");
- //! checking...
- if (chDataA != chDataB)
- {
- return FALSE;
- }
- }
- #endif
- return TRUE;
- }
- #endif
复制代码 这是一段ICC里面读取任意Flash并通过串口发送出来的代码- #if IAP_ENABLE_FLASH_READ == ENABLE
- else if (chMemoryType == IAP_MEM_TYPE_FLASH)
- {
- UINT8 chData = FRAME_HEAD;
- UINT16 wCRC = CRC_INIT;
- #if BL_USE_EXTEND_ADDRESS_SPACE == ENABLE
- UINT16 wCounter = wSize;
- UINT32 dwAddressCounter = dwAddress;
- UINT8 chTempRAMPZ;
- #else
- UINT16 wCounter = wSize;
- #endif
- wSize++;
- CRC(wCRC,((BYTE *)&wSize)[0])
- CRC(wCRC,((BYTE *)&wSize)[1])
- CRC(wCRC,IAP_CMD_READ_MEMORY)
-
- while(!SERIAL_OUT(chData)); //发送头部
- while(!SERIAL_OUT(wSize)); //发送数据包长度
- chData = IAP_CMD_READ_MEMORY;
- while(!SERIAL_OUT(chData)); //发送指令
-
-
- #if BL_USE_EXTEND_ADDRESS_SPACE == ENABLE
- chTempRAMPZ = RAMPZ;
- while(wCounter--)
- {
- UINT16 wAddress = dwAddressCounter;
- RAMPZ = dwAddressCounter >> 16;
- asm("movw r30,%wAddress");
- asm("elpm r24,z");
- asm("std Y+6,r24");
- while(!SERIAL_OUT(chData));
- CRC(wCRC,chData);
- dwAddressCounter++;
-
- WDR();
- }
- RAMPZ = chTempRAMPZ;
- #else
- //开始发送数据
- asm("movw r30,%wAddress");
- while(wCounter--)
- {
- asm("lpm r24,z+");
- asm("std Y+6,r24");
- while(!SERIAL_OUT(chData));
- WDR();
- CRC(wCRC,chData)
- }
- #endif
复制代码 |
|