当前位置:网站首页>Emulate stm32 directly with proteus - the programmer can be completely discarded
Emulate stm32 directly with proteus - the programmer can be completely discarded
2022-08-10 11:08:00 【Hexi stone】
stm32经济实惠,But its use is not as goodarduinoso convenient,Always get a downloaderst-linkOr have one toousb转ttl的ch34或者lp2002converter is connected,一个“痣”,麻烦!
stm32It is used very frequently in many small projects,Perhaps many people's embedded entry starts fromstm32开始,Here we take a look atproteushow to simulate.
对于初学者而言,We still want to be moreproteusIt's better to simulate it,No need to sell hardware,No need to buy a downloader, etc.Below we describe how to do it!
一、在prtoteusDraw a schematic diagram

我们做一个blink程序,Simple is simpler,But ok,容易看明白
二、写代码
#include "stm32f1xx_hal.h"
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
HAL_GPIO_TogglePin(Ld2_GPIO_Port, Ld2_Pin); //Toggle LED
HAL_Delay(1000); //Delay 1 Seconds
}
}
/** System Clock Configuration */
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|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_PIN_8
|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12
|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = Ld2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(Ld2_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10
|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
__HAL_AFIO_REMAP_PD01_ENABLE();
HAL_GPIO_WritePin(Ld2_GPIO_Port, Ld2_Pin, GPIO_PIN_RESET);
}
void Error_Handler(void)
{
while(1)
{
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
}
#endif
三、编译与运行
At first we may encounter compiler errors
The selected compiler ‘GCC for ARM’ is not installed.
Compilation failed. Check the Project Settings.
1、安装编译器
点击对GCC for arm后的download,It will pop up after the detection is completeYaGArto的安装界面,Continue to check after installation
Downloaded and stored in proteus的安装目录下的data的downloads下

2、配置编译器
安装好后,再次点击downloadIt will automatically install just nowyagarto配置进来,或者点击下面的check也可以
运行效果

It's often difficult to start things off,The difficulty of embedded development lies in the construction of the environment,There are many children's shoes that are just beginning to die on the way of environmental configuration,Difficulty in that stringhello world,The difficulty lies in the flickering oneLED灯blink程序.
I hope this blog post will help you replay the stumbling block of this starting point,从此一帆风顺~~
边栏推荐
猜你喜欢

Situation丨The intrusion of hackers intensifies, and the shooting range sets up a "defense shield" for network security

leetcode:334. 递增的三元子序列

Redis(三)——配置文件详解、发布和订阅、新数据类型

ISO9001在讲什么?过程方法和风险思维

什么是抽象类

让软件飞——“X+”技术揭秘

Several small projects that I have open sourced over the years

1-IMU参数解析以及选择

商城限时秒杀功能系统

Get started quickly and conquer three different distributed architecture calling schemes
随机推荐
"Data Strategy" Results-Driven Enterprise Data Strategy: Organization and Governance
什么是抽象类
【C语言】头文件#include <conio.h>,conio是Console Input/Output(控制台输入输出)
OneFlow源码解析:算子指令在虚拟机中的执行
网络文化经营许可证
1-IMU参数解析以及选择
leetcode:334. 递增的三元子序列
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
关于json转换器缺失的问题,报错内容:No converter found for return value of type
Dialogue with Chen Ciliang: Nezha wants to popularize high-end products
"Scalability" extensibility best practices: lessons from eBay
【C语言】浮点数四舍五入
短视频软件开发——平台同质化如何破局
EasyCVR级联时,修改下级平台名称将不同步至上级平台
mysql5.7 installation and deployment - yum installation
2022.8.7-----leetcode.636
AUTOCAD——减少样条曲线控制点数、CAD进阶练习(三)
使用cpolar远程连接群晖NAS(升级固定链接2)
MongoDB数据库笔记
越折腾越好用的 3 款开源 APP