Reminder: This article is a coursework, there are many shortcomings
Article Directory
1. Use Vscode to visualize c/c++ code tracking and debugging
1. Install Vscode
PS: The following is my own installation method. For more detailed reference, please refer to the tutorial on installing vscode under ubuntu18.04
1. Download the Vscode installation package on the official website
Choose .deb for Ubuntu
2. Copy the downloaded installation package to the virtual machine
3. Install Vscode
input code (the name of the installation package is different, please pay attention to your own installation package name)
sudo dpkg -i code_1.51.0-1604600753_amd64.deb
Enter code to open
code
4. Extension Installation
input code into the
Click the red circle icon on the left, enter the Chinese, Simplified Chinese language pack installation
input c ++, installation c / c ++ extensions
2. Configure and debug the c/c++ environment of Vscode
Create test.c file
touch test.c
gedit test.c
The test.c code is as follows:
#include<stdio.h>
int main()
{
printf("hello world\n");
return 0;
}
Click F5 to debug (generate launch.json, tasks.json files)
launch.json is as follows:
"version": "0.2.0",
"configurations": [
{
"name": "gcc - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false, //选为true则会在打开控制台后停滞,暂时不执行程序
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false, //true为使用外部工作台,会额外打开一个终端显示程序运行结果,false使用vscode自带的工作台
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json is as follows:
{
"tasks": [
{
"type": "cppbuild", //配置为cppbuild将会生成的文件放到根目录下,而改为shell会生成到当前目录下
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
}
],
"version": "2.0.0"
}
You can see that launch.json and tasks.json generally do not need to be changed. If the program needs it, you can change the cppbuild in tasks.json to shell
Two, Proteus simulation STM32 water lamp experiment routine
Reference blog: 1, Proteus simulation STM32 water lamp experimental routines, detailed steps.
1. Write the code The
code is as follows:
#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;
}
}
}
Check Create HEX File
and run the program to generate HEX file
2. Create a new project
Choose to create a firmware project here, choose Cortex-M3 for the series, and STM32F103R6 for the second
. 3. Configure the components and draw the circuit diagram.
Three components are needed. The resistance of the resistor needs to be reset, about 50 ohms.
4. Simulation
Use Altium Designer software to draw a circuit schematic diagram of the smallest stm32 system
Three, use Altium Designer software to draw a circuit schematic diagram of the smallest system of stm32
Process diagram:
The final picture is as follows: