IAR怎么在启动程序里面添加关闭看门狗代码

bandaoyu 2012-05-17 03:19:30
IAR怎么在启动程序里面添加关闭看门狗代码
看网上的资料教这么做:
解决办法:

方法一 将一些变量(主要是大全局数组)定义成 no init类型
方法二 修改IAR的cstartup.s43程序,具体方法如下:(iar310a为例)
1 将cstartup.s43程序加载到用户自己的项目中,cstartup.s43在iar310a的路径如下$TOOLKIT_DIR$\src\LIB\
2 修改cstartup.s43中的__program_start子程序,加入关闭看门狗的命令 MOV #0x5A80,&0x0120
3 在Project->Options->Linker->Config页中选择Override default programe ,并将Entry lib 设置成 __program_start

按照上面的指示:我在文件中加入:MOV.W #WDTPW+WDTHOLD , &WDTCTL
(也尝试过,在我的工程中添加#define DISABLE_WATCHDOG 语句,均无效果;也尝试过,直接注释掉调件编译,让其直接编译,也没有效果:
//#ifdef DISABLE_WATCHDOG
MOV #WDTPW + WDTHOLD, &WDTCTL
//#endif


但是我的IAR 是6.0版的,我用的是MSP430,没有看到Entry lib ,取而代之的是Entry symb 所以我选择了 Entry symb :__program_start





但是没有任何效果,什么原因??


cstartup.s43文件内容:
/**************************************************
*
* System initialization code for the MSP430 IAR C/EC++ Compiler.
*
* Copyright ?2002-2008 IAR Systems AB.
*
* $Revision: 5271 $
*
**************************************************/

//
// There are two libraries provided with compilers from IAR Systems,
// CLib and DLib. This file is designed to work with both libraries.
// Some parts of it is DLib-specific. However, those parts will not
// be included when building an application using CLib.
//

//
// Please define one of the following preprocessor symbols in order to
// customize the system initialization process.
//
// IGNORE_SEG_INIT -- To remove segment initialization
// IGNORE_DATA16_DATA -- To remove segment initialization of DATA16 data
// IGNORE_DATA20_DATA -- To remove segment initialization of DATA20 data
// IGNORE_RAMFUNC_INIT -- To remove segment initialization of ramfunc code
// DISABLE_WATCHDOG -- To disable the watchdog
//
// Note: In the current version the symbols "IGNORE_SEG_INIT" and
// "IGNORE_DATA16_DATA" will perform the same task. However, both are
// supported in order to be compatible with other IAR Compilers.
//
// Note: To disable the watchdog, a device-specific header file will
// be included.
//

#include "macros.m43"
#include "cfi.m43"

#ifdef DISABLE_WATCHDOG
#include "msp430.h"
#endif


#define XRSEGCSTART RSEG CSTART:CODE:NOROOT(1)

XCFI_NAMES libNames
XCFI_COMMON libCommon, libNames


// ---------------------------------------------------------
// The cstartup code -- call __low_level_init, perform initialization,
// call constructors and call main. If main returns the exit system
// is started.
//

MODULE ?cstart

//
// Ensure that this is build with the same "positions independent
// code" settings as the compiler uses.
//

XPICRTMODEL


//
// Forward declarations of segments.
//

RSEG HEAP:DATA:NOROOT(1)
RSEG CSTACK:DATA:NOROOT

RSEG DATA16_Z:DATA:NOROOT
RSEG DATA16_I:DATA:NOROOT
RSEG DATA16_ID:CONST:NOROOT
RSEG CODE_I:DATA:NOROOT
RSEG CODE_ID:CONST:NOROOT
#if __CORE__==__430X_CORE__
RSEG DATA20_Z:DATA:NOROOT
RSEG DATA20_I:DATA:NOROOT
RSEG DATA20_ID:CONST:NOROOT
#endif

// ---------------------------------------------------------
// System initialization.
//

XRSEGCSTART
PUBLIC __program_start

EXTERN ?reset_vector
REQUIRE ?reset_vector

__program_start:

PUBLIC ?cstart_begin
?cstart_begin:

// --------------------
// Turn off the watchdog.
//
// Note: This is excluded by default. Please define
// DISABLE_WATCHDOG to include it.
//

#ifdef DISABLE_WATCHDOG

MOV #WDTPW + WDTHOLD, &WDTCTL
#endif

// --------------------
// Initialize SP to point to the top of the stack.
//
MOV.W #WDTPW+WDTHOLD , &WDTCTL MOV #SFE(CSTACK), SP

//
// Ensure that main is called.
//
REQUIRE ?cstart_call_main


// -----------------------------------------------
// Call __low_level_init to perform initialization before initializing
// segments and calling main. If the function returns 0 no segment
// initialization should take place.
//
// Link with your own version of __low_level_init to override the
// default action: to do nothing but return 1.
//

XRSEGCSTART

PUBLIC ?cstart_call_low_level_init
EXTERN __low_level_init

?cstart_call_low_level_init:
XCALL #__low_level_init
CMP #0, W0
JEQ ?cstart_call_main


// -----------------------------------------------
// Segment initialization:
//
// xxx_Z -- uninitialized data that are filled with zeros.
// xxx_I -- initialized data that gets the values from the corresponding
// xxx_ID segment.
//

#ifndef IGNORE_SEG_INIT


// --------------------
// Initialize code for __ramfunc functions.
//

XRSEGCSTART
PUBLIC ?cstart_init_copy_ramfunc

?cstart_init_copy_ramfunc:

#ifndef IGNORE_RAMFUNC_INIT

#ifndef REGISTER_MODEL_REG20

MOV #SFB CODE_I, CW0
MOV #SFB CODE_ID, CW1

MOV #sizeof CODE_I, CW2

XCALL #__data16_memcpy

#else // MSP430X with 20 bit pointers.

EXTERN __data20_memcpy

MOVA #SFB CODE_I, CW0
MOVA #SFB CODE_ID, CW1
MOV.W #LWRD(sizeof CODE_I), L1L
MOV.W #HWRD(sizeof CODE_I), L1H

XCALL #__data20_memcpy


#endif // REGISTER_MODEL_REG20

#endif // IGNORE_RAMFUNC_INIT


// --------------------
// Initialize data16
//

#ifndef IGNORE_DATA16_DATA

//
// Clear DATA16_Z.
//

XRSEGCSTART
PUBLIC ?cstart_init_zero
EXTERN __data16_memzero

?cstart_init_zero:
MOV #SFB DATA16_Z, CW0
MOV #sizeof DATA16_Z, CW1

XCALL #__data16_memzero


//
// Copy DATA16_ID to DATA16_I
//

XRSEGCSTART
PUBLIC ?cstart_init_copy
EXTERN __data16_memcpy

?cstart_init_copy:
MOV #SFB DATA16_I, CW0
MOV #SFB DATA16_ID, CW1

MOV #sizeof DATA16_I, CW2

XCALL #__data16_memcpy

#endif // IGNORE_DATA16_DATA


// --------------------
// Data20
//

#if __CORE__==__430X_CORE__


#ifndef IGNORE_DATA20_DATA

//
// Clear DATA20_Z.
//

XRSEGCSTART
PUBLIC ?cstart_init_zero20
EXTERN __data20_memzero

?cstart_init_zero20:
MOVA #SFB DATA20_Z,W0
MOV.W #LWRD(sizeof DATA20_Z), L1L
MOV.W #HWRD(sizeof DATA20_Z), L1H

XCALL #__data20_memzero


//
// Copy DATA20_ID to DATA20_I
//

XRSEGCSTART
PUBLIC ?cstart_init_copy20
EXTERN __data20_memcpy

?cstart_init_copy20:
MOVA #SFB DATA20_I, CW0
MOVA #SFB DATA20_ID, CW1
MOV.W #LWRD(sizeof DATA20_I), L1L
MOV.W #HWRD(sizeof DATA20_I), L1H

XCALL #__data20_memcpy

#endif // IGNORE_DATA16_DATA

#endif // MSP430X

#endif // IGNORE_SEG_INIT



// -----------------------------------------------
// Call constructors of static objects.
//

RSEG DIFUNCT:CONST:NOROOT(1)
XRSEGCSTART
PUBLIC ?cstart_call_ctors

EXTERN __call_ctors

?cstart_call_ctors:

#ifdef REGISTER_MODEL_REG20

MOVA #SFB DIFUNCT, CW0
MOVA #SFE DIFUNCT, CW1

#else /* REGISTER_MODEL_REG20 */

MOV.W #SFB DIFUNCT, CW0
MOV.W #SFE DIFUNCT, CW1

#endif /* REGISTER_MODEL_REG20 */

XCALL #__call_ctors


// -----------------------------------------------
// Call main() with no arguments and then exit using the return value
// of main as the parameter.
//

XRSEGCSTART
PUBLIC ?cstart_call_main

EXTERN main
EXTERN exit

?cstart_call_main:
XCALL #main
XCALL #exit

PUBLIC ?cstart_end
?cstart_end:

// Note: "ENDMOD label" means code that this module is the
// start of the application.
ENDMOD __program_start




// ---------------------------------------------------------
// __low_level_init
//
// The only action of this default version of __low_level_init is to
// return 1. By doing so it signals that normal initialization of data
// segments should be done.
//
// A customized version of __low_level_init may be created in order to
// perform initialization before initializing segments and calling main
// and/or to skip initialization of data segments under certain
// circumstances.
//
// For further details see sample file lowinit.c
//


MODULE lowinit

PUBLIC __low_level_init

RSEG CODE:CODE:NOROOT(1)

__low_level_init:
MOV #1, W0 // By returning 1 this function
XRET // indicates that the normal
// initialization should take place

ENDMOD


// ---------------------------------------------------------
// Define reset vector.
//

MODULE ?reset_vector

RSEG RESET:CONST:NOROOT(1)
PUBLIC ?reset_vector
EXTERN __program_start

?reset_vector:
DC16 __program_start

ENDMOD

END
...全文
958 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tsummer2010 2014-06-15
  • 打赏
  • 举报
回复
main函数中添加这个函数即可,不用修改启动文件 int __low_level_init(void) { /* Insert your low-level initializations here */ // stop WDT WDTCTL = WDTPW + WDTHOLD; /* * Return value: * * 1 - Perform data segment initialization. * 0 - Skip data segment initialization. */ return 1; }
z1heldign 2013-11-14
  • 打赏
  • 举报
回复
请问怎么解决的? 同样问题,谢谢
lib6303c 2013-09-04
  • 打赏
  • 举报
回复
也碰到同样的问题,试试!再请教!cstartup.s43里的 EXTERN __data16_memzero的这个函数怎么定义的?好像在外面定义的,我想修改他的地址(重新定位到其他地方?比如1100-1FFF)
frozenwolf 2013-08-02
  • 打赏
  • 举报
回复
贴个可行的解决方法。 1:最好将拷一个cstartup.s43,把只读属性去掉,一定要加载到用户自己的项目工程中,文件开头加上 #define DISABLE_WATCHDOG 就行了。 2:在Project->Options->Linker->Config页中选择Override default programe ,并将Entry symb 设置 成 __program_start。 3:把debugger->setup->Run to main销掉,目的只是为了单步调试时看的更清楚。 4:调试一下。 网上找的
frozenwolf 2013-08-02
  • 打赏
  • 举报
回复
不知道楼主是怎么解决问题的啊,我也碰到了相同的的问题。好像改了cstartup.s43,里面的代码没有执行。
zhaohuijing 2012-07-12
  • 打赏
  • 举报
回复
敢问楼主是怎么解决的。。相同的问题。。求助高手啊!!
bandaoyu 2012-05-21
  • 打赏
  • 举报
回复
你们的水平有待提高,不过还是很谢谢。我自己解决了
bandaoyu 2012-05-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
在main程序给数组初始化不行吗?
[/Quote]
晕死!上面不是已经说了,进不了main吗,还在main里面初始化,晕死。
“因为我里面有大数组,上电后先经过编译器的启动程序,启动程序给数组初始化,超过看门狗的默认时间,就重启了,进不了mian里面,所以main里面的关闭看门狗没有。不信你设一个很大很大的数组试试,包你下进去了跑不了”

你可以做个试验,就是定义一组很大很大的数组,然后载进去你就知道怎么回事了,到时候你就知道我这个问题的意义了,所以你也去看看怎么在启动程序内加关看门狗吧,一起解决
aydf1 2012-05-17
  • 打赏
  • 举报
回复
在main程序给数组初始化不行吗?
bandaoyu 2012-05-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
重来都是上电后在main里首先关狗

不知道LZ为神马不能接受这种很传统的应用方式

:)
[/Quote]

因为我里面有大数组,上电后先经过编译器的启动程序,启动程序给数组初始化,超过看门狗的默认时间,就重启了,进不了mian里面,所以main里面的关闭看门狗没有。不信你设一个很大很大的数组试试,包你下进去了跑不了
lbing7 2012-05-17
  • 打赏
  • 举报
回复
重来都是上电后在main里首先关狗

不知道LZ为神马不能接受这种很传统的应用方式

:)

27,375

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