linux下的STM32开发尽管直接c代码开发环境已经搞定了,看上一篇, 命令行速度很快,简单粗暴,但是还不够简洁,而且没有简单易用的IDE,调试非常不方便,灵机一动,Arduino不是跨平台的么?而且之前在windows上已经成功导入了stm32的库,已经跑通了,何不移植到linux上?这才是简洁至上的“跨平台”开发环境,一番折腾下,顺利跑了起来。这个可以作为嵌入式开发入门利器,可以不用关心底层资源分配,也可以作为物联网快速应用平台,F103C8T6经典的开发板,10元以下就可以搞定,用来做培训和教育类应用太实用了。
1. 下载安装Arduino
链接: https://pan.baidu.com/s/1T_0QIlqTIxRo9BMF9-4okg 提取码: djwk
解压后运行./install.sh即完成安装
2.下载安装stm32包
链接: https://pan.baidu.com/s/1HwswohgUHqQ3A82wGYy1sw 提取码: m41r
github项目链接https://github.com/rogerclarkmelbourne/Arduino_STM32
3.解压到/home/Arduino/hardware目录
4.打开Arduino选择板子,下载方式选择stlink
下载方式可以用串口 bootloader烧录的方式(有时间再研究),但stlink更快,但同时需要相应的软件和库支持,下面就遇到这个问题
5.在例子里选择测试
选择blink例程,内置的led变量就是PC13,或者替换成相应的io 口
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
这个值在哪定义?
(boards)/variants/board/variant.h文件定义
编译提示找不到libusb库
安装sudo apt install libusb*
提示错误
libusb-1.0-doc set to manually installed.
libusbmuxd4 is already the newest version (1.0.10-2ubuntu0.1).
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libusb-ocaml : Depends: liblwt-ocaml-io1z5
Depends: ocaml-base-nox-4.02.3
Conflicts: libusb-ocaml:i386 but 1.3.0-3build1 is to be installed
libusb-ocaml:i386 : Conflicts: libusb-ocaml but 1.3.0-3build1 is to be installed
libusb-ocaml-dev : Depends: liblwt-ocaml-dev-io1z5
Depends: ocaml-nox-4.02.3
Recommends: ocaml-findlib but it is not going to be installed
Conflicts: libusb-ocaml-dev:i386 but 1.3.0-3build1 is to be installed
libusb-ocaml-dev:i386 : Depends: liblwt-ocaml-dev-i9vz1:i386
Depends: ocaml-nox-4.02.3:i386
Conflicts: libusb-ocaml-dev but 1.3.0-3build1 is to be installed
E: Unable to correct problems, you have held broken packages.
发现linux目录下的st-flash用不了,但是linux64目录下的可以用,那这个工具目录是哪里设置的呢?
调用的下载工具是st-flash,默认目录指向了hardware/boards/tools/linux
在这个目录下有个stlink_upload的配置文件,修改其中指定的st-flash目录至linux64
#!/bin/bash
/home/hy/Arduino/hardware/Arduino_STM32-master/tools/linux64/stlink/st-flash write "$1" 0x8000000
exit 0
再执行,下载成功
至此,配置成功
5.测试调试串口
查看IO口定义
在boards/board/variants/board/board.h
#ifndef _BOARD_GENERIC_STM32F103C_H_
#define _BOARD_GENERIC_STM32F103C_H_
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
#define BOARD_NR_USARTS 3
#define BOARD_USART1_TX_PIN PA9
#define BOARD_USART1_RX_PIN PA10
#define BOARD_USART2_TX_PIN PA2
#define BOARD_USART2_RX_PIN PA3
#define BOARD_USART3_TX_PIN PB10
#define BOARD_USART3_RX_PIN PB11
#define BOARD_NR_SPI 2
#define BOARD_SPI1_NSS_PIN PA4
#define BOARD_SPI1_MOSI_PIN PA7
#define BOARD_SPI1_MISO_PIN PA6
#define BOARD_SPI1_SCK_PIN PA5
#define BOARD_SPI2_NSS_PIN PB12
#define BOARD_SPI2_MOSI_PIN PB15
#define BOARD_SPI2_MISO_PIN PB14
#define BOARD_SPI2_SCK_PIN PB13
#define BOARD_NR_GPIO_PINS 35
#define BOARD_NR_PWM_PINS 12
#define BOARD_NR_ADC_PINS 9
#define BOARD_NR_USED_PINS 4
#define BOARD_JTMS_SWDIO_PIN 22
#define BOARD_JTCK_SWCLK_PIN 21
#define BOARD_JTDI_PIN 20
#define BOARD_JTDO_PIN 19
#define BOARD_NJTRST_PIN 18
#define BOARD_USB_DISC_DEV NULL
#define BOARD_USB_DISC_BIT NULL
#define LED_BUILTIN PC13
// Note this needs to match with the PIN_MAP array in board.cpp
enum {
PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13,PA14,PA15,
PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PB8, PB9, PB10, PB11, PB12, PB13,PB14,PB15,
PC13, PC14,PC15
};
#endif
其中PA9/PA10对应定义为UART1
所以要想将monitor接到PA9/PA10进行调试信息打印,应将打印信息输出制定到serial1
测试成功,接下来可以愉快的使用stm32开发板进行 linux下的arduino开发了,这是最简洁易用的ide了,没有之一。