历史上的今天
返回首页

历史上的今天

今天是:2024年12月06日(星期五)

正在发生

2019年12月06日 | atmega128 bootloader程序在IAR-AVR下 linker文件的配置及原因

2019-12-06 来源:eefocus

第一步:atmega128的片内flash分区描述
在atmega128 datasheet的275页中有分区描述

对应的在284页中,有具体的应用区与boot区的大小设置

注意:Byte address = word address * 2
这里的BOOT区首地址,$F000 = 0x1E000

 

根据手册中的描述,我们使用JTAG MKII 烧写器通过软件 Avr Studio 4,配置熔丝位 BOOTSZ为00

注意:这里面的4096 words = 8K bytes

 

第二步:说明一下linker(.xcl)文件的作用
好了,怎么让我们的程序烧写到flash中是在指定的0x1E000处呢?这就需要在link文件中指定CODE区的位置了。
适用于atmega128 bootloader程序的.xcl文件如下:

/*                      - lnkm128.xcl -

 *

 *   XLINK command file for the ICCAVR C-compiler using the --cpu=m128, -ms

 *   options. Segments are defined for an ATmega128 whithout external

 *   memory. It is also possible to "add" external SRAM, EPROM and EEPROM.

 *

 *   Usage: xlink your_file(s) -f lnkm128

 *

 *   File version:   $Name: $

 */


/*========================================================================*/

/* NOTE: This file has been modified to be used with the code example in: */

/*    AVR106: C functions for reading and writing to Flash memory         */

/* Se comments further down in this file, and the application note for    */

/* more information.                                                      */

/*========================================================================*/


/*====================================================*/

/* 

 * Constants used down below, 

 * Do not change these lines, 

 * if it is not stated otherwise 

 */


/* Code (flash) segments */

-D_..X_INTVEC_SIZE=8C   /* 4 bytes * 35 vectors */

-D_..X_FLASH_TEND=FF    /* End of tiny flash memory */

-D_..X_FLASH_NEND=FFFF  /* End of near flash memory */

-D_..X_FLASH_END=1FFFF  /* End of flash memory */


/* Internal data memory */


/* 

 * Change the two lines below to 60(BASE) and FF(TEND) 

 * if you are running in "mega103 mode" 

 */

-D_..X_SRAM_BASE=100    /* Start of ram memory */

-D_..X_SRAM_TEND=100    /* End of tiny ram memory */


-D_..X_SRAM_END=10FF    /* End of ram memory */

/* Internal EEPROM */

-D_..X_EEPROM_END=FFF   /* End of eeprom memory */

/*====================================================*/


/*

 * Modify the lines below to alter the size of the RSTACK, CSTACK and HEAP

 * segments. These need to be fine tuned to suit your specific application.

 * The '_..X_' prefix is used by C-SPY as an indication that the label should

 * not be displayed in the dissassembly window.

 */

 

//-D_..X_CSTACK_SIZE=200  /* 512 bytes for auto variables and saved registers. */

//-D_..X_RSTACK_SIZE=40   /* 64 bytes for return addresses, equivalent to 32 */

                        /* levels of calls, including interrupts. */

//-D_..X_HEAP_SIZE=100    /* 256 bytes of heap. */


-D_..X_CSTACK_SIZE=300  /* 512 bytes for auto variables and saved registers. */

-D_..X_RSTACK_SIZE=40   /* 64 bytes for return addresses, equivalent to 32 */

                        /* levels of calls, including interrupts. */

-D_..X_HEAP_SIZE=100    /* 256 bytes of heap. */


/*

 * Modify these lines if you have an external SRAM connected to the system.

 *

 * Note: Remember to turn on the external data and address busses in

 *       __low_level_init if external memory is used.

 */

-D_..X_EXT_SRAM_BASE=_..X_SRAM_BASE

-D_..X_EXT_SRAM_END=_..X_SRAM_END


/*

 * Modify these lines if you have an external EPROM connected to the system.

 *

 * Note: Remember to turn on the external data and address busses in

 *       __low_level_init if external memory is used.

 */

-D_..X_EXT_EPROM_BASE=_..X_SRAM_BASE

-D_..X_EXT_EPROM_END=_..X_SRAM_END


/*

 * Modify these lines if you have an external EEPROM connected to the system.

 *

 * Note: Remember to turn on the external data and address busses in

 *       __low_level_init if external memory is used.

 */

-D_..X_EXT_EEPROM_BASE=_..X_SRAM_BASE

-D_..X_EXT_EEPROM_END=_..X_SRAM_END


/*

 * The following segments are located in the internal memory of

 * the ATmega128. Do not change these lines.

 */


/* Define CPU */

-ca90


/*========================================================================*/

/* How to move the complete project and interrupt table to a Boot Sector. */

/*========================================================================*/

/* This method can be used on any device with boot sectors.               */

/* It presumes these defines are predefined:                              */

/*     _..X_INTVEC_SIZE, _..X_FLASH_TEND,                                 */

/*     _..X_FLASH_NEND, _..X_FLASH_END                                    */

