[其他ST产品] 自制DAPLink -- ARM官方源码以及STM32F103C8T6

[复制链接]
2518|44
 楼主| 4c1l 发表于 2023-3-23 23:51 | 显示全部楼层 |阅读模式
安装工具并配置环境变量

ARM的GitHub有如下说明

12557641c75830f544.png

1、python3

【官网】
【网盘】
链接:https://pan.baidu.com/s/1zW_H_eQlkzX3FkXuClFnTA
提取码:fp68

安装时会自动添加环境变量。如果电脑已有py2环境变量,安装完后在系统变量中将py3提到py2前面,下面的操作完成后卸载或者恢复到py2后面即可。

评论

———————————————— 版权声明:本文为CSDN博主「Tyrion.Mon」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/Stack_/article/details/128771308  发表于 2023-3-23 23:51
 楼主| 4c1l 发表于 2023-3-23 23:51 | 显示全部楼层
2、Git

【官网】
【网盘】
链接:https://pan.baidu.com/s/1TBMR6BPVAurQmqTZs-pp9w
提取码:v5t6
 楼主| 4c1l 发表于 2023-3-23 23:52 | 显示全部楼层
3、Keil MDK,需要有V5编译器。MDK5 v5.28即可
 楼主| 4c1l 发表于 2023-3-23 23:52 | 显示全部楼层
二、获取官方开源代码

右键Git Bash Here,输入

git clone https://github.com/ARMmbed/DAPLink
 楼主| 4c1l 发表于 2023-3-23 23:52 | 显示全部楼层
将拉取一个名为DAPLink的文件夹,内有如下文件。
57766641c75bc37220.png
选中的文件夹为后续步骤生成的
 楼主| 4c1l 发表于 2023-3-23 23:52 | 显示全部楼层
三、生成Keil工程

DAPLink\docs目录下找到DEVELOPERS-GUIDE.md文件(即第一张图的开发指引)
97432641c75d95a63a.png
 楼主| 4c1l 发表于 2023-3-23 23:53 | 显示全部楼层
1、输入pip install virtualenv,等待下载完成(此处以及后续命令行操作均在DAPLink路径下,DAPLink目录中右键Git Bash Here)。

98984641c75efae4c7.png
 楼主| 4c1l 发表于 2023-3-23 23:53 | 显示全部楼层
2、输入virtualenv venv,等待执行完成。将生成venv文件夹

21391641c760264e27.png

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目录下生成一系列工程
 楼主| 4c1l 发表于 2023-3-23 23:54 | 显示全部楼层
四、打开工程

确保Keil已激活以及已安装stm32f103的pack。

找到stm32f103xb_bl文件夹,打开工程文件,将提示如下信息,点击第一项,将弹出pack安装管理器(Pack Installer),关闭它。

52443641c762ea93ef.png
 楼主| 4c1l 发表于 2023-3-23 23:54 | 显示全部楼层
关闭后看到此界面,点击是,随后选择单片机型号为STM32F103C8T6。

90423641c7642ca9e1.png
 楼主| 4c1l 发表于 2023-3-23 23:55 | 显示全部楼层
五、编译下载

编译工程并用其它烧录器下载到STM32F103C8T6后,重新插拔USB线,电脑将出现一个虚拟硬盘。表示DAPLink的boot程序已成功运行。

12228641c765781ef0.png
 楼主| 4c1l 发表于 2023-3-23 23:55 | 显示全部楼层
随后找到stm32f103xb_stm32f103rb_if工程,进行和上面一致的操作,但是要根据自己DIY的硬件修改IO_Config.h引脚定义文件。

编译后在工程build目录下找到hex文件拖入到此虚拟U盘中,U盘名称将变为下图所示。DAPLINK运行成功

34162641c76677e8fe.png
 楼主| 4c1l 发表于 2023-3-23 23:55 | 显示全部楼层
六、注意

1、发现我自己画的板子烧入程序,有几率上电时停留在boot中无法进入app,排查后发现官方源码中RST引脚配置为开漏输出,boot中要读取到RST的电平为高才会跳转app,而我这板子没有上拉RST脚。配置为推挽输出便正常了。
2、keil工程芯片型号不一样,但它们的源文件是共用的,boot和app也是有公共的源文件的。
 楼主| 4c1l 发表于 2023-3-23 23:55 | 显示全部楼层
七、附

1、【硬件原理图】
链接:https://pan.baidu.com/s/1o40RZSf3Fbb1uKpI4PE4SQ
提取码:qlw5
 楼主| 4c1l 发表于 2023-3-23 23:56 | 显示全部楼层
