一、可视化代码跟踪调试–基于跨平台多类型代码编辑器VScode
1、官网下载VScode,然后解压。
2、打开VScode,安装c++插件。
3、使用VScode。
ctrl+o打开一个文件夹,然后新建一个文件。
自动生成的lanch.json文件:
修改后的lanch.json文件:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
自动生成的task.json文件:
修改后的task.json文件:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-std=c++11",
"-o",
"${fileBasenameNoExtension}.out"
]
}
]
}
最后只需设置断点进行调试。
二、Proteus仿真运行stm32程序
1、打开Proteus,创建一个新工程。
选择STM32F103R6芯片
选择相关的元件
添加完之后:
在keil中新建工程,写入代码:
#include "stm32f10x.h"
GPIO_InitTypeDef GPIO_InitStructure;
void delay_ms(uint32_t ms)
{
uint32_t i_cnt,j_cnt;
for(i_cnt=0;i_cnt<3000;i_cnt++);
for(j_cnt=0;j_cnt<ms;j_cnt++);
}
uint32_t i;
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIOC->BSRR=0xff;
while (1)
{
for(i=0;i<8;i++)
{
delay_ms(99000);
GPIOC->BRR=(1<<i);
delay_ms(99000);
GPIOC->BSRR=(1<<i);
}
for(i=0;i<8;i++)
{
delay_ms(99000);
GPIOC->BRR=0x000000ff;
delay_ms(99000);
GPIOC->BSRR=0x000000ff;
}
}
}