【Linux】ubuntu下配置stm32开发环境

一、参考资料:

1、vscode开发STM32 环境搭建 基于HAL库 STM32cubemx+Platform IO,MacOS/Windows通用安装
2、我在Linux上使用CubeMX搭建了一个丝滑的STM32开发环境
3、VScode安装PlatformIO Core卡死和新建项目速度慢的解决方法

二、准备工作

1、安装STM32CubeMX:

前往官网:ST官网

在这里插入图片描述在这里插入图片描述在这里插入图片描述

2、安装VSCODE

Code Editing. Redefined.

在这里插入图片描述

3、安装python3环境:

sudo apt install python3
sudo ln -s /usr/bin/python3 /usr/bin/python #创建快捷命令:'$python'
sudo apt install -y python3-venv

4、执行get-platformio.py文件:

(1)、开代理,之后设置端口代理:

export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

(2)、执行py文件进行下载

python3 -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"

或者:

wget https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
python3 get-platformio.py

成功结果响应:

~/> python3 get-platformio.py
Installer version: 1.1.2
Platform: macOS-10.15.7
Python version: 3.9.13 (main, May 24 2022, 21:28:12)
[Clang 12.0.0 (clang-1200.0.32.29)]
Python path: /usr/local/opt/python@3.9/bin/python3.9
Creating a virtual environment at /Users/simonliu/.platformio/penv
Updating Python package manager (PIP) in a virtual environment
PIP has been successfully updated!
Virtual environment has been successfully created!
Installing PlatformIO Core
Collecting platformio
  Using cached platformio-6.1.4-py3-none-any.whl
Collecting marshmallow==3.*
  Using cached marshmallow-3.17.1-py3-none-any.whl (48 kB)
Collecting semantic-version==2.10.*
  Using cached semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)
Collecting aiofiles==0.8.*
  Using cached aiofiles-0.8.0-py3-none-any.whl (13 kB)
Collecting wsproto==1.1.*
  Using cached wsproto-1.1.0-py3-none-any.whl (24 kB)
Collecting colorama
  Using cached colorama-0.4.5-py2.py3-none-any.whl (16 kB)
Collecting pyserial==3.5.*
  Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Collecting uvicorn==0.18.*
  Using cached uvicorn-0.18.3-py3-none-any.whl (57 kB)
Collecting click<9,>=8.0.4
  Using cached click-8.1.3-py3-none-any.whl (96 kB)
Collecting requests==2.*
  Using cached requests-2.28.1-py3-none-any.whl (62 kB)
Collecting tabulate==0.8.*
  Using cached tabulate-0.8.10-py3-none-any.whl (29 kB)
Collecting starlette==0.20.*
  Using cached starlette-0.20.4-py3-none-any.whl (63 kB)
Collecting zeroconf<1
  Using cached zeroconf-0.39.0-py3-none-any.whl (106 kB)
Collecting bottle==0.12.*
  Using cached bottle-0.12.23-py3-none-any.whl (90 kB)
Collecting ajsonrpc==1.*
  Using cached ajsonrpc-1.2.0-py3-none-any.whl (22 kB)
Collecting pyelftools<1,>=0.27
  Using cached pyelftools-0.29-py2.py3-none-any.whl (174 kB)
Collecting packaging>=17.0
  Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting urllib3<1.27,>=1.21.1
  Using cached urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2022.6.15-py3-none-any.whl (160 kB)
Collecting charset-normalizer<3,>=2
  Using cached charset_normalizer-2.1.1-py3-none-any.whl (39 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.3-py3-none-any.whl (61 kB)
Collecting anyio<5,>=3.4.0
  Using cached anyio-3.6.1-py3-none-any.whl (80 kB)
Collecting typing-extensions>=3.10.0
  Using cached typing_extensions-4.3.0-py3-none-any.whl (25 kB)
Collecting h11>=0.8
  Using cached h11-0.13.0-py3-none-any.whl (58 kB)
Collecting async-timeout>=4.0.1
  Using cached async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting ifaddr>=0.1.7
  Using cached ifaddr-0.2.0-py3-none-any.whl (12 kB)
Collecting sniffio>=1.1
  Using cached sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting pyparsing!=3.0.5,>=2.0.2
  Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Installing collected packages: pyserial, pyelftools, ifaddr, bottle, urllib3, typing-extensions, tabulate, sniffio, semantic-version, pyparsing, idna, h11, colorama, click, charset-normalizer, certifi, async-timeout, ajsonrpc, aiofiles, zeroconf, wsproto, uvicorn, requests, packaging, anyio, starlette, marshmallow, platformio
Successfully installed aiofiles-0.8.0 ajsonrpc-1.2.0 anyio-3.6.1 async-timeout-4.0.2 bottle-0.12.23 certifi-2022.6.15 charset-normalizer-2.1.1 click-8.1.3 colorama-0.4.5 h11-0.13.0 idna-3.3 ifaddr-0.2.0 marshmallow-3.17.1 packaging-21.3 platformio-6.1.4 pyelftools-0.29 pyparsing-3.0.9 pyserial-3.5 requests-2.28.1 semantic-version-2.10.0 sniffio-1.3.0 starlette-0.20.4 tabulate-0.8.10 typing-extensions-4.3.0 urllib3-1.26.12 uvicorn-0.18.3 wsproto-1.1.0 zeroconf-0.39.0

PlatformIO Core has been successfully installed into an isolated environment `/Users/simonliu/.platformio/penv`!

The full path to `platformio.exe` is `/Users/simonliu/.platformio/penv/bin/platformio`

If you need an access to `platformio.exe` from other applications, please install Shell Commands
(add PlatformIO Core binary directory `/Users/simonliu/.platformio/penv/bin` to the system environment PATH variable):

See https://docs.platformio.org/page/installation.html#install-shell-commands

(3)、更新环境变量:
最后将/Users/simonliu/.platformio/penv/bin(响应结果中最终路径)加入PATH,在用户profile(我使用的是~/.zshrc)中加入如下一行,并source ~/.zshrc使他在当前终端生效。

三、创建STM32项目:

1、环境:

STM32F103ZET6
STM32CubeMX
VSCode + 插件PlatformIO IDE
stlink

2、STM32CubeMX生成STMTest项目文件:

打开STM32CubeMX,创建一个STM32F103ZET6项目,比如路径:/home/doing/文档/PlatformIO/Projects/STMTest
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述在这里插入图片描述在这里插入图片描述

在这里插入图片描述

3、VSCode补全对应的STMTest文件:

在这里插入图片描述

在这里插入图片描述选择同样文件夹的路径/home/doing/文档/PlatformIO/Projects/STMTest
在这里插入图片描述### 4、编译与上传

完整项目文件:

在这里插入图片描述

platformio.ini内容:
; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:genericSTM32F103ZE]
# https://docs.platformio.org/en/latest/boards/ststm32/genericSTM32F103ZE.html#stm32f103ze-64k-ram-512k-flash
platform = ststm32
board = genericSTM32F103ZE
framework = stm32cube
upload_protocol: stlink

[platformio]
src_dir = Core/Src
include_dir = Core/Inc
编译项目:

在这里插入图片描述

上传项目:

在这里插入图片描述

总结:

keil 编译耗时13s
ubuntu虚拟机 编译耗时3.7s
树莓派 编译耗时25s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值