当前位置:网站首页>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,从此一帆风顺~~
边栏推荐
- dedecms supports one-click upload of Word content
- 【FAQ】【Push Kit】 华为怎么设置角标
- database transaction
- Gartner再次重申了“数据编织”的重要价值
- 网络安全笔记5——数字签名
- "Chief Engineer" Principal (Principal) engineer's way of training
- 【电商运营】你真的了解社交媒体营销(SMM)吗?
- runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
- 从产品维度来看 我们为什么不能完全信任Layer2?
- 让软件飞——“X+”技术揭秘
猜你喜欢
Dry goods!ASSANet: Making PointNet++ faster and stronger
String interception function in SQL
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
EasyCVR级联时,修改下级平台名称将不同步至上级平台
14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation
chart.js horizontal column chart plugin
MongoDB database notes
快速上手,征服三种不同分布式架构调用方案
Dalian University of Technology & Pengcheng & UAE propose a mixed-scale triple network ZoomNet for camouflaged target detection, with SOTA performance!
"Chief Engineer" Principal (Principal) engineer's way of training
随机推荐
4 面拿华为 offer 的水平,面试阿里居然一面就被吊打?
GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
解决ASP.NET Core在Task中使用IServiceProvider的问题
文本选中圆角样式border-radius
2022.8.9-----leetcode.1413
干货!ASSANet:让PointNet++更快更强
MongoDB database notes
ZZULIOJ 1116 删除元素【删】
什么是抽象类
[C language] Header file #include
, conio is Console Input/Output (console input and output) Load balancing principle analysis and source code interpretation
POJ 2891 Strange Way to Express Integers (扩展欧几里得)
Dalian University of Technology & Pengcheng & UAE propose a mixed-scale triple network ZoomNet for camouflaged target detection, with SOTA performance!
Codeforces 814 C. An impassioned circulation of affection (dp)
3D旋转文本动画js特效
面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
蔚来-软件开发工程师一面记录
bus事件总线 使用
getParameter()与 getAttribute()的用法与区别
【知识论概念】《理由论的进展》鲁汶大学2022最新220页博士论文