Skip to content

fix: 🐛 #166 CPU Clock set for RP2350 #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

geek981108
Copy link

Set different clock speed for rp2040 and rp2350 respect CMake variable

Set different clock speed for rp2040 and rp2350 respect CMake variable
@lurch
Copy link
Contributor

lurch commented Mar 17, 2025

In DAP_config.h just below the part that you've changed, I see that there's also a section that says:

/// Number of processor cycles for I/O Port write operations.
/// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O
/// Port write operations in the Debug Unit by a Cortex-M MCU. Most Cortex-M processors
/// require 2 processor cycles for a I/O Port Write operation.  If the Debug Unit uses
/// a Cortex-M0+ processor with high-speed peripheral I/O only 1 processor cycle might be
/// required.
#define IO_PORT_WRITE_CYCLES    1U              ///< I/O Cycles: 2=default, 1=Cortex-M0+ fast I/0.

Does this also need to be changed for Pico2 @P33M , as it has an M33 rather than an M0+ ?

@P33M
Copy link
Contributor

P33M commented Mar 17, 2025

These numbers are not used in a functional sense. They're defined to make CMSIS compile correctly (and report something useful back to the host, which according to the standard should derive the SWD clock frequency). If there is a difference in swd clock on RP2350 vs RP2040 then the bug is in the PIO SM setup, not the defines.

@P33M
Copy link
Contributor

P33M commented Mar 17, 2025

There's an indirection in the CMSIS firmware that translates a requested clock in Hz to a unit of delay cycles - which makes no sense on a RP2 device as PIO has accurate fractional clock division. This can be defeated with:

diff --git a/include/DAP_config.h b/include/DAP_config.h
index fb02fb1..88c11d9 100755
--- a/include/DAP_config.h
+++ b/include/DAP_config.h
@@ -44,6 +44,7 @@ This information includes:
  - Optional information about a connected Target Device (for Evaluation Boards).
 */
 #include <pico/stdlib.h>
+#include <hardware/clocks.h>
 #include <hardware/gpio.h>

 #include "cmsis_compiler.h"
@@ -52,8 +53,8 @@ This information includes:

 /// Processor Clock of the Cortex-M MCU used in the Debug Unit.
 /// This value is used to calculate the SWD/JTAG clock speed.
-/* Debugprobe actually uses kHz rather than Hz, so just lie about it here */
-#define CPU_CLOCK               125000000U      ///< Specifies the CPU Clock in Hz.
+/* Debugprobe uses PIO for clock generation, so return the current system clock. */
+#define CPU_CLOCK               clock_get_hz(clk_sys)

 /// Number of processor cycles for I/O Port write operations.
 /// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O

Does this result in an accurate clock on Pico and Pico 2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants