当前位置:网站首页>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,从此一帆风顺~~
边栏推荐
- 第5章相似矩阵及二次型(4)
- [Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)
- FastReport.Net 2022.2.17 Crack
- How can an organization judge the success of data governance?
- 3 injured in 'electrical accident' at Google data center
- In August the DB list latest scores - database Engines
- bus事件总线 使用
- runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
- STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建
- 短视频软件开发——平台同质化如何破局
猜你喜欢

Cybersecurity Notes 5 - Digital Signatures

STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建

Mobile and PC compatible loading and toast message plugins

Automated Testing and Selenium

"Time Series Database" uses cassandra to scan time series data

Dalian University of Technology & Pengcheng & UAE propose a mixed-scale triple network ZoomNet for camouflaged target detection, with SOTA performance!

MongoDB database notes

3D旋转文本动画js特效

ESP8266 Tutorial 2 - Burn AT Firmware

【Azure云】服务端点和私有链接有什么区别?观点(1)
随机推荐
Summary of whitespace, space and escape characters in C language
「业务架构」介绍BPMN第二部分-泳道
2022.8.9-----leetcode.1413
8月份DB-Engines 数据库排行榜最新战况
干货!ASSANet:让PointNet++更快更强
"Time Series Database" uses cassandra to scan time series data
ZZULIOJ 1124: 两个有序数组合并
从产品维度来看 我们为什么不能完全信任Layer2?
mysql5.7安装部署-yum安装
owl.carousel poster card Slider carousel switch
Mobile and PC compatible loading and toast message plugins
Store limited time seckill function system
STM32 encapsulation ESP8266 a key configuration function: implementations of AP mode and the STA mode switch, server and the client to create
金九银十跳槽旺季:阿里、百度、京东、美团等技术面试题及答案
第2章-矩阵及其运算-矩阵运算(2)
What is affecting MySQL performance?
网络安全笔记5——数字签名
Load balancing principle analysis and source code interpretation
【知识论概念】《理由论的进展》鲁汶大学2022最新220页博士论文
PPT | 「课件」企业中高层人员安全管理培训(118页)