In this practice, we will program SAML ARM Cortex microcontrollers with our DapCat programmer device in OpenOCD.
DapCat ProgrammerDapCat Programmer is a low-cost, debug probe based on the CMSIS-DAP (also known as DAPLink) protocol standard and USB-Serial convert and it can realize USB convert to the serial interface. It can be used to program and debug the application software running on Arm Cortex Microcontrollers.
- CH552G microcontroller
- 16KB Flash, 1KB xRAM & 256B iRAM;
- ROM-based USB drivers. Flash updates via USB supported.
- Shipped with Arm Mbed DAPLink Firmware
- HID – CMSIS-DAP compliant debug channel
- USB Serial bus convert and it can realize USB convert to the serial interface.
- Supported Arduino IDE and OpenOCD
- LED indicator & Button
- 3.3V DC-DC regulator with 1A output current
- 3.3V Digital I/O Operating Voltage
- Reversible USB-C Connector
- Easy-to-use 5-pin 2.54mm Header with SWD & UART interface
- Very small form factor: 20 x 48
- OpenOCD
- Arduino IDE
- PyOCD
- Dap.js()
- Keil
- IAR
- edbg
Download "arm-none-eabi-gdb" which is included on the "gcc-arm-none-eabi" from ARM Developer
Linux Exception
Linux users will need to download the pre-compiled version instead of "apt-get install arm-none-eabi" in order to get the arm gdb
2. Download OpenOCDLinux
sudo apt-get install openocd
macOS
sudo brew install openocd
Unofficial binary packages
Some special circumstances might make using a package manager or self-compiling OpenOCD impractical, so several nice community members provide regularly updated binary builds on their websites.
Liviu Ionescu maintains multi-platform binaries Windows 32/64-bit, Intel GNU/Linux 32/64-bit, Arm GNU/Linux 32/64-bit, and Intel macOS 64-bit as part of The xPack OpenOCD project. The official Github mirror automatically generates Windows binary archives for releases and all master commits.
UsageOpenOCDExecute OpenOCD calling your configuration file for your microcontroller
You can create your own configuration file but also you can download our owns in the main repository
sudo openocd -f saml21.cfg
The flag " -f " loads a specific file from your system, above is assumed that you have the file saml21.cfg in the same folder you're executing openocd.
Windows In windows there's no " sudo " command, execute the cmd as administrator.
If your microcontroller is well connected you should see prompted something like this:
At this point everything is well connected to OpenOCD so now we have run a gdb server up and running on our own machine at port 3333.
GDBNow we need to connect to the GDB server using the client previously installed with the ARM GCC toolchain.
To invoke we just need to type:
arm-none-eabi-gdb
Once GDB is running we need to connect to OpenOCD with any of the next commands
When the debugged program exits or you detach from it, GDB disconnects from the target.
target remote localhost:3333
- When the debugged program exits or you detach from it, GDB disconnects from the target.target remote localhost:3333
When the debugged program exits or you detach from it, GDB remains connected to the target,
target extended-remote localhost:3333
- When the debugged program exits or you detach from it, GDB remains connected to the target,target extended-remote localhost:3333
Just one of the above.
Now you're connected to the OpenOCD GDB serverOnce connected your able to debug and flash your microcontroller.
In order to flash you can use the next commands:
1. monitor reset halt
2. set mem inaccessible-by-default off
3. load yourBinary.elf
4. q
GDB AutomationSingle command to init GDB
arm-none-eabi-gdb -ex 'target extended-remote localhost:3333'
Single command to flash with GDB
arm-none-eabi-gdb yourBinary.elf -ex 'target extended-remote localhost:3333' -ex 'load' -ex 'q'
Example
Comments