0

我是 C 和 CodeWarrior 嵌入式编程的新手,我想知道是否有人可以帮助我解决我的问题。似乎当我去构建我的项目时,我得到了某种链接器错误,如下所示:

**** Build of configuration FLASH for project test ****

"C:\\Freescale\\CW MCU v10.6\\gnu\\bin\\mingw32-make" -j12 all 
'Building target: test.elf'
'Executing target #9 test.elf'
'Invoking: ColdFire Linker'
"C:/Freescale/CW MCU v10.6/MCU/ColdFire_Tools/Command_Line_Tools/mwldmcf" -o "test.elf" @@"test.args"   
C:/Freescale/CW MCU v10.6/MCU/ColdFire_Tools/Command_Line_Tools/mwldmcf|Linker|Error
>Undefined : "tFlag"
>Referenced from "TI1_OnInterrupt" in
mingw32-make: *** [test.elf] Error 1
C:/Freescale/CW MCU v10.6/MCU/ColdFire_Tools/Command_Line_Tools/mwldmcf|Linker|Error
>Link failed. 

我正在使用带有 MCF51EM 系列微控制器的 DEMOEM 板。任何建议将不胜感激。

谢谢,

泰勒

4

3 回答 3

3

您缺少 C 语言范围概念。您定义的 tFlag 变量是主函数中的局部变量。它分配在主函数堆栈内存中,只有主函数可以通过它的名称看到它。解决这个问题需要将 tFlag 定义为包含 main 函数的文件中的全局变量,并在包含 TI1_OnInterrupt 函数的文件中将其外部化。您可以在此链接中找到有关 C 变量范围的更多信息,以及有关存储类(extern 就是其中之一)在此链接中的更多信息。

于 2014-11-22T00:16:36.773 回答
2

您应该检查函数 TI1_OnInterrupt。
此函数使用变量 tFlag,搜索此变量,它在某处声明为
extern int tFlag;

但似乎缺少定义。
您需要添加
ìnt tFlag;

从您发布的代码中:

void main(void)
{
  bool tFlag = FALSE;
...

tFlag变量仅在 main() 中可见。
你应该把它移到函数之外

于 2014-11-20T07:43:54.820 回答
0

我相信我做得对。这是我拥有的源代码。

主.c:

/* ###################################################################
**     Filename    : main.c
**     Project     : test
**     Processor   : MCF51EM256CLL
**     Version     : Driver 01.00
**     Compiler    : CodeWarrior ColdFireV1 C Compiler
**     Date/Time   : 2014-11-19, 17:54, # CodeGen: 0
**     Abstract    :
**         Main module.
**         This module contains user's application code.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.00
** @brief
**         Main module.
**         This module contains user's application code.
*/         
/*!
**  @addtogroup main_module main module documentation
**  @{
*/         
/* MODULE main */


/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "Bit1.h"
#include "TI1.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

/* User includes (#include below this line is not maintained by Processor Expert) */

void main(void)
{
  bool tFlag = FALSE;

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  for(;;)
  {
      if(tFlag == TRUE)
      {
          Bit1_NegVal();
          tFlag = FALSE;
      }
  }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.3 [05.09]
**     for the Freescale ColdFireV1 series of microcontrollers.
**
** ###################################################################
*/

和 events.c:

/* ###################################################################
**     Filename    : Events.c
**     Project     : test
**     Processor   : MCF51EM256CLL
**     Component   : Events
**     Version     : Driver 01.02
**     Compiler    : CodeWarrior ColdFireV1 C Compiler
**     Date/Time   : 2014-11-19, 17:54, # CodeGen: 0
**     Abstract    :
**         This is user's event module.
**         Put your event handler code here.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file Events.c
** @version 01.02
** @brief
**         This is user's event module.
**         Put your event handler code here.
*/         
/*!
**  @addtogroup Events_module Events module documentation
**  @{
*/         
/* MODULE Events */

#include "Cpu.h"
#include "Events.h"

/* User includes (#include below this line is not maintained by Processor Expert) */

/*
** ===================================================================
**     Event       :  TI1_OnInterrupt (module Events)
**
**     Component   :  TI1 [TimerInt]
**     Description :
**         When a timer interrupt occurs this event is called (only
**         when the component is enabled - <Enable> and the events are
**         enabled - <EnableEvent>). This event is enabled only if a
**         <interrupt service/event> is enabled.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/

void TI1_OnInterrupt(void)
{
  extern bool tFlag;

  tFlag = TRUE;

}

/* END Events */

/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.3 [05.09]
**     for the Freescale ColdFireV1 series of microcontrollers.
**
** ###################################################################
*/

我觉得我错过了一些简单的东西。感谢你的回复!

于 2014-11-20T15:52:47.660 回答