【本文发布于https://blog.csdn.net/Stack_/article/details/128771308,未经许可禁止转载,转载须注明出处】
一、安装工具并配置环境变量
1、python3
【官网】
【网盘】
链接:https://pan.baidu.com/s/1zW_H_eQlkzX3FkXuClFnTA
提取码:fp68
安装时会自动添加环境变量
2、Git
【官网】
【网盘】
链接:https://pan.baidu.com/s/1TBMR6BPVAurQmqTZs-pp9w
提取码:v5t6
3、Keil MDK,需要有V5编译器。MDK5 v5.28即可
二、获取官方开源代码
右键Git Bash Here,输入
git clone https://github.com/ARMmbed/DAPLink
三、生成Keil工程
DAPLink\docs目录下找到DEVELOPERS-GUIDE.md文件
1、输入pip install virtualenv,等待下载完成。
2、输入virtualenv venv,等待执行完成。将生成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。需要等较长的时间。当出现Successfully installed即为成功
5、输入progen generate -t uvision,将生成projectfiles,并在projectfiles目录下生成一系列工程
四、打开工程
确保Keil已激活以及已安装stm32f103的pack。
找到stm32f103xb_bl文件夹,打开工程文件,将提示如下信息,点击第一项,将弹出pack安装管理器(Pack Installer),关闭它。
关闭后看到此界面,点击是,随后选择单片机型号为STM32F103C8T6。
五、编译下载
编译工程并用其它烧录器下载到STM32F103C8T6后,重新插拔USB线,电脑将出现一个虚拟硬盘。表示DAPLink的boot程序已成功运行。
随后找到stm32f103xb_stm32f103rb_if工程,进行和上面一致的操作,但是要根据自己DIY的硬件修改IO_Config.h引脚定义文件。
编译后在工程build目录下找到hex文件拖入到此虚拟U盘中,U盘名称将变为下图所示。DAPLINK运行成功
六、附
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 5
#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,需要根据下文对源码做些修改
【新版daplink keil5识别不了】