- 在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调试窗口可以任意拖动。


本文详细介绍了如何在Keil5环境下为STM32F103RC建立工程,包括设备选择、调试选项配置、代码编写以及使用printf调试。通过创建学生结构体并进行指针操作,展示了C语言的基本运用,并利用Debug(printf)Viewer窗口进行变量观察,实现了串口输出。

436

被折叠的 条评论
为什么被折叠?