2、引脚定义修改

  1. /**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]    IO_Config.h
  3. * @brief
  4. *
  5. * DAPLink Interface Firmware
  6. * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
  7. * SPDX-License-Identifier: Apache-2.0
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  10. * not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  17. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */

  21. #ifndef __IO_CONFIG_H__
  22. #define __IO_CONFIG_H__

  23. #include "stm32f1xx.h"
  24. #include "compiler.h"
  25. #include "daplink.h"

  26. COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_STM32F103XB);

  27. //USB control pin
  28. #define USB_CONNECT_PORT_ENABLE()    __HAL_RCC_GPIOA_CLK_ENABLE()
  29. #define USB_CONNECT_PORT_DISABLE()   __HAL_RCC_GPIOA_CLK_DISABLE()
  30. #define USB_CONNECT_PORT             GPIOA
  31. #define USB_CONNECT_PIN              GPIO_PIN_15
  32. #define USB_CONNECT_ON()             (USB_CONNECT_PORT->BSRR = USB_CONNECT_PIN)
  33. #define USB_CONNECT_OFF()            (USB_CONNECT_PORT->BRR  = USB_CONNECT_PIN)

  34. //Connected LED
  35. #if (0)
  36. #define CONNECTED_LED_PORT           GPIOB
  37. #define CONNECTED_LED_PIN            GPIO_PIN_6
  38. #define CONNECTED_LED_PIN_Bit        6
  39. #else        //PWH修改为PA8
  40. #define CONNECTED_LED_PORT           GPIOA
  41. #define CONNECTED_LED_PIN            GPIO_PIN_8
  42. #define CONNECTED_LED_PIN_Bit        8
  43. #endif

  44. //When bootloader, disable the target port(not used)
  45. #define POWER_EN_PIN_PORT            GPIOB
  46. #define POWER_EN_PIN                 GPIO_PIN_15
  47. #define POWER_EN_Bit                 15

  48. // nRESET OUT Pin
  49. #if (0)
  50. #define nRESET_PIN_PORT              GPIOB
  51. #define nRESET_PIN                   GPIO_PIN_0
  52. #define nRESET_PIN_Bit               0
  53. #else        //PWH修改为
  54. #define nRESET_PIN_PORT              GPIOA
  55. #define nRESET_PIN                   GPIO_PIN_6
  56. #define nRESET_PIN_Bit               6
  57. #endif

  58. //SWD
  59. #if (0)
  60. #define SWCLK_TCK_PIN_PORT           GPIOB
  61. #define SWCLK_TCK_PIN                GPIO_PIN_13
  62. #define SWCLK_TCK_PIN_Bit            13
  63. #else        //PWH修改为
  64. #define SWCLK_TCK_PIN_PORT           GPIOA
  65. #define SWCLK_TCK_PIN                GPIO_PIN_4
  66. #define SWCLK_TCK_PIN_Bit            4
  67. #endif

  68. #if (0)
  69. #define SWDIO_OUT_PIN_PORT           GPIOB
  70. #define SWDIO_OUT_PIN                GPIO_PIN_14
  71. #define SWDIO_OUT_PIN_Bit            14
  72. #else        //PWH修改为
  73. #define SWDIO_OUT_PIN_PORT           GPIOA
  74. #define SWDIO_OUT_PIN                GPIO_PIN_7
  75. #define SWDIO_OUT_PIN_Bit            7
  76. #endif

  77. #if (0)
  78. #define SWDIO_IN_PIN_PORT            GPIOB
  79. #define SWDIO_IN_PIN                 GPIO_PIN_12
  80. #define SWDIO_IN_PIN_Bit             12
  81. #else        //PWH修改为
  82. #define SWDIO_IN_PIN_PORT            GPIOB
  83. #define SWDIO_IN_PIN                 GPIO_PIN_0
  84. #define SWDIO_IN_PIN_Bit             5
  85. #endif

  86. //LEDs
  87. //USB status LED
  88. #define RUNNING_LED_PORT             GPIOA
  89. #define RUNNING_LED_PIN              GPIO_PIN_9
  90. #define RUNNING_LED_Bit              9

  91. #define PIN_HID_LED_PORT             GPIOA
  92. #define PIN_HID_LED                  GPIO_PIN_9
  93. #define PIN_HID_LED_Bit              9

  94. #define PIN_CDC_LED_PORT             GPIOA
  95. #define PIN_CDC_LED                  GPIO_PIN_9
  96. #define PIN_CDC_LED_Bit              9

  97. #define PIN_MSC_LED_PORT             GPIOA
  98. #define PIN_MSC_LED                  GPIO_PIN_9
  99. #define PIN_MSC_LED_Bit              9


  100. #endif

 楼主| 4c1l 发表于 2023-3-23 23:56 | 显示全部楼层
3、如果Keil无法识别到DAPLink,需要根据下文对源码做些修改

【新版daplink keil5识别不了】


本来想着加块屏幕可以个性化一下,但读懂源码就不容易了,目前只能显示USB连接状态,其余得慢慢研究了
 楼主| 4c1l 发表于 2023-3-23 23:56 | 显示全部楼层
 楼主| 4c1l 发表于 2023-3-23 23:56 | 显示全部楼层
linfelix 发表于 2023-5-10 21:41 | 显示全部楼层
可以用daplink破 读保护吗
robincotton 发表于 2023-5-11 16:16 | 显示全部楼层
看到过9.9元自制WIFI无线DAPLINK调试器
您需要登录后才可以回帖 登录 | 注册

本版积分规则

65

主题

703

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部