Skip to content

Commit

Permalink
Merge pull request #127 from rgrr/feature/rp2350-target
Browse files Browse the repository at this point in the history
RP2350 as a debug target plus RTT
  • Loading branch information
rgrr authored Oct 21, 2024
2 parents 4076b7b + 49e877e commit dc86894
Show file tree
Hide file tree
Showing 39 changed files with 1,316 additions and 328 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ target_sources(${PROJECT} PRIVATE
src/daplink-pico/board/rp2040/pico_target_utils.c
src/daplink-pico/board/rp2040/program_flash_generic.c
src/daplink-pico/family/raspberry/rp2040/target_reset_rp2040.c

src/daplink-pico/family/raspberry/rp2350/target_reset_rp2350.c
)

target_include_directories(${PROJECT} PRIVATE
Expand All @@ -208,8 +210,13 @@ target_include_directories(${PROJECT} PRIVATE

# Both are actually dummies to prevent the DAPLink files from throwing errors
# Actually not required because picoprobes structure is different
add_compile_definitions(INTERFACE_RP2040=1
DAPLINK_IF=1)
if(PICO_BOARD STREQUAL "pico2")
add_compile_definitions(INTERFACE_RP2350=1
DAPLINK_IF=1)
else()
add_compile_definitions(INTERFACE_RP2040=1
DAPLINK_IF=1)
endif()

# not sure if this is still required, but this equals to DAPLINK_HIC_ID_RP2040 in daplink.h
add_compile_definitions(DAPLINK_HIC_ID=0x08154711)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ flash: all
.PHONY: create-images
create-images:
# with SDK2 clang no longer works. This is a TODO
mkdir -p images
#
$(MAKE) cmake-create-release PICO_BOARD=pico
$(MAKE) all
mkdir -p images
cp $(BUILD_DIR)/$(PROJECT).uf2 images/yapicoprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-pico-$(GIT_HASH).uf2
#
# does not compile with clang because of missing __heap_start/end
Expand All @@ -110,7 +111,6 @@ create-images:
#
$(MAKE) cmake-create-release PICO_BOARD=pico2
$(MAKE) all
mkdir -p images
cp $(BUILD_DIR)/$(PROJECT).uf2 images/yapicoprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-pico2-$(GIT_HASH).uf2
#
# put development environment in a clean state
Expand Down
19 changes: 17 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ NOTE: Pico2 / RP2350 can also be used as probe hardware.

WARNING: Pico2 / RP2350 targets are currently not supported.

WARNING: Pico2 target is only working at <= 300kHz reliably. +
``time /home/hardy/.pico-sdk/openocd/0.12.0+dev/openocd.exe -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /home/hardy/.pico-sdk/openocd/0.12.0+dev/scripts -f /home/hardy/.vscode/extensions/marus25.cortex-debug-1.12.1/support/openocd-helpers.tcl -f interface/cmsis-dap.cfg -f target/rp2350.cfg -c "adapter speed 349" -c "program {pio_blink.elf} verify reset; shutdown;"``


## Features

Expand Down Expand Up @@ -102,11 +105,16 @@ containing the steps from installation until debugging in VSCode.
|yes
|`openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 25000" -c "program {firmware.elf} verify reset; shutdown;"`

|pyOCD 0.34 & 0.35
|pyOCD 0.34 .. 0.36
|yes
|yes
|`pyocd flash -f 400000 -t nrf52840 firmware.elf`

|probe-rs 0.23 ..
|yes
|?
|`probe-rs benchmark --protocol swd --address 0x20000000 --chip RP2040`

|cp / copy
|yes
|yes
Expand All @@ -133,7 +141,11 @@ Those settings are:
DAP_PACKET_SIZE=512

|OpenOCD / CMSIS-DAPv2
|DAP_PACKET_COUNT=2 +
|DAP_PACKET_COUNT=1 +
DAP_PACKET_SIZE=512

|probe-rs / CMSIS-DAPv2
|DAP_PACKET_COUNT=8 +
DAP_PACKET_SIZE=512

|unknown / CMSIS-DAPv2
Expand Down Expand Up @@ -624,6 +636,9 @@ Or use simply `make show-options` in the projects root.
| https://github.com/openocd-org/openocd[OpenOCD on github]
| https://openocd.org/[Official Homepage]

| https://github.com/probe-rs/probe-rs[probe-rs on github]
|

| https://wiki.segger.com/Use_SystemView_without_RTOS[Use SystemView without RTOS]
|

Expand Down
2 changes: 2 additions & 0 deletions include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
#define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application]
*/

#define configKERNEL_PROVIDED_STATIC_MEMORY 1

/* SMP port only */
#define configNUMBER_OF_CORES 2
#define configTICK_CORE 1
Expand Down
28 changes: 17 additions & 11 deletions src/cmsis-dap/dap_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@
*
* OpenOCD 0.11: packet size of 1024 and 2 buffers ok
* OpenOCD 0.12: 1024 no longer working, but 512 and 2 buffers is ok
*
* 2024-10-13 - confusing... openocd and so on work only with 1 packet
*/
#define _DAP_PACKET_COUNT_OPENOCD 2
#define _DAP_PACKET_COUNT_OPENOCD 1
#define _DAP_PACKET_SIZE_OPENOCD 512
#define _DAP_PACKET_COUNT_PROBERS 8
#define _DAP_PACKET_SIZE_PROBERS 1024
#define _DAP_PACKET_SIZE_PROBERS 512
#define _DAP_PACKET_COUNT_PYOCD 1
#define _DAP_PACKET_SIZE_PYOCD 512 // pyocd does not like packets > 128 if COUNT != 1,
// there seems to be also a problem with flashing if
Expand All @@ -82,19 +84,23 @@
uint8_t dap_packet_count = _DAP_PACKET_COUNT_UNKNOWN;
uint16_t dap_packet_size = _DAP_PACKET_SIZE_UNKNOWN;

#if (CFG_TUD_VENDOR_RX_BUFSIZE < _DAP_PACKET_SIZE_OPENOCD || CFG_TUD_VENDOR_RX_BUFSIZE < _DAP_PACKET_SIZE_PYOCD)
#error "increase CFG_TUD_VENDOR_RX_BUFSIZE"
#endif
#define BUFFER_MAXSIZE_1 MAX(_DAP_PACKET_COUNT_OPENOCD*_DAP_PACKET_SIZE_OPENOCD, _DAP_PACKET_COUNT_PROBERS*_DAP_PACKET_SIZE_PROBERS)
#define BUFFER_MAXSIZE_2 MAX(_DAP_PACKET_COUNT_PYOCD *_DAP_PACKET_SIZE_PYOCD, _DAP_PACKET_COUNT_UNKNOWN*_DAP_PACKET_SIZE_UNKNOWN)
#define BUFFER_MAXSIZE MAX(BUFFER_MAXSIZE_1, BUFFER_MAXSIZE_2)

#define PACKET_MAXSIZE_1 MAX(_DAP_PACKET_COUNT_OPENOCD*_DAP_PACKET_SIZE_OPENOCD, _DAP_PACKET_COUNT_PROBERS*_DAP_PACKET_SIZE_PROBERS)
#define PACKET_MAXSIZE_2 MAX(_DAP_PACKET_COUNT_PYOCD *_DAP_PACKET_SIZE_PYOCD, _DAP_PACKET_COUNT_UNKNOWN*_DAP_PACKET_SIZE_UNKNOWN)
#define PACKET_MAXSIZE_1 MAX(_DAP_PACKET_SIZE_OPENOCD, _DAP_PACKET_SIZE_PROBERS)
#define PACKET_MAXSIZE_2 MAX(_DAP_PACKET_SIZE_PYOCD, _DAP_PACKET_SIZE_UNKNOWN)
#define PACKET_MAXSIZE MAX(PACKET_MAXSIZE_1, PACKET_MAXSIZE_2)

#if (CFG_TUD_VENDOR_RX_BUFSIZE < PACKET_MAXSIZE)
#error "increase CFG_TUD_VENDOR_RX_BUFSIZE"
#endif

#if OPT_CMSIS_DAPV1 || OPT_CMSIS_DAPV2
static uint8_t TxDataBuffer[PACKET_MAXSIZE];
static uint8_t TxDataBuffer[BUFFER_MAXSIZE];
#endif
#if OPT_CMSIS_DAPV2
static uint8_t RxDataBuffer[PACKET_MAXSIZE];
static uint8_t RxDataBuffer[BUFFER_MAXSIZE];
#endif


Expand Down Expand Up @@ -193,8 +199,8 @@ void dap_task(void *ptr)
if (sw_lock("DAPv2", true)) {
swd_connected = true;
picoprobe_info("=================================== DAPv2 connect target, host %s, buffer: %dx%dbytes\n",
(tool == E_DAPTOOL_OPENOCD) ? "OpenOCD with two big buffers" :
(tool == E_DAPTOOL_PYOCD) ? "pyOCD with single big buffer" :
(tool == E_DAPTOOL_OPENOCD) ? "OpenOCD" :
(tool == E_DAPTOOL_PYOCD) ? "pyOCD" :
(tool == E_DAPTOOL_PROBERS) ? "probe-rs" : "UNKNOWN", dap_packet_count, dap_packet_size);
led_state(LS_DAPV2_CONNECTED);
}
Expand Down
61 changes: 53 additions & 8 deletions src/daplink-pico/board/rp2040/pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,25 @@
* Note that handling of the rescue DP has been dropped (no idea how to test this).
*
* Two important global variables:
* - \a g_board_info contains information about the probe, e.g. how to perform
* - \a g_board_info contains information about the probe and target, e.g. how to perform
* probe initialization, send a HW reset to the target, etc
* - \a g_target_family tells things like: what is the actual reset sequence for
* the target (family), how to set the state of the target (family), etc.
* This may differ really from target to target although all have "standard" DAPs
* included. See RP2040 with dual cores and dormant sequence which does not
* like the JTAG2SWD sequence. Others like the nRF52840 have other reset
* sequences.
*
* TODO I'm really not sure about the architectural idea of DAPLink: is board the
* target board or the probe board? So is g_board_info a probe or a target
* item? Anyway I have decided to put some probe stuff into this files.
*/

#include <stdio.h>

#include "DAP_config.h"
#include "DAP.h"
#include "swd_host.h"

#include "target_family.h"
#include "target_board.h"
#include "target_rp2040.h"
#include "target_rpXXXX.h"
#include "program_flash_generic.h"

#include "probe.h"
Expand All @@ -55,6 +53,7 @@

// these are IDs for target identification, required registers to identify may/do differ
const uint32_t swd_id_rp2040 = (0x927) + (0x0002 << 12); // taken from RP2040 SDK platform.c
const uint32_t swd_id_rp2350 = (0x927) + (0x0004 << 12); // taken from RP2350 SDK platform.c
const uint32_t swd_id_nrf52832 = 0x00052832; // see FICR.INFO.PART
const uint32_t swd_id_nrf52833 = 0x00052833;
const uint32_t swd_id_nrf52840 = 0x00052840;
Expand All @@ -73,8 +72,8 @@ const uint32_t uf2_id_rp2350 = 0xe48bff5b; // Non-secure Arm image
#define board_id_nrf52832_dk "1101"
#define board_id_nrf52833_dk "1101"
#define board_id_nrf52840_dk "1102"
#define board_id_rp2040_pico "7f01"
#define board_id_rp2350_pico2 "7f02"
#define board_id_rp2040_pico "7f01" // see TARGET_RP2040_FAMILY_ID
#define board_id_rp2350_pico2 "7f02" // see TARGET_RP2350_FAMILY_ID

// here we can modify the otherwise constant board/target information
target_cfg_t target_device;
Expand Down Expand Up @@ -105,6 +104,28 @@ target_cfg_t target_device_rp2040 = {
};


// target information for RP2350 (actually Pico2), must be global
// because a special algo is used for flashing, corresponding fields below are empty.
target_cfg_t target_device_rp2350 = {
.version = kTargetConfigVersion,
.sectors_info = NULL,
.sector_info_length = 0,
.flash_regions[0].start = 0x10000000,
.flash_regions[0].end = 0x10000000,
.flash_regions[0].flags = kRegionIsDefault,
.flash_regions[0].flash_algo = NULL,
.ram_regions[0].start = 0x20000000,
.ram_regions[0].end = 0x20000000 + KB(512),
.target_vendor = "RaspberryPi",
.target_part_number = "RP2350",
.rt_family_id = TARGET_RP2350_FAMILY_ID,
.rt_board_id = board_id_rp2350_pico2,
.rt_uf2_id = uf2_id_rp2350,
.rt_max_swd_khz = 50000,
.rt_swd_khz = 15000,
};


// target information for a generic device which allows at least RTT (if connected)
target_cfg_t target_device_generic = {
.version = kTargetConfigVersion,
Expand Down Expand Up @@ -214,6 +235,30 @@ void pico_prerun_board_config(void)
}
}

if ( !target_found) {
// check for RP2350
target_device = target_device_rp2350;
search_family();
if (target_set_state(ATTACH)) {
uint32_t chip_id;

r = swd_read_word(0x40000000, &chip_id);
printf("!!!!!!!!!!!!!!!!!! chip_id: 0x%lx\n", chip_id);
if (r && (chip_id & 0x0fffffff) == swd_id_rp2350) {
target_found = true;
strcpy(board_vendor, "RaspberryPi");
strcpy(board_name, "Pico2");

// get size of targets flash
// TODO uint32_t size = target_rp2350_get_external_flash_size();
uint32_t size = 4 * 1024 * 1024;
if (size > 0) {
target_device.flash_regions[0].end = target_device.flash_regions[0].start + size;
}
}
}
}

if ( !target_found) {
// check for nRF52832, nRF52833 or nRF52840
// DK names taken from https://infocenter.nordicsemi.com/topic/ug_gsg_ses/UG/gsg/chips_and_sds.html
Expand Down
2 changes: 1 addition & 1 deletion src/daplink-pico/board/rp2040/pico_target_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "pico_target_utils.h"

#include "swd_host.h"
#include "target_rp2040.h"
#include "target_rpXXXX.h"



Expand Down
4 changes: 2 additions & 2 deletions src/daplink-pico/board/rp2040/program_flash_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extern char __start_for_target_connect[];
extern char __stop_for_target_connect[];

// Attributes for RP2040 target code
// NOTE: this needs PICO_NO_CMSE to be set
#define FOR_TARGET_RP2040_CODE __attribute__((noinline, section("for_target_connect"), target("arch=armv6-m")))
// NOTE: PICO_NO_CMSE must be set and also "-Og"!
#define FOR_TARGET_RP2040_CODE __attribute__((noinline, section("for_target_connect"), target("arch=armv6-m"), optimize("-Og")))

#define TARGET_RP2040_CODE (TARGET_RP2040_RAM_START + 0x10000)
#define TARGET_RP2040_FLASH_SIZE ((uint32_t)rp2040_flash_size - (uint32_t)__start_for_target_connect + TARGET_RP2040_CODE)
Expand Down
14 changes: 7 additions & 7 deletions src/daplink-pico/family/raspberry/rp2040/target_reset_rp2040.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#include <string.h>
#include <stdio.h>
#include <target_rpXXXX.h>
#include "DAP_config.h"
#include "target_family.h"
#include "target_rp2040.h"
#include "swd_host.h"


Expand All @@ -37,7 +37,7 @@
#endif


const uint32_t soft_reset = SYSRESETREQ;
static const uint32_t soft_reset = SYSRESETREQ;



Expand Down Expand Up @@ -74,7 +74,7 @@ static void swd_from_dormant(void)
const uint8_t zero_seq[] = {0x00};
const uint8_t act_seq[] = { 0x1a };

// printf("---swd_from_dormant()\n");
// printf("---swd_from_dormant()\n");

SWJ_Sequence( 8, ones_seq);
SWJ_Sequence(128, selection_alert_seq);
Expand Down Expand Up @@ -103,7 +103,7 @@ static void swd_targetsel(uint8_t core)
static const uint8_t out2[] = {0x00};
static uint8_t input;

// printf("---swd_targetsel(%u)\n", core);
// printf("---swd_targetsel(%u)\n", core);

SWD_Sequence(8, out1, NULL);
SWD_Sequence(0x80 + 5, NULL, &input);
Expand Down Expand Up @@ -138,7 +138,7 @@ static bool dp_core_select(uint8_t _core)
swd_targetsel(_core);

CHECK_OK_BOOL(swd_read_dp(DP_IDCODE, &rv));
// printf("--- id(%u)=0x%08lx\n", _core, rv); // 0x0bc12477 is the RP2040
// printf("--- id(%u)=0x%08lx\n", _core, rv); // 0x0bc12477 is the RP2040

core = _core;
return true;
Expand All @@ -154,7 +154,7 @@ static bool dp_disable_breakpoint()
{
static const uint32_t bp_reg[4] = { 0xE0002008, 0xE000200C, 0xE0002010, 0xE0002014 };

// printf("---dp_disable_breakpoint()\n");
// printf("---dp_disable_breakpoint()\n");

// Clear each of the breakpoints...
for (int i = 0; i < 4; ++i) {
Expand Down Expand Up @@ -225,7 +225,7 @@ static bool rp2040_swd_init_debug(uint8_t core)
CHECK_ABORT( swd_write_ap(AP_CSW, 1) ); // force dap_state.csw to "0"
CHECK_ABORT( swd_write_ap(AP_CSW, 0) );

CHECK_ABORT( swd_read_ap(0xfc, &tmp) ); // AP IDR: must it be 0x4770031?
CHECK_ABORT( swd_read_ap(AP_IDR, &tmp) ); // AP IDR: must it be 0x4770031?
CHECK_ABORT( swd_write_dp(DP_SELECT, 0) );

return true;
Expand Down
Loading

0 comments on commit dc86894

Please sign in to comment.