Visual code tracking debugging and Proteus simulation run stm32 program and Altium Designer to draw a stm32 minimum system

Reminder: This article is a coursework, there are many shortcomings



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

Download address portal

Insert picture description here
Choose .deb for Ubuntu

2. Copy the downloaded installation package to the virtual machine

Insert picture description here
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

Insert picture description here
Enter code to open

code

4. Extension Installation
input code into the
Insert picture description here
Click the red circle icon on the left, enter the Chinese, Simplified Chinese language pack installation
Insert picture description here
input c ++, installation c / c ++ extensions
Insert picture description here
Insert picture description here

2. Configure and debug the c/c++ environment of Vscode

Create test.c file

touch test.c
gedit test.c

Insert picture description here

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)
Insert picture description here
Insert picture description here

Insert picture description here

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
Insert picture description here
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
Insert picture description here
and run the program to generate HEX file
2. Create a new project
Insert picture description here

Insert picture description here
Insert picture description here
Choose to create a firmware project here, choose Cortex-M3 for the series, and STM32F103R6 for the second
Insert picture description here
. 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.
Insert picture description here
Insert picture description here

Insert picture description here
4. Simulation
Insert picture description here
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

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Process diagram:
Insert picture description here

The final picture is as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/aiwr_/article/details/109547080