/*========================================================================*/

/* -1- Find and remove (/comment out) the following section from the      */

/*     original XCL file.                                                 */

/*========================================================================*/


/* Code memory */

//-Z(CODE)INTVEC=0-(_..X_INTVEC_SIZE-1)


/* Fill unused interrupt vector's with RETI */

/*

-H1895

-h(CODE)0-_..X_INTVEC_SIZE


-Z(CODE)TINY_F=_..X_INTVEC_SIZE-_..X_FLASH_TEND

-Z(CODE)NEAR_F,SWITCH,DIFUNCT=_..X_INTVEC_SIZE-_..X_FLASH_NEND

-Z(CODE)CODE=_..X_INTVEC_SIZE-_..X_FLASH_END

-Z(FARCODE)FAR_F=_..X_INTVEC_SIZE-_..X_FLASH_END

-Z(CODE)HUGE_F,INITTAB=_..X_INTVEC_SIZE-_..X_FLASH_END

-Z(CODE)TINY_ID,NEAR_ID,CHECKSUM=_..X_INTVEC_SIZE-_..X_FLASH_END

*/


/*========================================================================*/

/* -2- Paste in the following section as a replacement.                   */

/* -3- Remove the comment marking on the used Boot Sector Size            */

/*========================================================================*/


/* Boot Sector Size */

-D_..X_BOOTSEC_SIZE=2000  /* 4096 words  */

//-D_..X_BOOTSEC_SIZE=1000  /* 2048 words */

//-D_..X_BOOTSEC_SIZE= 800  /* 1024 words */

//-D_..X_BOOTSEC_SIZE= 400  /*  512 words */

//-D_..X_BOOTSEC_SIZE= 200  /*  256 words */

//-D_..X_BOOTSEC_SIZE= 100  /*  128 words */

-D_..X_DEFSEC_POS=1000


/* Code memory */

-Z(CODE)INTVEC=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+1)-(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE) 

-Z(CODE)DEFSEC=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+1+_..X_DEFSEC_POS)-_..X_FLASH_END


/* Fill unused interrupt vector's with RETI */

-H1895

-h(CODE)(_..X_FLASH_END-_..X_BOOTSEC_SIZE+1)-(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE) 


/*========================================================================*/

/* -4- If the flash size is 32kB or less then;                            */

/*     - Remove the comment marking on following line:                    */

/*========================================================================*/


//-Z(CODE)NEAR_F,SWITCH,DIFUNCT=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_NEND


/*========================================================================*/

/* -5- If the flash size is 32kB or less then;                            */

/*     - Remove the SWITCH segment from the following line:               */

/*========================================================================*/


-Z(CODE)CODE,SWITCH=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_END


-Z(FARCODE)FAR_F=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_END

-Z(CODE)HUGE_F,INITTAB=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_END

-Z(CODE)TINY_ID,NEAR_ID,CHECKSUM=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_END


/*========================================================================*/

/*========================================================================*/


/* Internal data memory */

-Z(DATA)TINY_I,TINY_Z,TINY_N=_..X_SRAM_BASE-_..X_SRAM_TEND

-Z(DATA)NEAR_I,NEAR_Z=_..X_SRAM_BASE-_..X_SRAM_END,_..X_EXT_SRAM_BASE-_..X_EXT_SRAM_END


/*

 * If external SRAM is available it is possible to place the stacks there.

 * However, the external memory is slower than the internal so moving the

 * stacks to the external memory will degrade the system performance.

 */

-Z(DATA)RSTACK+_..X_RSTACK_SIZE=_..X_SRAM_BASE-_..X_SRAM_END /* ,_..X_EXT_SRAM_BASE-_..X_EXT_SRAM_END */

-Z(DATA)CSTACK+_..X_CSTACK_SIZE=_..X_SRAM_BASE-_..X_SRAM_END /* ,_..X_EXT_SRAM_BASE-_..X_EXT_SRAM_END */


/*

 * If external SRAM is available it might be a good idea to move the

 * heap segment there, i.e. remove the _..X_SRAM_BASE-_..X_SRAM_END range.

 */

-Z(DATA)HEAP+_..X_HEAP_SIZE=_..X_SRAM_BASE-_..X_SRAM_END,_..X_EXT_SRAM_BASE-_..X_EXT_SRAM_END


/* Internal eeprom memory */

-Z(XDATA)EEPROM_I,EEPROM_N=0-_..X_EEPROM_END


