1. 使用的開發板子
使用的開發板是好幾年好幾年前買的了,板子一直在家里睡覺。最近閑著沒事,所以打算學習一下stm32.
板子是普中STM32-PZ6806L開發板。開發板的圖見下
puzhongkaifaban.png
2. stm32 燒入程序原理
我們這里使用ISP(In-System Programming)燒入.
ISP 燒入使用串口.
這個開發板子提供了上圖的6的位置是一個miniUSB,5的位置是一個usb轉串口的芯片。5,6的原理圖見下:
yuanli.png
其中串口的 DTR引腳控制STM32的重置。
RTS引腳控制STM32的boot選擇。
我們要想燒入程序:要把開發版上面的34的位置的跳冒
BOOT0連接到3.3V
BOOT1連接到GND。
(PS,我試了試他們都連接到GND也是可以用的。。。)
3. 下載 stm32flash 程序
git clone https://github.com/ARMinARM/stm32flash.git make make install
注意:
上面可能執行make的時候會出現編譯錯誤。因為archlinux是滾動更新的。不能保證代碼每次都編譯通過。我這次編譯就出現了錯誤。但是也很好解決,就不多說了。
make install 命令會默認安裝stm32flash命令到/usr/local下面。如過不想安裝到這個里面請修改Makefile。
在 Makefile中也指定了man pages安裝到哪里了。請參考 man page的配置,去配置man手冊。(ps:如果不需要手冊,這一步不需要考慮了)
4. 測試stm32flash程序能不能正常工作
我們把開發板通過usb插入電腦。并查看man stm32flash的配置,發現可以直接執行stm32flash
[vicking@archlinux ~]$ ls /dev/ttyUSB* /dev/ttyUSB0 /dev/ttyUSB2 [vicking@archlinux ~]$ stm32flash /dev/ttyUSB2 stm32flash 0.4 http://stm32flash.googlecode.com/ Interface serial_posix: 57600 8E1 Failed to init device.
喔吼,執行失敗了。查看man stm32flash我們可以看到如下配置:應該是通過rst和boot兩個口去配置芯片進入和退出bootloader。
BOOTLOADER GPIO SEQUENCE
This feature is currently available on Linux host only.
As explained in ST application note AN2606, after reset the STM32 will execute either the application pro‐
gram in user flash or the bootloader, depending on the level applied at specific pins of STM32 during re‐
set.
STM32 bootloader is automatically activated by configuring the pins BOOT0='high' and BOOT1='low' and then
by applying a reset. Application program in user flash is activated by configuring the pin BOOT0='low'
(the level on BOOT1 is ignored) and then by applying a reset.
When GPIO from host computer are connected to either configuration and reset pins of STM32, stm32flash can
control the host GPIO to reset STM32 and to force execution of bootloader or execution of application pro‐
gram.
The sequence of GPIO values to entry to and exit from bootloader mode is provided with command line option
-i GPIO_string.
The format of GPIO_string is:
GPIO_string = [entry sequence][:[exit sequence]]
sequence = [-]n[,sequence]
In the above sequences, negative numbers correspond to GPIO at 'low' level; numbers without sign corre‐
spond to GPIO at 'high' level. The value 'n' can either be the GPIO number on the host system or the
string 'rts', 'dtr' or 'brk'. The strings 'rts' and 'dtr' drive the corresponding UART's modem lines RTS
and DTR as GPIO. The string 'brk' forces the UART to send a BREAK sequence on TX line; after BREAK the
UART is returned in normal 'non-break' mode. Note: the string '-brk' has no effect and is ignored.
As example, let's suppose the following connection between host and STM32:
? host GPIO_3 connected to reset pin of STM32;
? host GPIO_4 connected to STM32 pin BOOT0;
? host GPIO_5 connected to STM32 pin BOOT1.
In this case, the sequence to enter in bootloader mode is: first put GPIO_4='high' and GPIO_5='low'; then
send reset pulse by GPIO_3='low' followed by GPIO_3='high'. The corresponding string for GPIO_string is
'4,-5,-3,3'.
To exit from bootloade and run the application program, the sequence is: put GPIO_4='low'; then send reset
pulse. The corresponding string for GPIO_string is '-4,-3,3'.
The complete command line flag is '-i 4,-5,-3,3:-4,-3,3'.
查看文檔后,我們這個開發板子上面進入bootloader和離開bootloader的序列應該如下
rts,dtr,-dtr ## 進入bootloader序列: rts高電平,dtr高電平,dtr 低電平 -rts,dtr,-dtr ## 退出bootloader序列: rts低電平,dtr高電平,dtr 低電平
所以,我們執行我們根據開發板的原理圖和這里的手冊嘗試執行如下命令。發現就成功了。
注意:
我的芯片是stm32f1, 而stm32w的配置可能有所不同。
芯片進入和退出bootloader的順序設置可能跟你的ch34x(并轉串)芯片和stm32芯片連接不同而有不同的設置。自己可以測試出自己的序列。
[vicking@archlinux ~]$ stm32flash -i rts,dtr,-dtr:-rts,dtr,-dtr /dev/ttyUSB2
stm32flash 0.4
http://stm32flash.googlecode.com/
Interface serial_posix: 57600 8E1
Version : 0x22
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0414 (High-density)
- RAM : 64KiB (512b reserved by bootloader)
- Flash : 512KiB (sector size: 2x2048)
上面讀取的是設備信息,反正我暫時也看不懂,就先不說了。
5. 測試寫入程序
stm32flash -b 9600 -i rts,dtr,-dtr:-rts,dtr,-dtr -w newhelloworld.hex -v -g 0x0 /dev/ttyUSB1
stm32flash 0.4
http://stm32flash.googlecode.com/
Using Parser : Intel HEX
Interface serial_posix: 9600 8E1
Version : 0x22
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0414 (High-density)
- RAM : 64KiB (512b reserved by bootloader)
- Flash : 512KiB (sector size: 2x2048)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
Wrote and verified address 0x08000bbc (100.00%) Done.
Starting execution at address 0x08000000... done.
-w:指定要寫入的hex文件,
-v:表示校驗寫入的數據
-g:表示從哪個地址執行程序
6. 其他
上面燒寫環境是在archlinux進行的。但是配置過程好像跟linux發行版本沒有什么太大的關系。唯一可能失敗的地方應該就是編譯stm32flash的地方。
另外串口/dev/ttyUSB2這樣的串口設備,普通用戶可能沒有辦法使用。需要root權限。
下面給出archlinux 下面非root用戶也可以使用的方法。
[vicking@archlinux ~]$ ls -l /dev/ttyUSB2
crw-rw---- 1 root uucp 188, 2 Jul 2日 01:36 /dev/ttyUSB2 ## 發現設備文件屬于uucp組
[vicking@archlinux ~]$ sudo usermod -a -G uucp vicking ##把我們當前的用戶加到uucp組
[sudo] vicking 的密碼:
[vicking@archlinux ~]$ reboot ## 重啟生效
如果你的archlinux 配置了AUR,那么也可以從AUR倉庫下載
yay -S stm32flash
查看man stm32flash 其使用方法與上面的稍微有點不同。現在的序列為-i rts,,,-dtr,,,dtr:-rts,,,-dtr,,,dtr。 其中每個逗號代表兩個信號之間相隔100ms。當然具體的配置,要查看你們電腦里面的man pages。不能一概而論。多嘗試嘗試。
上一篇:【STM32調試(三)】采集bmp圖像保存在SD卡
下一篇:STM32通過rosserial接入ROS通訊開發
推薦閱讀最新更新時間:2025-04-17 15:54





設計資源 培訓 開發板 精華推薦
- 用于消費電子產品的 PIC32 MCU 開發系統
- MPC8349EMITXE: MPC8349E-mITXE Reference Platform
- EVAL-AD7741/42EB,用于 AD7741 單通道/多通道同步電壓頻率轉換器的評估板
- 效率高達 97% 且具有堵轉電流限制的 10.8V/250W 緊湊型無刷直流電機驅動器參考設計
- 使用 Infineon Technologies AG 的 IRIS-F6428S 的參考設計
- EVAL-CN0285-EB1Z,基于 ADF4351 的寬帶低誤差矢量幅度 (EVM) 直接轉換發射器
- NE555八音電子琴
- [測試通過] 18650 鋰電池 露營燈 手電筒 臺燈
- 基于STC3105的帶有報警輸出的電池監視演示板,用于燃氣表應用
- NCP300HSN18T1 1.8V 電壓檢測器的典型應用,用于具有附加遲滯的微處理器復位電路