2

I've been playing around with the new Pico Debugger, and it is very nice. I have been running into some issues when using an external GPIO clock as the debugger does not seem able to detect the CPU's after the clock has been changed.

I believe that I have created a minimal(ish) example which can be uploaded once but not twice using the debugger. UART is used with the pico debugger, and the PWM generation from the pico-examples is used to create a 4-cycle wave which allows for verification that the clock has changed frequency.

#include <stdio.h>
#include <string.h>

#include "hardware/pll.h" #include "hardware/clocks.h" #include "hardware/structs/pll.h" #include "hardware/structs/clocks.h" #include "hardware/pwm.h"

void setup_debug() { const uint32_t BAUD_RATE = 115200; const uint32_t UART_TX_PIN = 16; const uint32_t UART_RX_PIN = 17; stdio_uart_init_full(uart0, BAUD_RATE, UART_TX_PIN, UART_RX_PIN); printf("\n-------------\n"); printf("PROGRAM START\n"); printf("UART0... OK\n"); }

void switch_pico_to_external_clock() { printf("Configuring pico clock..."); clock_configure_gpin(clk_sys, 22, 2000 * KHZ, 2000 * KHZ); // Re init uart now that clk_peri has changed stdio_init_all(); printf("ok\n"); }

void start_PWM() { // Allocate GPIO 0 and 1 to PWM gpio_set_function(0, GPIO_FUNC_PWM); gpio_set_function(1, GPIO_FUNC_PWM);

// Find out which PWM slice is connected to GPIO 0 (it's slice 0)
uint slice_num = pwm_gpio_to_slice_num(0);

// Set period of 4 cycles (0 to 3 inclusive)
pwm_set_wrap(slice_num, 3);
// Set channel A output high for one cycle before dropping
pwm_set_chan_level(slice_num, PWM_CHAN_A, 1);
// Set initial B output high for three cycles before dropping
pwm_set_chan_level(slice_num, PWM_CHAN_B, 3);
// Set the PWM running
pwm_set_enabled(slice_num, true);

}

int main() { stdio_init_all(); setup_debug(); switch_pico_to_external_clock(); printf("Program done SPINNING...\n"); start_PWM(); while (1) { sleep_ms(1000); printf("Spin..."); }; }

Running the openOCD command:

openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program src/main.elf verify reset exit"

Fails with

Open On-Chip Debugger 0.12.0-g4257276 (2023-01-27-10:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz

Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E6616407E32D4229 Info : CMSIS-DAP: SWD supported Info : CMSIS-DAP: Atomic commands supported Info : CMSIS-DAP: Test domain timer supported Info : CMSIS-DAP: FW Version = 2.0.0 Info : CMSIS-DAP: Interface Initialised (SWD) Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0 Info : CMSIS-DAP: Interface ready Info : clock speed 5000 kHz Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001 Info : SWD DPIDR 0x0bc12477, DLPIDR 0x10000001 Info : [rp2040.core0] Cortex-M0+ r0p1 processor detected Info : [rp2040.core0] target has 4 breakpoints, 2 watchpoints Info : [rp2040.core1] Cortex-M0+ r0p1 processor detected Info : [rp2040.core1] target has 4 breakpoints, 2 watchpoints Info : starting gdb server for rp2040.core0 on 3333 Info : Listening on port 3333 for gdb connections [rp2040.core0] halted due to debug-request, current mode: Thread xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00 [rp2040.core1] halted due to debug-request, current mode: Thread xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00 ** Programming Started ** Info : Found flash device 'win w25q16jv' (ID 0x001540ef) Info : RP2040 B0 Flash Probe: 2097152 bytes @0x10000000, in 32 sectors

Info : Padding image section 1 at 0x10005178 with 136 bytes (bank write end alignment) Warn : Adding extra erase range, 0x10005200 .. 0x1000ffff ** Programming Finished ** ** Verify Started ** ** Verified OK ** ** Resetting Target ** Error: Failed to connect multidrop rp2040.dap1 Warn : Connecting DP: stalled AP operation, issuing ABORT Error: Failed to connect multidrop rp2040.dap1 Warn : Connecting DP: stalled AP operation, issuing ABORT Error: Failed to connect multidrop rp2040.dap1 Warn : Connecting DP: stalled AP operation, issuing ABORT Error: Failed to connect multidrop rp2040.dap1 Warn : Connecting DP: stalled AP operation, issuing ABORT Error: Failed to connect multidrop rp2040.dap1 Warn : Connecting DP: stalled AP operation, issuing ABORT Error: Failed to connect multidrop rp2040.dap1 Warn : Connecting DP: stalled AP operation, issuing ABORT Error: Failed to select multidrop rp2040.dap1 Error: Failed to connect multidrop rp2040.dap1 Warn : Connecting DP: stalled AP operation, issuing ABORT Error: [rp2040.core1] DP initialisation failed in procedure 'program'

The microcontroller then needs to be reprogrammed by entering the USB bootloader.

I can remove the reset from the openOCD command and it exits with code 0, but I would like to be able to reset the MCU using the debugger.

Would anyone be able to point me in the right direction?

Edwin Shepherd
  • 211
  • 3
  • 9

0 Answers0