- 在keil 5中先建立好工程,我使用的是STM32F103RC,device选择的有:
在keil的工具栏里面可以修改device:
- 工程建立完后如下:
- 测试函数如下:
#include "stm32f10x.h"
#include "stdio.h"
extern int add(int,int);
#include "test.h"
typedef struct student{
int age;
char *name;
struct student *classmate;
}Student,*pStudent;
int C = 0;
int main(void){
char *name1;
char *name2;
Student boy = {10,"xiaoming",NULL};
Student girl = {10,"xiaohong",NULL};
boy.classmate = &girl;
girl.classmate = &boy;
name1 = boy.classmate->name;
name2 = girl.classmate->name;
C = add(1,2);
printf("%s\n",name1);
printf("%s\n",name2);
return 0;
}
int add(int a,int b){
int c = a+b;
return c;
}
- 进行调试和仿真:
这里,需要配置调试选项: Target: Output: C/C++和asm:在Define处添加
DEBUG_ENABLE_SEMIHOST
C/C++的Optimization Level根据需要填写: Debug:选择仿真,并在CPU DLL处填写:
DARMSTM.dll
Parameter处填写STM型号
- 进入调试界面后,选择 View – Serial Windows - Debug (printf) Viewer,Watch Windows窗口添加Watch1,点击这个符号,全速运行:
结果如下: 在test.c文件中,可以将想要观察的变量add to 到Watch1窗口内,选中变量C右键有个add “C” to选项即可。 Debug (printf) Viewer调试窗口可以任意拖动。
|