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);
}
