使用platformio平台和Arduino框架开发STM32G0

使用platformio平台和arduino框架开发stm32g0,开发环境使用vscode+platformio插件;
1 自定义boards因为platformio中没有自己需要的stm32g070rb这个型号的板子,因此需要自己定义一个开发板型号。
1.1 添加一个自定义boards首先这个是stm32系列,因此其boards目录如下(这里pio安装在默认位置):
c:\\users\\username\\.platformio\\platforms\\ststm32\\boards在这个目录新建一个board描述文件:monkeypi_stm32_g070rb.json,因为和stm32g071接近,因此可以复制 nucleo_g071rb.json文件 进行修改,内容如下:
1{ 2 build: { 3 core: stm32, 4 cpu: cortex-m0plus, 5 extra_flags: -dstm32g0xx -dstm32g070xx, 6 f_cpu: 64000000l, 7 framework_extra_flags: { 8 arduino: -d__cortex_sc=0 9 },10 mcu: stm32g070rbt6,11 product_line: stm32g070xx,12 variant: stm32g0xx/g070rbt13 },14 debug: {15 default_tools: [16 stlink17 ],18 jlink_device: stm32g070rb,19 onboard_tools: [20 stlink21 ],22 openocd_target: stm32g0x,23 svd_path: stm32g070.svd24 },25 frameworks: [26 arduino,27 cmsis,28 libopencm3,29 stm32cube,30 zephyr31 ],32 name: monkeypi_stm32_g070rb,33 upload: {34 maximum_ram_size: 36864,35 maximum_size: 131072,36 protocol: stlink,37 protocols: [38 stlink,39 jlink,40 cmsis-dap,41 blackmagic,42 mbed43 ]44 },45 url: https://www.st.com/zh/microcontrollers-microprocessors/stm32g070rb.html,46 vendor: st47}这里的 monkeypi_stm32_g070rb 就是自定义的板子名称;
1.2 arduino框架下添加board定义在目录
c:\\users\\username\\.platformio\\packages\\framework-arduinoststm32下有一个boards.txt文件,需要在这个文件中添加自定义的板子定义,内容可以根据近似的型号 nucleo_g071rb 进行修改,内容如下:
1# monkeypi stm32g070rb board 2nucleo_64.menu.pnum.monkeypi_g070rb=monkeypi stm32g070rb 3nucleo_64.menu.pnum.monkeypi_g070rb.node=node_g070rb 4nucleo_64.menu.pnum.monkeypi_g070rb.upload.maximum_size=131072 5nucleo_64.menu.pnum.monkeypi_g070rb.upload.maximum_data_size=32768 6nucleo_64.menu.pnum.monkeypi_g070rb.build.mcu=cortex-m0plus 7nucleo_64.menu.pnum.monkeypi_g070rb.build.board=monkeypi_stm32_g070rb 8nucleo_64.menu.pnum.monkeypi_g070rb.build.series=stm32g0xx 9nucleo_64.menu.pnum.monkeypi_g070rb.build.product_line=stm32g070xx10nucleo_64.menu.pnum.monkeypi_g070rb.build.variant=g070rbt11nucleo_64.menu.pnum.monkeypi_g070rb.build.cmsis_lib_gcc=arm_cortexm0l_math12nucleo_64.menu.pnum.monkeypi_g070rb.build.extra_flags=-d{build.product_line} {build.enable_usb} {build.xserial} -d__cortex_sc=01.3 添加arduino板的引脚定义打开目录:
c:\\users\\username\\.platformio\\packages\\framework-arduinoststm32\\variants\\stm32g0xx然后在这个目录的g070rb文件夹下复制 variant_generic.h 和 variant_generic.cpp 两个文件并更改名字为 variant_monkeypi_stm32_g070rb.h 和 variant_monkeypi_stm32_g070rb.cpp ,这个名字是之前自定义的板子名称,需要一致。
然后在variant_monkeypi_stm32_g070rb文件中根据板子硬件信息修改引脚定义,最后添加 systemclock_config 时钟配置函数如下:
1/** 2 * @brief system clock configuration 3 * @param none 4 * @retval none 5 */ 6weak void systemclock_config(void) 7{ 8 /* systemclock_config can be generated by stm32cubemx */ 9#warning systemclock_config() is empty. default clock at reset is used.10}并修改文件的定义如下:
#if defined(arduino_monkeypi_stm32_g070rb)注:如果g070rb目录下没有ldscript.ld这个文件,还需要从g071等相似目录下拷贝一个,这个在链接时候需要用到。
2 使用2.1 新建项目在pio的home中新建项目,选择自定义开发板型号 monkeypi_stm32_g070rb:
2.2 编写测试arduino代码打开项目中 src/main.cpp 文件,编写arduino代码:
1#include 2 3void setup() { 4 // put your setup code here, to run once: 5 6 pinmode(pb5,output); 7 8} 910void loop() {11 // put your main code here, to run repeatedly:1213 digitalwrite(pb5,1);14 delay(100);15 digitalwrite(pb5,0);16 delay(100);1718}2.3 烧写程序烧写的方式需要根据自己的需要进行修改,比如我这里使用daplink swd方式下载,需要修改项目的platformio.ini文件:
1[env:monkeypi_stm32_g070rb]2platform = ststm323board = monkeypi_stm32_g070rb4framework = arduino56upload_protocol = cmsis-dap修改完成后,点击platformio:upload按钮即可完成烧写:

263视频会议发布桌面大屏终端,引领双屏办公时代
产品分析:谁是利益相关者?
专业网线厂家回应:光纤线和网线的区别-科兰
无限反射镜的工作原理
RTT zephyr_polling SPI Bluenrg2数据传输测试
使用platformio平台和Arduino框架开发STM32G0
2018年上半年互联网电视企业战绩日渐明朗,华为在一旁虎视眈眈
!销售/收购/维修HP3577A网络分析仪HP3577A现货
可靠性预测的不确定性是否证明强制要求双通道安全是合理的
勤哲Excel服务器在图书出版企业管理系统中的应用
诺基亚6评测:对比诺基亚8,都是情怀你买谁?
一文看懂华为的5G布局
什么是8类网线?8类线与七类线、超六类线的区别 8类线的应用
1分钟读懂芯片设计 何为半导体?它可能是下一个房地产 比一比
出货少,得不到FAE重视?中小企业或将迎来新机遇
SolidWorks三维机械设计软件超实用操作技巧(九)
澳大利亚、新西兰两国的区块链政策及应用分析
可配置技术影响SoC(系统级芯片)的设计
摩擦起电诱导电致发光是一种新型的发光材料
5G技术将正面推动医疗事业的转型