STM32 Tutorial: #4 Using STM32Duino
来源:互联网 发布:淘宝发布宝贝 压缩包 编辑:程序博客网 时间:2024/06/05 17:42
Brief
This article is about how to use Arduino IDE and STM32duino to develop software for my STM32F103ZET6
development board (Type: PZ6806L
). Arduino
helps me out from a lot of hard C code such as GPIOX_xxxx and RCCxxx. Life should be easier and you deserve that.
Prepare ST-Link
To make STM32duino
work with my board, I bought a ST-Link-v2
, which officially supports STM32F10xx
. Investment on better hardware can save you a lot of time. I won’t tell you how could I conclude this. According documents, the ST-Link
should connect to STM32F10xx
board in this way: ST-Link
pins are listed on the left side:
- SWDIO
to PA13
- GND
to GND
- SWCLK
to PA14
- 3.3v
to 3.3v
Check my board carefully, I found the PA13 and PA14 pins are on the left side. Also the 3.3v and GND are very close to them, named by Power Module
. Connect pins carefully, make sure you won’t miss anything. Here is the
Official page about ST-Link.
ST-Link tools download link.
Install Arduino IDE and STM32duino
Download Arduino IDE and install it.
Note:
You’d better download the zip version and extract to your favorite place such as Desktop
. As I know the dry version works much better than installer version.
Download STM32duino and install it.
Instruction of installing STM32duino.
Run Arduino IDE
, look up the menu Tools\Board
, a long list of STM32 chip set will appear.
Here is my configuration:
- Board
-> Generic STM32F103Z series
which is under STM32 Boards (STM32duino.com)
- Variant
-> STM32F103ZE
- CPU Speed(MHz)
-> 72MHz (Normal)
- Upload Method
-> STLink
I tried other options but no luck
- Optimize
-> Size(default)
The most important thing we consider
- Port
-> COMx
Varies, depends on your situation
Connect Dev Board
Shut off the dev board, connect ST-Link
pins to board then plug ST-Link
to PC’s USB port. Now the board will light up. If you are in Arduino IDE
, just compile and upload, be patient. If everything is right, you will see the IDE shows message like this:
Sketch uses 16984 bytes (3%) of program storage space. Maximum is 524288 bytes.Global variables use 3552 bytes (5%) of dynamic memory, leaving 61984 bytes for local variables. Maximum is 65536 bytes.STM32 ST-LINK CLI v2.1.0STM32 ST-LINK Command Line InterfaceST-LINK SN : Old ST-LINK firmware/ST-LINK already usedST-LINK Firmware version : V2J17S4 (Need Update)Old ST-LINK firmware detected!Please upgrade it from ST-LINK->'Firmware update' menu.Connected via SWD.Connection mode : Normal.Device ID:0x414 Device flash Size : 512 KbytesDevice family :STM32F10xx High-densityLoading file...Flash Programming: File : C:\Users\igame\AppData\Local\Temp\arduino_build_214956\sketch_aug01a.ino.bin Address : 0x08000000Flash memory programming...北北北北北北北北北北北北北北北北北北北北北北北北北 0% 0%圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹圹 100%Flash memory programmed in 1s and 234ms.Programming Complete.MCU Reset.Application started.
Congratulations! You just made it!
Port Program From CoIDE
Now we could port our bare C program written under CoIDE to Arduino
. Here is the code. It’s much simpler.
#define DIGIT_SEGMENTS 8#define LED_BEGIN 32#define LED_END (LED_BEGIN + DIGIT_SEGMENTS - 1)#define MAX_NUM 0x16char DIGIT_MATRIX[MAX_NUM * DIGIT_SEGMENTS] = { 1, 1, 1, 1, 1, 1, 0, 0, // 0 0, 1, 1, 0, 0, 0, 0, 0, // 1, 1, 1, 0, 1, 1, 0, 1, 0, // 2, 1, 1, 1, 1, 0, 0, 1, 0, // 3, 0, 1, 1, 0, 0, 1, 1, 0, // 4, 1, 0, 1, 1, 0, 1, 1, 0, // 5, 1, 0, 1, 1, 1, 1, 1, 0, // 6, 1, 1, 1, 0, 0, 0, 0, 0, // 7, 1, 1, 1, 1, 1, 1, 1, 0, // 8, 1, 1, 1, 1, 0, 1, 1, 0, // 9, 1, 1, 1, 0, 1, 1, 1, 1, // A, 0, 0, 1, 1, 1, 1, 1, 1, // b, 1, 0, 0, 1, 1, 1, 0, 1, // c, 0, 1, 1, 1, 1, 0, 1, 1, // d, 1, 0, 0, 1, 1, 1, 1, 1, // e, 1, 0, 0, 0, 1, 1, 1, 1, // f, 1, 0, 1, 1, 1, 1, 0, 1, // G, 0, 0, 1, 0, 1, 1, 1, 1, // h, 0, 1, 1, 0, 0, 0, 0, 1, // I, 0, 1, 1, 1, 0, 0, 0, 1, // J, 0, 1, 1, 0, 1, 1, 1, 1, // K, 0, 0, 0, 1, 1, 1, 0, 1 // L}; //int num = 0;void setup() { // put your setup code here, to run once: for(int i = LED_BEGIN; i <= LED_END; i++) pinMode(i, OUTPUT);}void showDigit(int x) { if (x >= 0 && x <= MAX_NUM) { char* ptr = DIGIT_MATRIX + x * DIGIT_SEGMENTS; for(int i = 0; i < DIGIT_SEGMENTS; i++) { digitalWrite(LED_BEGIN + i, *ptr == 1 ? LOW : HIGH); // NOTE: LOW to turn LED on! ptr++; } }}void loop() { // put your main code here, to run repeatedly: showDigit(num++); if (num > MAX_NUM) num = 0; delay(200);}
NOTE
The Arduino
digitalWrite()
uses LOW
to light LEDs up, not HIGH
as I assumed.
Good luck!
Reference
- STM32F100 Value Line
- STM32F103ZE Introduction
- STM32 Tutorial: #4 Using STM32Duino
- 【玩STM32】STM32Duino的引脚映射,ADC,PWM等介绍
- Tutorial:Streaming using VLC
- Tutorial for building J2EE Applications using JBOSS and ECLIPSE -4
- STM32 Tutorial: #3 Show digit
- regex tutorial using java (1)
- C# Tutorial - Using The ThreadPool
- Tutorial Lesson 1: Using Quartz
- Tutorial: Using AngularJS with Django
- STM32 Tutorial: #1 Buy a board
- STM32 Tutorial: #2 Light up LEDs
- Tutorial for building J2EE Applications using JBOSS and ECLIPSE Chapter 4
- Tutorial for building J2EE Applications using JBOSS and ECLIPSE(4)
- Tutorial for building J2EE Applications using JBOSS and ECLIPSE(4)
- Simple iOS 5 UI Design Tutorial Using Storyboard in XCode 4
- Using Lua with C++: A short tutorial
- C# Tutorial - Using the BackgroundWorker Class
- cscope tutorial: Using Cscope on large projects
- Brew error: Could not symlink, xx/xx/xxx is not writable
- Properties类
- 最小表示法
- 设置环境变量的方法
- Swift3豆瓣电台
- STM32 Tutorial: #4 Using STM32Duino
- hadoop核心逻辑shuffle代码分析-map端
- spark shuffle内在原理说明
- springMvc和struts2区别
- 贪吃蛇C语言代码(window版本)
- Linux学习笔记之七
- 蓝桥杯练习题 BEGIN-1 A+B问题
- matlab lsqnonlin fsolve的区别
- Webpack相关网址