PlatformIO 开发STM32 (Arduino框架)

创建项目

BoardSTM32F103C8(20k RAM.64k Flash)(Generic)

硬件接线及跳线

跳线

使用Jlink无需配置boot引脚

建议都默认为0boot启动模式参考文档

硬件接线

JLINK STM32 Board
(Reset) (R)
(3.3v) (3.3v)
(SWCLK) (DCLK)
(SWDIO) (DIO)
(GND) (GND)

JLink驱动安装包及其手册

测试代码

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:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino

; board_build.f_cpu = 72000000L

upload_protocol = jlink
main.cpp
/*
 * @Author: Dapenson
 * @Date: 2022-03-28 15:20:38
 * @LastEditors: Dapenson
 * @LastEditTime: 2022-03-28 16:36:05
 * @FilePath: \F103EnvTest\src\main.cpp
 * @Description:
 *
 * Copyright (c) 2022 by Dapenson, All Rights Reserved.
 */
#include <Arduino.h>

const int ledPin = PC13;

void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
  delay(1000);                // wait for a second
  digitalWrite(ledPin, LOW);  // turn the LED off by making the voltage LOW
  delay(1000);                // wait for a second
  Serial.println("Done!");
}

引脚笔记

  • GND3.3v都是内部相通的。3.3v直接给单片机供电,5v接口会通过LDO稳压芯片给单片机供电。
  • microusb只能供电不能下载。
  • 另一端swd下载接口,和跳线帽搭配使用 ,JlinkSTlink都可以。
  • 跳线后可串口下载(PA9 PA10),建议swd,方便测试。
  • PC13连指示灯。
  • B12`PB15`是`SPI2`,`PA4`7SPI1, PA9 PA10串口1PA2 PA3串口2,PB10 PB11串口3PB6~PB9一般可以用于pwm输出,对应TIM4PC13~15 用于时钟相关。
  • VB用于后备电源供电。
  • ADC接口:PA0~PA7,PB0 PB1尽量别用PB3 PB4 PA15,它们和下载口相关。

参考教程

stm32开发新方式-platformio的IDE (smslit.cn)

PlatformIO IDE(VSCode) - stm32cube 框架的工程 - 知乎 (zhihu.com)

stm32开发新方式-platformio (smslit.cn)

posted @ 2022-03-28 18:24  Dapenson  阅读(1018)  评论(0编辑  收藏  举报