# SWD In-circuit programming using a Raspberry Pi Pico RP2040

<abstract>
This article illustrates how to use the popular Raspberry Pi Pico RP2040 board to make a cheap
In-circuit SWD programmer for the H10 module and Berta H10 board
</abstract>

<img src="./swd_icsp_rp2040.jpg">

## Free-dap project

Free-dap is a free and open implementation of the CMSIS-DAP debugger firmware available on GitHub:

* <https://github.com/ataradov/free-dap>

Using this firmware is enought to wire these signal between the Raspberry Pi Pico RP2040

| RP2040 GPIO | RP2040 pin #  | Berta-H10 J12 pin # | Signals          |
|-------------|---------------|---------------------|------------------|
| GP15        | 20            | 1                   | NRST             |
| GP11        | 15            | 7                   | SWCLK            |
| GP12        | 16            | 9                   | SWDIO            |
| GND         | 18            | 6                   | GND              |

## Programming the Free-dap firmware on RP2040 board

A very easy way to save the firmware on the RP2040 board is using the ready-to-use binary file available on the Free-dap 
Git repository:

* <https://github.com/ataradov/free-dap/blob/master/bin/free_dap_rp2040.uf2>

Download this file and save it on your local disk. Plug the microUSB port of the RP2040 to your PC while holdinf down the
button BOOTSEL on RP2040 board. A disk called RPI-RP2 will appear on your desktop.

Drag and drop the <code>free_dap_rp2040.uf2</code> file on this new drive. After a while the RPI-RP2 will disappear from
your desktop and the green led on RP2040 turn-on. Your SWD programmer is now ready-to-use.

You can transfer the H10 firmware by using the command:

	make flash

	...
	### Flashing Target ###
	Debugger: Alex Taradov Generic CMSIS-DAP Adapter 3A6B79A7 2.0.0 (SJ)
	Clock frequency: 16.0 MHz
	Target: SAM R34J18B (Rev C)
	Verification.......... done.
	Done flashing
	
## Links

* @article='h10_berta_getting_started'
* [Raspberry Pi Pico RP2040 pinout](https://d28lcup14p4e72.cloudfront.net/203128/7592134/423FEC27-201C-4091-B185-F9E24A5EBFB9.png)