【本文發(fā)布于https://blog.csdn.net/Stack_/article/details/128771308,未經(jīng)許可禁止轉載,轉載須注明出處】
一、安裝工具并配置環(huán)境變量
ARM的GitHub有如下說明
1、python3
【官網(wǎng)】
【網(wǎng)盤】提取碼:fp68
安裝時會自動添加環(huán)境變量。如果電腦已有py2環(huán)境變量,安裝完后在系統(tǒng)變量中將py3提到py2前面,下面的操作完成后卸載或者恢復到py2后面即可。
2、Git
【官網(wǎng)】
【網(wǎng)盤】提取碼:v5t6
3、Keil MDK,需要有V5編譯器。MDK5 v5.28即可
【網(wǎng)盤】提取碼:keil
二、獲取官方開源代碼
右鍵Git Bash Here,輸入
git clone https://github.com/ARMmbed/DAPLink
將拉取一個名為DAPLink的文件夾,內(nèi)有如下文件。
三、生成Keil工程
DAPLink\docs目錄下找到DEVELOPERS-GUIDE.md文件(即第一張圖的開發(fā)指引)
1、輸入pip install virtualenv,等待下載完成(此處以及后續(xù)命令行操作均在DAPLink路徑下,DAPLink目錄中右鍵Git Bash Here)。
2、輸入virtualenv venv,等待執(zhí)行完成。將生成venv文件夾
3、輸入venv/Scripts/activate.bat
4、輸入pip install -r requirements.txt。如果顯示timed out字樣,改用pip install --default-timeout=1000 --no-cache-dir -r requirements.txt。需要等較長的時間。當出現(xiàn)Successfully installed即為成功
5、輸入progen generate -t uvision,將生成projectfiles,并在projectfiles目錄下生成一系列工程
四、打開工程
確保Keil已激活以及已安裝stm32f103的pack。
找到stm32f103xb_bl文件夾,打開工程文件,將提示如下信息,點擊第一項,將彈出pack安裝管理器(Pack Installer),關閉它。
【工程名是stm32f103xb,但是我這里為什么用stm32f103c8t6?原因請看評論區(qū)。】
關閉后看到此界面,點擊是,隨后選擇單片機型號為STM32F103C8T6。
五、編譯下載
1、根據(jù)自己DIY的硬件修改IO_Config.h引腳定義文件
2、編譯工程并用其它燒錄器下載到STM32F103C8T6后,重新插拔USB線,電腦將出現(xiàn)一個虛擬硬盤。表示DAPLink的boot程序已成功運行。
3、隨后找到stm32f103xb_stm32f103rb_if工程,進行和上面一致的操作。編譯后在工程build目錄下找到hex文件拖入到此虛擬U盤中,U盤名稱將變?yōu)橄聢D所示。DAPLINK運行成功
六、注意
1、發(fā)現(xiàn)我自己畫的板子燒入程序,有幾率上電時停留在boot中無法進入app,排查后發(fā)現(xiàn)官方源碼中RST引腳配置為開漏輸出,boot中要讀取到RST的電平為高才會跳轉app,而我這板子沒有上拉RST腳。配置為推挽輸出便正常了。
2、keil工程芯片型號不一樣,但它們的源文件是共用的,boot和app也是有公共的源文件的,例如IO_Config.h。
七、附
1、【硬件原理圖】
鏈接:https://pan.baidu.com/s/1o40RZSf3Fbb1uKpI4PE4SQ
提取碼:qlw5
2、引腳定義修改
/**
* @file IO_Config.h
* @brief
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __IO_CONFIG_H__
#define __IO_CONFIG_H__
#include "stm32f1xx.h"
#include "compiler.h"
#include "daplink.h"
COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_STM32F103XB);
//USB control pin
#define USB_CONNECT_PORT_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USB_CONNECT_PORT_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
#define USB_CONNECT_PORT GPIOA
#define USB_CONNECT_PIN GPIO_PIN_15
#define USB_CONNECT_ON() (USB_CONNECT_PORT->BSRR = USB_CONNECT_PIN)
#define USB_CONNECT_OFF() (USB_CONNECT_PORT->BRR = USB_CONNECT_PIN)
//Connected LED
#if (0)
#define CONNECTED_LED_PORT GPIOB
#define CONNECTED_LED_PIN GPIO_PIN_6
#define CONNECTED_LED_PIN_Bit 6
#else //PWH修改為PA8
#define CONNECTED_LED_PORT GPIOA
#define CONNECTED_LED_PIN GPIO_PIN_8
#define CONNECTED_LED_PIN_Bit 8
#endif
//When bootloader, disable the target port(not used)
#define POWER_EN_PIN_PORT GPIOB
#define POWER_EN_PIN GPIO_PIN_15
#define POWER_EN_Bit 15
// nRESET OUT Pin
#if (0)
#define nRESET_PIN_PORT GPIOB
#define nRESET_PIN GPIO_PIN_0
#define nRESET_PIN_Bit 0
#else //PWH修改為
#define nRESET_PIN_PORT GPIOA
#define nRESET_PIN GPIO_PIN_6
#define nRESET_PIN_Bit 6
#endif
//SWD
#if (0)
#define SWCLK_TCK_PIN_PORT GPIOB
#define SWCLK_TCK_PIN GPIO_PIN_13
#define SWCLK_TCK_PIN_Bit 13
#else //PWH修改為
#define SWCLK_TCK_PIN_PORT GPIOA
#define SWCLK_TCK_PIN GPIO_PIN_4
#define SWCLK_TCK_PIN_Bit 4
#endif
#if (0)
#define SWDIO_OUT_PIN_PORT GPIOB
#define SWDIO_OUT_PIN GPIO_PIN_14
#define SWDIO_OUT_PIN_Bit 14
#else //PWH修改為
#define SWDIO_OUT_PIN_PORT GPIOA
#define SWDIO_OUT_PIN GPIO_PIN_7
#define SWDIO_OUT_PIN_Bit 7
#endif
#if (0)
#define SWDIO_IN_PIN_PORT GPIOB
#define SWDIO_IN_PIN GPIO_PIN_12
#define SWDIO_IN_PIN_Bit 12
#else //PWH修改為
#define SWDIO_IN_PIN_PORT GPIOB
#define SWDIO_IN_PIN GPIO_PIN_0
#define SWDIO_IN_PIN_Bit 0
#endif
//LEDs
//USB status LED
#define RUNNING_LED_PORT GPIOA
#define RUNNING_LED_PIN GPIO_PIN_9
#define RUNNING_LED_Bit 9
#define PIN_HID_LED_PORT GPIOA
#define PIN_HID_LED GPIO_PIN_9
#define PIN_HID_LED_Bit 9
#define PIN_CDC_LED_PORT GPIOA
#define PIN_CDC_LED GPIO_PIN_9
#define PIN_CDC_LED_Bit 9
#define PIN_MSC_LED_PORT GPIOA
#define PIN_MSC_LED GPIO_PIN_9
#define PIN_MSC_LED_Bit 9
#endif
3、如果Keil無法識別到DAPLink,需要根據(jù)下文對源碼做些修改
【新版daplink keil5識別不了】
本來想著加塊屏幕可以個性化一下,但讀懂源碼就不容易了,目前只能顯示USB連接狀態(tài),其余得慢慢研究了文章來源:http://www.zghlxwxcb.cn/news/detail-418067.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-418067.html
到了這里,關于自制DAPLink -- ARM官方源碼以及STM32F103C8T6的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!