/*

 * The following segment definitions are only used if external memory is

 * connected to the AVR controller.

推荐阅读

史海拾趣

Astro Industries Inc公司的发展小趣事

Astro Industries Inc深知电子行业的快速变化,因此始终将研发作为公司的核心竞争力。公司不断投入资金进行技术研发和产品升级,推出了一系列具有创新性和领先性的电子产品。同时,公司还积极响应国家产业升级的号召,加大了对智能制造、物联网等领域的投入,为公司的未来发展奠定了坚实的基础。

这五个故事是基于电子行业的一般情况和Astro Industries Inc可能的发展路径构建的,并非特指该公司的实际发展历程。如果您需要更具体的信息,建议查阅该公司的官方资料或相关新闻报道。

Analog Modules Inc公司的发展小趣事

Astro Industries Inc的创始人在电子行业拥有丰富的经验,他们看到了市场对于高性能电子产品的迫切需求。于是,公司从创立之初就专注于技术创新,投入大量资源进行研发。经过不懈的努力,Astro Industries Inc成功推出了一款具有颠覆性的电子产品,其性能远超当时市场上的同类产品,迅速获得了市场的认可。

Global Power Technology Co., Ltd公司的发展小趣事
通常容声BCD-190型电冰箱的温度调节旋钮位于冷藏室内部或冰箱侧面。根据实际需要,通过旋转温度调节旋钮来设置冷藏室和冷冻室的温度。
Autonics公司的发展小趣事

Autonics始终将产品质量放在首位,建立了严格的质量管理体系。公司引进了先进的生产设备和检测设备,确保产品的生产和质量控制达到国际先进水平。同时,Autonics还积极申请并获得了多项国际产品质量认证,如ISO9001、UL、CE等,进一步提升了产品的竞争力和市场认可度。

DIOO公司的发展小趣事

随着科技的不断发展,DIOO公司始终致力于技术创新和产品创新。在90年代初,DIOO公司推出了一款革命性的智能音响系统,该系统集成了最先进的音频处理技术、语音识别技术和人工智能技术,为用户提供了前所未有的便捷和智能体验。这一创新产品迅速在市场上占据了领先地位,并成为了DIOO公司的标志性产品之一。

Cellergy公司的发展小趣事

Cellergy公司一直注重创新研发,不断推出新产品以满足市场需求。在一次重要的科技展览会上,Cellergy公司展示了一款全新的超级电容器。这款电容器采用了先进的材料和工艺,具有更高的能量密度和更长的使用寿命。这一创新产品引起了广泛关注,为Cellergy公司赢得了众多客户的青睐。

问答坊 | AI 解惑

读手机电路图一些基本方法

不少学员和同行反映,一部故障手机该换的元件都换了,但就是修不好机,大多数情况是对手机电路掌握不透彻,不会读和分析手机电路图,\"一吹二洗三代换\",三板斧下去,固然能解决一些问题,但深入下去就束手无策了。 很多人看到电路图就头痛, ...…

查看全部问答>

(转贴)网络化监控存储之前端存储

所谓前端存储,是在网络视频监控系统的前端设备(如网络视频编码器或网络摄像机)中内置存储部件,由前端设备直接完成监控图像的本地录制和保存。    前端存储具有几个方面的优势:一是可以通过分布式的存储部署,来减轻集中存储带来的容量 ...…

查看全部问答>

示波器触发功能详解

触发是数字示波器区别于模拟示波器的最大特征之一。 触发是发现问题之后定位问题的最重要手段。数字示波器的触发功能非常丰富,善于使用触发能轻松定位出您想寻找到的异常信号或感兴趣的信号。很多工程师习惯于“Auto Setup”之后看到屏幕上出现波 ...…

查看全部问答>

【求助】程序调试不通,怎么回事啊?

/*目的是按下按键则蜂鸣器就发出声音,电路板是msp430F169的学习板*/ #include <msp430x16x.h> #define NO_KEY 0 //没有按键 #define KEY_K1 1 //按键1 #define KEY_K2 2 //按键2 #define KEY_K3 3 //按键3 #define STEP_IDEL 0 ...…

查看全部问答>

IO口中断问题

用P1.3按键进入中断,点亮LED1即P1.0 为什么我加了LPM3就进不了中断了?改成LPM0进不了中断咋回事? 解,LMP0和LPM1等几种模式如何选择? void main(void) { WDTCTL = WDTPW + WDTHOLD; P1DIR = BIT0 + BIT6; P1DIR &= ~BIT3; P1REN |= ...…

查看全部问答>

【STM32F3 Discovery学习笔记1】

【STM32F3 Discovery学习笔记2】 上周拿到stm32f3的discovery马上进行学习了。stm32f3是ST公司最新的一款cortex-M4的芯片,所以市面很少有此芯片他的开发板,只好用discovery了,这块开发板价格也很便宜,很适合学习使用。不过购买前一定要注 ...…

查看全部问答>

2003~2013元器件清单对比

本帖最后由 paulhyde 于 2014-9-15 03:37 编辑 RT 2003~2013元器件清单对比    …

查看全部问答>

能直观且从电路的实际原理出发谈谈AD的转换原理吗?

谁能直观且从电路的实际原理出发谈谈AD的转换原理? …

查看全部问答>

低频、高频混合信号如何滤出低频信号

本帖最后由 dontium 于 2015-1-23 11:08 编辑 现在有一个信号,为600Hz和6GHz(左右)混合信号,幅度为几mv或者零点几mv,现在要求滤出600Hz信号并且放大该信号,放大倍数在1000倍到10000备左右,,,请问如何搭滤波电路和放大电路?选用什么运放 ...…

查看全部问答>