SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: Debugging Cortex-M1 on Arty without adaptor or DAPLink
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

Debugging Cortex-M1 on Arty without adaptor or DAPLink

Andrew Irwin
Last updated: September 20, 2023 10:44 am
Andrew Irwin 5 Min Read
Share
SHARE

Debugging embedded systems like Cortex-M1 on Arty board without a debug adaptor or DAPLink can be challenging, but is possible with some effort. This article will guide you through the process step-by-step.

Contents
OverviewEnabling SWD Pins on ArtyBuilding and Flashing Debugger FirmwareCompiling DebuggerFlashing Debugger FirmwareConnecting GDB DebuggerGDB CommandsDebugging CodeLoading CodeStepping Through CodeSample SessionTroubleshootingGDB Won’t ConnectBreakpoints Not HittingVariables Show Wrong ValueSWD Adapter IssuesConclusion

Overview

The key steps are:

  1. Enable SWD pins on Arty board
  2. Build and flash debugger firmware
  3. Connect to GDB debugger
  4. Debug code with GDB

Enabling SWD Pins on Arty

Arty board has SWD pins broken out to the headers, but they are not enabled by default. To enable them:

  1. Locate the 2-pin shunt jumper near the Cortex-M1 module
  2. Shunt the jumper to connect the pins and enable SWD
  3. The SWD pins are now available on the board headers

Building and Flashing Debugger Firmware

Next, we need to build and flash a small debugger firmware onto the Cortex-M1 that will allow GDB to connect to it directly over SWD.

Compiling Debugger

You can use the open source CMSIS-DAP firmware for this.

  1. Download the firmware source code
  2. Open the project in Keil MDK toolkit
  3. Configure the project settings for your Arty board and Cortex-M1 module
  4. Build the project

This will produce a binary firmware image you can flash.

Flashing Debugger Firmware

To flash the debugger image:

  1. Connect Arty board SWD pins to another SWD debugger
  2. Load the compiled firmware binary
  3. Halt the target Cortex-M1 before flashing
  4. Flash the debugger firmware onto Cortex-M1

Once flashed, the debugger will start running on Cortex-M1 on next boot.

Connecting GDB Debugger

With debugger firmware running on the target, you can now connect to it directly from GDB over SWD interface.

  1. Connect Arty SWD pins to your PC using an SWD adapter
  2. Power on Arty board
  3. Launch GDB and connect to the SWD interface
  4. The debugger firmware will halt the Cortex-M1 on boot
  5. Cortex-M1 is now ready for debugging in GDB

GDB Commands

Useful GDB commands:

  • continue – resume execution
  • next – step over next instruction
  • step – step into next instruction
  • break – set breakpoint
  • print – print variable value
  • backtrace – show stack trace

Debugging Code

With GDB connected, you can now debug code running on Cortex-M1 just like using a dedicated debugger.

Loading Code

To load code:

  1. Compile your code into ELF file
  2. In GDB, load the ELF file using ‘file’ command
  3. Set any breakpoints you need
  4. Use ‘continue’ to run to first breakpoint

Stepping Through Code

Use GDB commands like step and next to step through code.

Set additional breakpoints as needed to pause execution.

Inspect variables, registers, memory etc.

Sample Session

Here is an example debugging session: $ arm-none-eabi-gdb demo.elf (gdb) target remote localhost:3333 (gdb) load Loading section .text, size 0x258 lma 0x0 Loading section .data, size 0x8 lma 0x258 Start address 0x0, load size 616 Transfer rate: 18 KB/sec, 616 bytes/write. (gdb) break main Breakpoint 1 at 0x104: file demo.c, line 5. (gdb) continue Continuing. Breakpoint 1, main () at demo.c:5 5 int i = 10; (gdb) print i $1 = 0 (gdb) next 7 for(i=0; i<10; i++) { (gdb) print i $2 = 0 (gdb) step 9 printf(“Hello %d\n”, i); (gdb) next Hello 0 7 for(i=0; i<10; i++) { (gdb) print i $3 = 1

Troubleshooting

Here are some common issues and solutions:

GDB Won’t Connect

  • Check SWD pins are connected properly
  • Verify debugger firmware is flashed and running
  • Try resetting the board

Breakpoints Not Hitting

  • Make sure code is compiled with debug symbols
  • Breakpoint may be set at invalid address
  • Code region might not be loaded in memory

Variables Show Wrong Value

  • Rebuild code from scratch, old binaries may be stale
  • Optimize variable placement in memory

SWD Adapter Issues

  • Update adapter firmware or drivers if needed
  • Check adapter power – some may need external power
  • Try a different SWD adapter

Conclusion

Debugging Cortex-M1 on Arty without a dedicated debugger is very doable with some effort. The key steps are enabling SWD pins, flashing debugger firmware, connecting GDB via SWD, and using GDB to control execution and inspect state. With a few tweaks and customizations, this approach can work for many different boards and projects.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Using De Bruijn sequences for faster count leading zeros (CLZ)
Next Article Using ST-Link debugger with Cortex-M1 FPGA design
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

Debugging Multi-Core ARM Designs with SWD

ARM processors are extremely popular in embedded systems due to…

7 Min Read

The History of ARM’s Cortex-M Series

ARM's Cortex-M series of processor cores has become ubiquitous in…

6 Min Read

Resolving “Uses VFP Register Arguments” Errors when Compiling for Cortex-M3

When compiling code for the ARM Cortex-M3 processor, you may…

11 Min Read

How to Enable the FPU in Cortex-M4 Microcontrollers?

The Cortex-M4 processor includes a single precision floating point unit…

7 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account