ESP32-C6: possible to route 40Mhz XTAL to gpio pin?
Posted: Thu Mar 12, 2026 10:51 pm
On the esp32-s3 I can route the 40Mhz clock to a pin with the following code:
ESP32-C6 doesn't seem to have CLKOUT channels. Is there some other way to route the 40Mhz root clock to a gpio or is it only possible to create a PLL derived 40Mhz clock using LEDC?
Code: Select all
#include "driver/gpio.h"
#include "driver/ledc.h"
#include "hal/clk_tree_hal.h"
#include "soc/clkout_channel.h"
#include "soc/io_mux_reg.h"
void route_40mhz_xtal_to_gpio39_s3() {
// 1. Set GPIO 39 as an output
gpio_set_direction(GPIO_NUM_39, GPIO_MODE_OUTPUT);
// 2. Set to maximum drive strength to keep the 40MHz edges sharp
gpio_set_drive_capability(GPIO_NUM_39, GPIO_DRIVE_CAP_3);
// 3. Configure the IO_MUX:
// On the ESP32-S3, 'Function 2' on GPIO 39 routes the physical pin to CLK_OUT3
PIN_FUNC_SELECT(IO_MUX_GPIO39_REG, 2);
// 4. Configure the clock tree to send the Main XTAL to CLKOUT Channel 3
clk_hal_clock_output_setup(CLKOUT_SIG_XTAL, CLKOUT_CHANNEL_3);
}
void setup() {
route_40mhz_xtal_to_gpio39_s3();
}
void loop() {
delay(1000);
}