当前位置:网站首页>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,从此一帆风顺~~
边栏推荐
- 干货!ASSANet:让PointNet++更快更强
- 「首席工程师」首席(Principal )工程师修炼之道
- Short video software development - how to break the platform homogenization
- 商城限时秒杀功能系统
- getParameter()与 getAttribute()的用法与区别
- Mobile and PC compatible loading and toast message plugins
- Redis6 (1) - Introduction to NoSQL Database and Installation of Redis
- 突破次元壁垒,让身边的玩偶手办在屏幕上动起来!
- PTA 7-2 方阵对角线元素求和及计数 题解
- "Chief Engineer" Principal (Principal) engineer's way of training
猜你喜欢
【知识论概念】《理由论的进展》鲁汶大学2022最新220页博士论文
js guessing game source code
String interception function in SQL
快速上手,征服三种不同分布式架构调用方案
兼容移动和PC的loading加载和toast消息插件
Introduction to cross-end development of Taro applet
首次入选OSDI顶会!腾讯提出超大规模推荐系统的模型低延时更新方案
Pycharm终端出现PS问题、conda或activate不是内部命令问题..
ESP8266 Tutorial 2 - Burn AT Firmware
开发模式对测试的影响
随机推荐
Get started quickly and conquer three different distributed architecture calling schemes
C语言空白符、空格符 与转义字符题点总结
How can an organization judge the success of data governance?
GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
Codeforces 814 C. An impassioned circulation of affection (dp)
Will SQL and NoSQL eventually converge?
高阶组件使用
第5章相似矩阵及二次型(4)
企业如何判断数据治理是否成功?
Short video software development - how to break the platform homogenization
what is bsp in rtems
开发模式对测试的影响
ECCV 2022 | 视频理解新框架X-CLIP:仅用微调的成本,达到预训练的全能
自动化测试及Selenium
网络安全笔记6——数字证书与公钥基础设施
【知识论概念】《理由论的进展》鲁汶大学2022最新220页博士论文
第2章-矩阵及其运算-矩阵运算(2)
【FAQ】【Push Kit】 华为怎么设置角标
14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation
POJ 2891 Strange Way to Express Integers (扩展欧几里得)