I am using the Waveshare ESP32-P4-ETH module and programming it via the Arduino IDE. Uploading and debug output are working fine via the USB connection.
However, when setting up the SPI and performing a transfer at 5 MHz clock speed, the actual SPI clock signal is only clocking at 2.222 MHz when measured with an oscilloscope. The factor seems to closely match the difference of the 40 MHz XTAL clock and the 90 MHz assumed ABP clock, that the sketch (see below) is outputting.
Could this be an issue with the Arduino port or do I have something misconfigured on my side? The "test pin" that is toggled below takes about 19.5ms for the delay loop in the sketch.
Interestingly, the UART output *does* have a correct timing for the 115200 baud setting.
Used Sketch:
Code: Select all
#include <SPI.h>
#define SCK 18
#define MOSI 19
#define MISO 54
void setup() {
Serial.begin(115200);
pinMode(17, OUTPUT); // test pin
SPI.begin(SCK, MISO, MOSI);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Tick..");
Serial.println(getApbFrequency()); // Outputs 90 MHz
Serial.println(getXtalFrequencyMhz()); // Outputs 40 MHz
digitalWrite(17, HIGH);
for(volatile uint32_t i = 0; i < 1000000; i++); // Takes 19.5ms
digitalWrite(17, LOW);
SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0));
SPI.write(0xAA);
SPI.endTransaction();
delay(1000);
}