华芯微特开发论坛

 找回密码
 立即注册
搜索
热搜: SWM341 资料
查看: 2734|回复: 3

使用 VSCode + Cortex-Debug 插件调试 SWM341 程序

[复制链接]

14

主题

61

帖子

789

积分

超级版主

Rank: 8Rank: 8

积分
789
发表于 2024-1-17 17:04:21 | 显示全部楼层 |阅读模式


有坛友因为各种原因,无法使用 Keil、IAR 等集成开发环境,,而是使用 gcc+makefile 开发 SWM341 程序

使用 gcc、make 编译单片机程序很方便,,但 gdb 调试软件用起来却比较麻烦,,可以使用 VSCode + Cortex-Debug 图形化调试界面简化调试工作,,界面如下:

Cortex-Debug.jpg

上图中使用的工程是 https://gitee.com/synwit-co-ltd/micropython,下载该工程,使用 VSCode 执行 File -> Open Workspace from File ... 选择 upy34s.code-workspace 即可打开工程

使用 SYNWIT-PRG 或 SWMProg 将将编译生成的 micropython.elf 下载到 SWM341 中,,然后在 VSCode 中点击 Start Debugging 按钮即可进入上述界面

如果想要调试其他工程,,参照 upy34s.code-workspace 文件修改自己的工程配置文件中的 launch 章节即可
  1. {
  2.     "folders": [
  3.         {
  4.             "path": "."
  5.         }
  6.     ],
  7.     "settings": {
  8.     },
  9.     "launch": {
  10.         "version": "0.2.0",
  11.         "configurations": [
  12.             {
  13.                 "type": "cortex-debug",
  14.                 "name": "Cortex Debug",
  15.                 "cwd": "${workspaceRoot}/ports/swm34s/",
  16.                 "executable": "./build-SWM34SLite/micropython.elf",
  17.                 "runToEntryPoint": "main",
  18.                 "request": "launch",
  19.                 "servertype": "jlink",
  20.                 "interface": "swd",
  21.                 "device": "Cortex-M33",
  22.                 "svdFile": "ports/swm34s/SWM341.svd",
  23.                 "loadFiles": []
  24.             }
  25.         ]
  26.     }
  27. }
复制代码



回复

使用道具 举报

14

主题

61

帖子

789

积分

超级版主

Rank: 8Rank: 8

积分
789
 楼主| 发表于 2024-1-17 17:12:41 | 显示全部楼层


此调试方法用到了 Cortex-Debug 插件,,需提前安装和配置,,重点是配置 gdb 和 JLinkGDBServerCL.exe 的完整路径:

settings.json
  1. {
  2.     "cortex-debug.gdbPath": "D:/Ubuntu/bin/gcc-arm-win/bin/arm-none-eabi-gdb.exe",
  3.     "cortex-debug.JLinkGDBServerPath": "D:/Program/Segger/JLink_V688/JLinkGDBServerCL.exe",
  4. }
复制代码

如果使用 DAPLink 替代 JLink,,则需要配置 openocdPath 或 pyocdPath
回复

使用道具 举报

8

主题

27

帖子

120

积分

注册会员

Rank: 2

积分
120
发表于 2024-3-17 11:18:19 | 显示全部楼层
本帖最后由 pophu 于 2024-3-17 11:19 编辑

能搞一个 task.json 直接下载,免得下载程序 切换几次UI
openocd  的target/swm341.cfg 怎么写
回复

使用道具 举报

8

主题

27

帖子

120

积分

注册会员

Rank: 2

积分
120
发表于 2024-3-17 15:36:01 | 显示全部楼层
发一个vscode+GCC 的一个makefile.  makeupload 暂且用不了,swm341.cfg 写不出来

  1. CROSS_COMPILE ?= arm-none-eabi-
  2. CC      = $(CROSS_COMPILE)gcc
  3. OBJCOPY = $(CROSS_COMPILE)objcopy
  4. OBJDUMP = $(CROSS_COMPILE)objdump
  5. SZ = $(CROSS_COMPILE)size

  6. TARGET ?= 02_logger

  7. BUILD ?= out
  8. BUILD_DIR ?= out
  9. OBJ_DIR ?= ${BUILD_DIR}/obj
  10. WORKSPACE_DIR = ./

  11. #######################################
  12. # CFLAGS  -mthumb -mcpu=cortex-m33 -mfloat-abi=soft -std=c99 -Wpointer-arith
  13. #######################################
  14. C_DEFS ?=  -D__UVISION_VERSION="532" -D__TARGET_FPU_VFP -D__ARM_MATH_CM4 -D__FPU_PRSENT=1

  15. DEBUG = 1
  16. ifeq ($(DEBUG),1)
  17. CFLAGS += -O0 -g
  18. else
  19. CFLAGS += -O2
  20. endif

  21. CPU = -mcpu=cortex-m33
  22. # fpu
  23. FPU = -mfpu=fpv5-sp-d16
  24. # float-abi
  25. FLOAT-ABI = -mfloat-abi=hard
  26. # mcu
  27. MCU =   -mthumb $(CPU) $(FPU) $(FLOAT-ABI)

  28. # CFLAGS  ?= $(MCU)   
  29. # CFLAGS +=    -std=c99   -Wpointer-arith
  30. # # CFLAGS +=     -ffunction-sections -fdata-sections -fno-common -funsigned-char
  31. # CFLAGS +=     -fno-common -funsigned-char  
  32. # CFLAGS +=     -mlittle-endian -gdwarf-3 -O0 -ffunction-sections -fdata-sections -fno-common -funsigned-char -mno-unaligned-access
  33. # # CFLAGS +=     -Wno-missing-noreturn -Wno-sign-conversion
  34. # # CFLAGS +=     -ffunction-sections -fdata-sections -fno-common -funsigned-char
  35. # CFLAGS += $(C_INCLUDES)

  36. CFLAGS  =  $(MCU)  -std=c99 -Wpointer-arith
  37. CFLAGS += -ffunction-sections -fdata-sections -fno-common -funsigned-char -mno-unaligned-access

  38. DEBUG = 1
  39. ifeq ($(DEBUG),1)
  40. CFLAGS += -O0 -g
  41. else
  42. CFLAGS += -O2
  43. endif

  44. ASFLAGS = $(CFLAGS)

  45. LINKER_SCRIPT = swm341.ld
  46. LDFLAGS = -Wl,--gc-sections -Wl,-Map=$@.map -T $(LINKER_SCRIPT) $(MCU) -specs=nosys.specs -specs=nano.specs -u _printf_float

  47. # CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"


  48. ASFLAGS = $(CFLAGS)

  49. # LINKER_SCRIPT = swm341.ld
  50. # LIBS = -lc -lm   
  51. # LIBDIR =
  52. # LDFLAGS  ?= $(MCU)
  53. # LDFLAGS += -Wl,--gc-sections  -T$(LINKER_SCRIPT)   $(LIBDIR) $(LIBS)  -Wl,-Map=$@.map
  54. # LDFLAGS +=  -specs=nosys.specs -specs=nano.specs -u _printf_float


  55. # LIBS = -lc -lm -lnosys
  56. # LIBDIR =
  57. # LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections



  58. ASM_SOURCES ?=
  59. ASM_SOURCES +=  $(WORKSPACE_DIR)CSL/CMSIS/DeviceSupport/startup/gcc/startup_SWM341.s
  60. C_SOURCES ?=


  61. C_INCLUDES ?=
  62. C_INCLUDES += -I ${WORKSPACE_DIR}CSL/CMSIS/CoreSupport/
  63. C_INCLUDES += -I ${WORKSPACE_DIR}CSL/CMSIS/DeviceSupport/
  64. C_INCLUDES += -I ${WORKSPACE_DIR}CSL/SWM341_StdPeriph_Driver/
  65. # C_INCLUDES +=  $(addprefix -I,$(sort $(dir $(filter-out $(ROOT_DIR)/platform%,$(subst \,/,$(shell find . -type f -name *.h)))) ))
  66. # C_INCLUDES +=  -I APP/
  67. # C_INCLUDES += -I BSP/

  68. # 自行注释用不到的Drivers

  69. C_SOURCES += $(WORKSPACE_DIR)CSL/CMSIS/DeviceSupport/system_SWM341.c
  70. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_adc.c
  71. # C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_can.c
  72. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_cordic.c
  73. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_crc.c
  74. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_dac.c
  75. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_div.c
  76. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_dma.c
  77. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_dma2d.c
  78. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_exti.c
  79. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_flash.c
  80. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_gpio.c
  81. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_i2c.c
  82. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_jpeg.c
  83. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_lcd.c
  84. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_port.c
  85. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_pwm.c
  86. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_rtc.c
  87. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_sdio.c
  88. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_sdram.c
  89. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_sfc.c
  90. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_sleep.c
  91. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_spi.c
  92. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_timr.c
  93. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_uart.c
  94. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_usbd.c
  95. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_usbh.c
  96. C_SOURCES += $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver/SWM341_wdt.c


  97. ############ Freertos
  98. C_SOURCES +=  $(wildcard *.c   $(WORKSPACE_DIR)FreeRTOS/*.c)
  99. C_SOURCES +=  $(wildcard *.c   $(WORKSPACE_DIR)FreeRTOS/portable/GCC/ARM_CM33_NTZ/non_secure/*.c)
  100. C_INCLUDES += -I$(WORKSPACE_DIR)FreeRTOS/include/
  101. C_INCLUDES += -I$(WORKSPACE_DIR)FreeRTOS/
  102. C_INCLUDES += -I$(WORKSPACE_DIR)FreeRTOS/portable/GCC/ARM_CM33_NTZ/non_secure


  103. ############ Easylooger
  104. C_SOURCES +=  $(wildcard *.c   $(WORKSPACE_DIR)EasyLogger/src/*.c)
  105. C_INCLUDES += -I$(WORKSPACE_DIR)EasyLogger/inc/

  106. C_SOURCES += $(wildcard *.c  APP/*.c)
  107. C_INCLUDES +=  $(addprefix -I,$(sort $(dir $(filter-out $(ROOT_DIR)/platform%,$(subst \,/,$(shell find ./APP -type f -name *.h)))) ))
  108. C_SOURCES +=  $(wildcard *.c  BSP/*.c)
  109. C_INCLUDES +=  $(addprefix -I,$(sort $(dir $(filter-out $(ROOT_DIR)/platform%,$(subst \,/,$(shell find ./BSP -type f -name *.h)))) ))

  110. # OBJS = $(addprefix $(BUILD)/, $(APP_SRC:.c=.o) $(CSL_SRC:.c=.o) $(CSL_SRS:.s=.o) $(BSP_SRC:.c=.o))

  111. # color
  112. NO_COLOR = \033[0;01m
  113. OK_COLOR = \033[35;01m
  114. ERROR_COLOR = \033[31;01m
  115. DONE_COLOR = \033[31;01m
  116. CC_COLOR = \033[34;01m

  117. .PHONY: test echo     prestage endsatge  

  118. # default action: build all
  119. all:   prestage  buildstage endsatge
  120. build: buildstage  FORCE
  121. buildstage: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  122. prestage:
  123.         @echo -e "$(OK_COLOR)::::::::::: prestage build :::::::::::$(NO_COLOR) "
  124.         @mkdir -p $(BUILD_DIR)
  125.         @mkdir -p $(OBJ_DIR)
  126. endsatge:
  127.         @echo -e "$(OK_COLOR)::::::::::: COMPLETE BUILDING :::::::::::$(NO_COLOR) "
  128.        
  129. #######################################
  130. # build the application
  131. #######################################
  132. # list of objects
  133. OBJECTS = $(addprefix $(OBJ_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  134. vpath %.c $(sort $(dir $(C_SOURCES)))
  135. # list of ASM program objects
  136. OBJECTS += $(addprefix $(OBJ_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
  137. vpath %.s $(sort $(dir $(ASM_SOURCES)))

  138. $(OBJ_DIR)/%.o: %.c Makefile | $(OBJ_DIR)
  139.         @echo -e "$(OK_COLOR)  $< ===>>>  $@  $(NO_COLOR) "
  140.         $(CC) -c -o  $(OBJ_DIR)/$(notdir $@)  $(CFLAGS) $(C_INCLUDES)  -Wa,-a,-ad,-alms=$(OBJ_DIR)/$(notdir $(<:.c=.lst)) $<

  141. $(OBJ_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
  142.         $(CC) -c -o  $(OBJ_DIR)/$(notdir $@)  $(CFLAGS) $(C_INCLUDES) $<

  143. $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
  144.         @echo  -e "$(OK_COLOR)  LINK TO ELF :  $@  $(NO_COLOR) "
  145.         $(CC) -o $@  $(LDFLAGS) $(OBJECTS)
  146.         @echo  -e "$(CC_COLOR)     "
  147.         $(SZ) $@

  148. # $(CC) $(OBJECTS) $(LDFLAGS) -o $@
  149. $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  150.         $(OBJCOPY) -O ihex   $<   $@

  151. $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  152.         $(OBJCOPY) -O binary  $<   $@
  153.         @echo  -e "$(NO_COLOR)"
  154. # $(BUILD_DIR):
  155. #         mkdir $@       


  156. test:
  157.         @$(info  === test ===)
  158.         @echo  -e "$(CC_COLOR)  =====  "
  159.         @echo ${C_SOURCES}       
  160.         @echo  -e "$(CC_COLOR)  =====  "
  161.         @echo ${C_INCLUDES}
  162.         @echo  -e "$(CC_COLOR)  =====  "
  163.         @echo ${OBJECTS}
  164.         @echo  -e "$(NO_COLOR)"
  165. echo:
  166.         @$(info  === echo info ===)
  167.         @echo ${C_DEFS}         ${C_INCLUDES}         
  168. clean:
  169.         rm -rf $(BUILD)/*


  170. #######################################
  171. # upload cmsis-dap.cfg stlink.cfg
  172. #######################################
  173. upload:
  174. # @openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg -c init -c halt -c "flash write_image erase $(BUILD_DIR)/$(TARGET).bin 0x08000000" -c reset -c shutdown
  175. # @openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg -c init -c halt -c "program $(BUILD_DIR)/$(TARGET).bin exit 0x08000000" -c reset -c shutdown
  176. # @openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg -c init -c halt -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit"  -c reset -c shutdown
  177.         @openocd -f  cmsis-dap.cfg         -f swm341.cfg \
  178.                         -c init -c reset -c halt \
  179.                         -c "program $(BUILD_DIR)/$(TARGET).bin exit 0x00000000" \
  180.                         -c reset -c shutdown
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|华芯微特开发论坛

GMT+8, 2025-1-10 06:47 , Processed in 0.035163 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表